|
@@ -113,10 +113,10 @@ typedef intptr_t userptr_t;
|
113
|
113
|
/**
|
114
|
114
|
* Copy data to user buffer
|
115
|
115
|
*
|
116
|
|
- * @v buffer User buffer
|
117
|
|
- * @v offset Offset within user buffer
|
118
|
|
- * @v src Source
|
119
|
|
- * @v len Length
|
|
116
|
+ * @v buffer User buffer
|
|
117
|
+ * @v offset Offset within user buffer
|
|
118
|
+ * @v src Source
|
|
119
|
+ * @v len Length
|
120
|
120
|
*/
|
121
|
121
|
static inline __attribute__ (( always_inline )) void
|
122
|
122
|
copy_to_user ( userptr_t buffer, off_t offset, const void *src, size_t len ) {
|
|
@@ -126,10 +126,10 @@ copy_to_user ( userptr_t buffer, off_t offset, const void *src, size_t len ) {
|
126
|
126
|
/**
|
127
|
127
|
* Copy data from user buffer
|
128
|
128
|
*
|
129
|
|
- * @v dest Destination
|
130
|
|
- * @v buffer User buffer
|
131
|
|
- * @v offset Offset within user buffer
|
132
|
|
- * @v len Length
|
|
129
|
+ * @v dest Destination
|
|
130
|
+ * @v buffer User buffer
|
|
131
|
+ * @v offset Offset within user buffer
|
|
132
|
+ * @v len Length
|
133
|
133
|
*/
|
134
|
134
|
static inline __attribute__ (( always_inline )) void
|
135
|
135
|
copy_from_user ( void *dest, userptr_t buffer, off_t offset, size_t len ) {
|
|
@@ -139,11 +139,11 @@ copy_from_user ( void *dest, userptr_t buffer, off_t offset, size_t len ) {
|
139
|
139
|
/**
|
140
|
140
|
* Copy data between user buffers
|
141
|
141
|
*
|
142
|
|
- * @v dest Destination user buffer
|
143
|
|
- * @v dest_off Offset within destination buffer
|
144
|
|
- * @v src Source user buffer
|
145
|
|
- * @v src_off Offset within source buffer
|
146
|
|
- * @v len Length
|
|
142
|
+ * @v dest Destination user buffer
|
|
143
|
+ * @v dest_off Offset within destination buffer
|
|
144
|
+ * @v src Source user buffer
|
|
145
|
+ * @v src_off Offset within source buffer
|
|
146
|
+ * @v len Length
|
147
|
147
|
*/
|
148
|
148
|
static inline __attribute__ (( always_inline )) void
|
149
|
149
|
copy_user ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off,
|
|
@@ -152,11 +152,24 @@ copy_user ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off,
|
152
|
152
|
len );
|
153
|
153
|
}
|
154
|
154
|
|
|
155
|
+/**
|
|
156
|
+ * Fill user buffer with a constant byte
|
|
157
|
+ *
|
|
158
|
+ * @v buffer User buffer
|
|
159
|
+ * @v offset Offset within buffer
|
|
160
|
+ * @v c Constant byte with which to fill
|
|
161
|
+ * @v len Length
|
|
162
|
+ */
|
|
163
|
+static inline __attribute__ (( always_inline )) void
|
|
164
|
+memset_user ( userptr_t buffer, off_t offset, int c, size_t len ) {
|
|
165
|
+ memset ( ( ( void * ) buffer + offset ), c, len );
|
|
166
|
+}
|
|
167
|
+
|
155
|
168
|
/**
|
156
|
169
|
* Convert virtual address to user buffer
|
157
|
170
|
*
|
158
|
|
- * @v virtual Virtual address
|
159
|
|
- * @ret buffer User buffer
|
|
171
|
+ * @v virtual Virtual address
|
|
172
|
+ * @ret buffer User buffer
|
160
|
173
|
*
|
161
|
174
|
* This constructs a user buffer from an ordinary pointer. Use it
|
162
|
175
|
* when you need to pass a pointer to an internal buffer to a function
|
|
@@ -170,9 +183,9 @@ virt_to_user ( void * virtual ) {
|
170
|
183
|
/**
|
171
|
184
|
* Convert segment:offset address to user buffer
|
172
|
185
|
*
|
173
|
|
- * @v segment Real-mode segment
|
174
|
|
- * @v offset Real-mode offset
|
175
|
|
- * @ret buffer User buffer
|
|
186
|
+ * @v segment Real-mode segment
|
|
187
|
+ * @v offset Real-mode offset
|
|
188
|
+ * @ret buffer User buffer
|
176
|
189
|
*/
|
177
|
190
|
static inline __attribute__ (( always_inline )) userptr_t
|
178
|
191
|
real_to_user ( unsigned int segment, unsigned int offset ) {
|
|
@@ -182,14 +195,26 @@ real_to_user ( unsigned int segment, unsigned int offset ) {
|
182
|
195
|
/**
|
183
|
196
|
* Convert physical address to user buffer
|
184
|
197
|
*
|
185
|
|
- * @v physical Physical address
|
186
|
|
- * @ret buffer User buffer
|
|
198
|
+ * @v physical Physical address
|
|
199
|
+ * @ret buffer User buffer
|
187
|
200
|
*/
|
188
|
201
|
static inline __attribute__ (( always_inline )) userptr_t
|
189
|
202
|
phys_to_user ( physaddr_t physical ) {
|
190
|
203
|
return virt_to_user ( phys_to_virt ( physical ) );
|
191
|
204
|
}
|
192
|
205
|
|
|
206
|
+/**
|
|
207
|
+ * Convert user buffer to physical address
|
|
208
|
+ *
|
|
209
|
+ * @v buffer User buffer
|
|
210
|
+ * @v offset Offset within user buffer
|
|
211
|
+ * @ret physical Physical address
|
|
212
|
+ */
|
|
213
|
+static inline __attribute__ (( always_inline )) physaddr_t
|
|
214
|
+user_to_phys ( userptr_t buffer, off_t offset ) {
|
|
215
|
+ return virt_to_phys ( ( void * ) buffer + offset );
|
|
216
|
+}
|
|
217
|
+
|
193
|
218
|
/* Copy to/from real-mode stack */
|
194
|
219
|
extern uint16_t copy_to_rm_stack ( void *data, size_t size );
|
195
|
220
|
extern void remove_from_rm_stack ( void *data, size_t size );
|