Revision 53a5960a linux-user/qemu.h
b/linux-user/qemu.h | ||
---|---|---|
69 | 69 |
int swi_errno; |
70 | 70 |
#endif |
71 | 71 |
#ifdef TARGET_I386 |
72 |
struct target_vm86plus_struct *target_v86;
|
|
72 |
target_ulong target_v86;
|
|
73 | 73 |
struct vm86_saved_state vm86_saved_regs; |
74 | 74 |
struct target_vm86plus_struct vm86plus; |
75 | 75 |
uint32_t v86flags; |
... | ... | |
84 | 84 |
int elf_exec(const char * filename, char ** argv, char ** envp, |
85 | 85 |
struct target_pt_regs * regs, struct image_info *infop); |
86 | 86 |
|
87 |
void target_set_brk(char *new_brk);
|
|
88 |
long do_brk(char *new_brk);
|
|
87 |
void target_set_brk(target_ulong new_brk);
|
|
88 |
long do_brk(target_ulong new_brk);
|
|
89 | 89 |
void syscall_init(void); |
90 | 90 |
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
91 | 91 |
long arg4, long arg5, long arg6); |
... | ... | |
112 | 112 |
void save_v86_state(CPUX86State *env); |
113 | 113 |
void handle_vm86_trap(CPUX86State *env, int trapno); |
114 | 114 |
void handle_vm86_fault(CPUX86State *env); |
115 |
int do_vm86(CPUX86State *env, long subfunction, |
|
116 |
struct target_vm86plus_struct * target_v86); |
|
115 |
int do_vm86(CPUX86State *env, long subfunction, target_ulong v86_addr); |
|
117 | 116 |
#endif |
118 | 117 |
|
119 | 118 |
/* mmap.c */ |
120 |
int target_mprotect(unsigned long start, unsigned long len, int prot);
|
|
121 |
long target_mmap(unsigned long start, unsigned long len, int prot,
|
|
122 |
int flags, int fd, unsigned long offset);
|
|
123 |
int target_munmap(unsigned long start, unsigned long len);
|
|
124 |
long target_mremap(unsigned long old_addr, unsigned long old_size,
|
|
125 |
unsigned long new_size, unsigned long flags,
|
|
126 |
unsigned long new_addr);
|
|
127 |
int target_msync(unsigned long start, unsigned long len, int flags);
|
|
119 |
int target_mprotect(target_ulong start, target_ulong len, int prot);
|
|
120 |
long target_mmap(target_ulong start, target_ulong len, int prot,
|
|
121 |
int flags, int fd, target_ulong offset);
|
|
122 |
int target_munmap(target_ulong start, target_ulong len);
|
|
123 |
long target_mremap(target_ulong old_addr, target_ulong old_size,
|
|
124 |
target_ulong new_size, unsigned long flags,
|
|
125 |
target_ulong new_addr);
|
|
126 |
int target_msync(target_ulong start, target_ulong len, int flags);
|
|
128 | 127 |
|
129 | 128 |
/* user access */ |
130 | 129 |
|
... | ... | |
133 | 132 |
|
134 | 133 |
#define access_ok(type,addr,size) (1) |
135 | 134 |
|
135 |
/* NOTE get_user and put_user use host addresses. */ |
|
136 | 136 |
#define __put_user(x,ptr)\ |
137 | 137 |
({\ |
138 | 138 |
int size = sizeof(*ptr);\ |
139 | 139 |
switch(size) {\ |
140 | 140 |
case 1:\ |
141 |
stb(ptr, (typeof(*ptr))(x));\
|
|
141 |
*(uint8_t *)(ptr) = (typeof(*ptr))(x);\
|
|
142 | 142 |
break;\ |
143 | 143 |
case 2:\ |
144 |
stw(ptr, (typeof(*ptr))(x));\
|
|
144 |
*(uint16_t *)(ptr) = tswap16((typeof(*ptr))(x));\
|
|
145 | 145 |
break;\ |
146 | 146 |
case 4:\ |
147 |
stl(ptr, (typeof(*ptr))(x));\
|
|
147 |
*(uint32_t *)(ptr) = tswap32((typeof(*ptr))(x));\
|
|
148 | 148 |
break;\ |
149 | 149 |
case 8:\ |
150 |
stq(ptr, (typeof(*ptr))(x));\
|
|
150 |
*(uint64_t *)(ptr) = tswap64((typeof(*ptr))(x));\
|
|
151 | 151 |
break;\ |
152 | 152 |
default:\ |
153 | 153 |
abort();\ |
... | ... | |
160 | 160 |
int size = sizeof(*ptr);\ |
161 | 161 |
switch(size) {\ |
162 | 162 |
case 1:\ |
163 |
x = (typeof(*ptr))ldub((void *)ptr);\
|
|
163 |
x = (typeof(*ptr))*(uint8_t *)(ptr);\
|
|
164 | 164 |
break;\ |
165 | 165 |
case 2:\ |
166 |
x = (typeof(*ptr))lduw((void *)ptr);\
|
|
166 |
x = (typeof(*ptr))tswap16(*(uint16_t *)(ptr));\
|
|
167 | 167 |
break;\ |
168 | 168 |
case 4:\ |
169 |
x = (typeof(*ptr))ldl((void *)ptr);\
|
|
169 |
x = (typeof(*ptr))tswap32(*(uint32_t *)(ptr));\
|
|
170 | 170 |
break;\ |
171 | 171 |
case 8:\ |
172 |
x = (typeof(*ptr))ldq((void *)ptr);\
|
|
172 |
x = (typeof(*ptr))tswap64(*(uint64_t *)(ptr));\
|
|
173 | 173 |
break;\ |
174 | 174 |
default:\ |
175 | 175 |
abort();\ |
... | ... | |
177 | 177 |
0;\ |
178 | 178 |
}) |
179 | 179 |
|
180 |
static inline unsigned long __copy_to_user(void *dst, const void *src, |
|
181 |
unsigned long size) |
|
182 |
{ |
|
183 |
memcpy(dst, src, size); |
|
184 |
return 0; |
|
185 |
} |
|
186 |
|
|
187 |
static inline unsigned long __copy_from_user(void *dst, const void *src, |
|
188 |
unsigned long size) |
|
189 |
{ |
|
190 |
memcpy(dst, src, size); |
|
191 |
return 0; |
|
192 |
} |
|
193 |
|
|
194 |
static inline unsigned long __clear_user(void *dst, unsigned long size) |
|
195 |
{ |
|
196 |
memset(dst, 0, size); |
|
197 |
return 0; |
|
198 |
} |
|
199 |
|
|
200 | 180 |
#define put_user(x,ptr)\ |
201 | 181 |
({\ |
202 | 182 |
int __ret;\ |
... | ... | |
217 | 197 |
__ret;\ |
218 | 198 |
}) |
219 | 199 |
|
220 |
static inline unsigned long copy_to_user(void *dst, const void *src, |
|
221 |
unsigned long size) |
|
200 |
/* Functions for accessing guest memory. The tget and tput functions |
|
201 |
read/write single values, byteswapping as neccessary. The lock_user |
|
202 |
gets a pointer to a contiguous area of guest memory, but does not perform |
|
203 |
and byteswapping. lock_user may return either a pointer to the guest |
|
204 |
memory, or a temporary buffer. */ |
|
205 |
|
|
206 |
/* Lock an area of guest memory into the host. If copy is true then the |
|
207 |
host area will have the same contents as the guest. */ |
|
208 |
static inline void *lock_user(target_ulong guest_addr, long len, int copy) |
|
222 | 209 |
{ |
223 |
if (access_ok(VERIFY_WRITE, dst, size)) |
|
224 |
return __copy_to_user(dst, src, size); |
|
210 |
#ifdef DEBUG_REMAP |
|
211 |
void *addr; |
|
212 |
addr = malloc(len); |
|
213 |
if (copy) |
|
214 |
memcpy(addr, g2h(guest_addr), len); |
|
225 | 215 |
else |
226 |
return size; |
|
216 |
memset(addr, 0, len); |
|
217 |
return addr; |
|
218 |
#else |
|
219 |
return g2h(guest_addr); |
|
220 |
#endif |
|
227 | 221 |
} |
228 | 222 |
|
229 |
static inline unsigned long copy_from_user(void *dst, const void *src, |
|
230 |
unsigned long size) |
|
223 |
/* Unlock an area of guest memory. The first LEN bytes must be flushed back |
|
224 |
to guest memory. */ |
|
225 |
static inline void unlock_user(void *host_addr, target_ulong guest_addr, |
|
226 |
long len) |
|
231 | 227 |
{ |
232 |
if (access_ok(VERIFY_READ, src, size)) |
|
233 |
return __copy_from_user(dst, src, size); |
|
234 |
else |
|
235 |
return size; |
|
228 |
#ifdef DEBUG_REMAP |
|
229 |
if (host_addr == g2h(guest_addr)) |
|
230 |
return; |
|
231 |
if (len > 0) |
|
232 |
memcpy(g2h(guest_addr), host_addr, len); |
|
233 |
free(host_addr); |
|
234 |
#endif |
|
236 | 235 |
} |
237 | 236 |
|
238 |
static inline unsigned long clear_user(void *dst, unsigned long size) |
|
237 |
/* Return the length of a string in target memory. */ |
|
238 |
static inline int target_strlen(target_ulong ptr) |
|
239 | 239 |
{ |
240 |
if (access_ok(VERIFY_WRITE, dst, size)) |
|
241 |
return __clear_user(dst, size); |
|
242 |
else |
|
243 |
return size; |
|
240 |
return strlen(g2h(ptr)); |
|
241 |
} |
|
242 |
|
|
243 |
/* Like lock_user but for null terminated strings. */ |
|
244 |
static inline void *lock_user_string(target_ulong guest_addr) |
|
245 |
{ |
|
246 |
long len; |
|
247 |
len = target_strlen(guest_addr) + 1; |
|
248 |
return lock_user(guest_addr, len, 1); |
|
244 | 249 |
} |
245 | 250 |
|
251 |
/* Helper macros for locking/ulocking a target struct. */ |
|
252 |
#define lock_user_struct(host_ptr, guest_addr, copy) \ |
|
253 |
host_ptr = lock_user(guest_addr, sizeof(*host_ptr), copy) |
|
254 |
#define unlock_user_struct(host_ptr, guest_addr, copy) \ |
|
255 |
unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) |
|
256 |
|
|
257 |
#define tget8(addr) ldub(addr) |
|
258 |
#define tput8(addr, val) stb(addr, val) |
|
259 |
#define tget16(addr) lduw(addr) |
|
260 |
#define tput16(addr, val) stw(addr, val) |
|
261 |
#define tget32(addr) ldl(addr) |
|
262 |
#define tput32(addr, val) stl(addr, val) |
|
263 |
#define tget64(addr) ldq(addr) |
|
264 |
#define tput64(addr, val) stq(addr, val) |
|
265 |
#if TARGET_LONG_BITS == 64 |
|
266 |
#define tgetl(addr) ldq(addr) |
|
267 |
#define tputl(addr, val) stq(addr, val) |
|
268 |
#else |
|
269 |
#define tgetl(addr) ldl(addr) |
|
270 |
#define tputl(addr, val) stl(addr, val) |
|
271 |
#endif |
|
272 |
|
|
246 | 273 |
#endif /* QEMU_H */ |
Also available in: Unified diff