root / linux-user / qemu.h @ c16f9ed3
History | View | Annotate | Download (11.3 kB)
1 | e88de099 | bellard | #ifndef QEMU_H
|
---|---|---|---|
2 | e88de099 | bellard | #define QEMU_H
|
3 | 31e31b8a | bellard | |
4 | 9de5e440 | bellard | #include <signal.h> |
5 | edf779ff | bellard | #include <string.h> |
6 | 31e31b8a | bellard | |
7 | 6180a181 | bellard | #include "cpu.h" |
8 | 992f48a0 | blueswir1 | |
9 | 992f48a0 | blueswir1 | #ifdef TARGET_ABI32
|
10 | 992f48a0 | blueswir1 | typedef uint32_t abi_ulong;
|
11 | 992f48a0 | blueswir1 | typedef int32_t abi_long;
|
12 | f3e3285d | ths | #define TARGET_ABI_FMT_lx "%08x" |
13 | f3e3285d | ths | #define TARGET_ABI_FMT_ld "%d" |
14 | f3e3285d | ths | #define TARGET_ABI_FMT_lu "%u" |
15 | 992f48a0 | blueswir1 | #define TARGET_ABI_BITS 32 |
16 | 992f48a0 | blueswir1 | #else
|
17 | 992f48a0 | blueswir1 | typedef target_ulong abi_ulong;
|
18 | 992f48a0 | blueswir1 | typedef target_long abi_long;
|
19 | f3e3285d | ths | #define TARGET_ABI_FMT_lx TARGET_FMT_lx
|
20 | f3e3285d | ths | #define TARGET_ABI_FMT_ld TARGET_FMT_ld
|
21 | f3e3285d | ths | #define TARGET_ABI_FMT_lu TARGET_FMT_lu
|
22 | 992f48a0 | blueswir1 | #define TARGET_ABI_BITS TARGET_LONG_BITS
|
23 | 992f48a0 | blueswir1 | #endif
|
24 | 992f48a0 | blueswir1 | |
25 | 992f48a0 | blueswir1 | #include "thunk.h" |
26 | 992f48a0 | blueswir1 | #include "syscall_defs.h" |
27 | 6180a181 | bellard | #include "syscall.h" |
28 | a04e134a | ths | #include "target_signal.h" |
29 | 1fddef4b | bellard | #include "gdbstub.h" |
30 | 66fb9763 | bellard | |
31 | 31e31b8a | bellard | /* This struct is used to hold certain information about the image.
|
32 | 31e31b8a | bellard | * Basically, it replicates in user space what would be certain
|
33 | 31e31b8a | bellard | * task_struct fields in the kernel
|
34 | 31e31b8a | bellard | */
|
35 | 31e31b8a | bellard | struct image_info {
|
36 | 992f48a0 | blueswir1 | abi_ulong load_addr; |
37 | 992f48a0 | blueswir1 | abi_ulong start_code; |
38 | 992f48a0 | blueswir1 | abi_ulong end_code; |
39 | 992f48a0 | blueswir1 | abi_ulong start_data; |
40 | 992f48a0 | blueswir1 | abi_ulong end_data; |
41 | 992f48a0 | blueswir1 | abi_ulong start_brk; |
42 | 992f48a0 | blueswir1 | abi_ulong brk; |
43 | 992f48a0 | blueswir1 | abi_ulong start_mmap; |
44 | 992f48a0 | blueswir1 | abi_ulong mmap; |
45 | 992f48a0 | blueswir1 | abi_ulong rss; |
46 | 992f48a0 | blueswir1 | abi_ulong start_stack; |
47 | 992f48a0 | blueswir1 | abi_ulong entry; |
48 | 992f48a0 | blueswir1 | abi_ulong code_offset; |
49 | 992f48a0 | blueswir1 | abi_ulong data_offset; |
50 | 38d0662a | pbrook | char **host_argv;
|
51 | 31e31b8a | bellard | int personality;
|
52 | 31e31b8a | bellard | }; |
53 | 31e31b8a | bellard | |
54 | b346ff46 | bellard | #ifdef TARGET_I386
|
55 | 851e67a1 | bellard | /* Information about the current linux thread */
|
56 | 851e67a1 | bellard | struct vm86_saved_state {
|
57 | 851e67a1 | bellard | uint32_t eax; /* return code */
|
58 | 851e67a1 | bellard | uint32_t ebx; |
59 | 851e67a1 | bellard | uint32_t ecx; |
60 | 851e67a1 | bellard | uint32_t edx; |
61 | 851e67a1 | bellard | uint32_t esi; |
62 | 851e67a1 | bellard | uint32_t edi; |
63 | 851e67a1 | bellard | uint32_t ebp; |
64 | 851e67a1 | bellard | uint32_t esp; |
65 | 851e67a1 | bellard | uint32_t eflags; |
66 | 851e67a1 | bellard | uint32_t eip; |
67 | 851e67a1 | bellard | uint16_t cs, ss, ds, es, fs, gs; |
68 | 851e67a1 | bellard | }; |
69 | b346ff46 | bellard | #endif
|
70 | 851e67a1 | bellard | |
71 | 28c4f361 | bellard | #ifdef TARGET_ARM
|
72 | 28c4f361 | bellard | /* FPU emulator */
|
73 | 28c4f361 | bellard | #include "nwfpe/fpa11.h" |
74 | 28c4f361 | bellard | #endif
|
75 | 28c4f361 | bellard | |
76 | 851e67a1 | bellard | /* NOTE: we force a big alignment so that the stack stored after is
|
77 | 851e67a1 | bellard | aligned too */
|
78 | 851e67a1 | bellard | typedef struct TaskState { |
79 | 851e67a1 | bellard | struct TaskState *next;
|
80 | 28c4f361 | bellard | #ifdef TARGET_ARM
|
81 | 28c4f361 | bellard | /* FPA state */
|
82 | 28c4f361 | bellard | FPA11 fpa; |
83 | a4f81979 | bellard | int swi_errno;
|
84 | 28c4f361 | bellard | #endif
|
85 | 84409ddb | j_mayer | #if defined(TARGET_I386) && !defined(TARGET_X86_64)
|
86 | 992f48a0 | blueswir1 | abi_ulong target_v86; |
87 | 851e67a1 | bellard | struct vm86_saved_state vm86_saved_regs;
|
88 | b333af06 | bellard | struct target_vm86plus_struct vm86plus;
|
89 | 631271d7 | bellard | uint32_t v86flags; |
90 | 631271d7 | bellard | uint32_t v86mask; |
91 | b346ff46 | bellard | #endif
|
92 | e6e5906b | pbrook | #ifdef TARGET_M68K
|
93 | e6e5906b | pbrook | int sim_syscalls;
|
94 | e6e5906b | pbrook | #endif
|
95 | a87295e8 | pbrook | #if defined(TARGET_ARM) || defined(TARGET_M68K)
|
96 | a87295e8 | pbrook | /* Extra fields for semihosted binaries. */
|
97 | a87295e8 | pbrook | uint32_t stack_base; |
98 | a87295e8 | pbrook | uint32_t heap_base; |
99 | a87295e8 | pbrook | uint32_t heap_limit; |
100 | a87295e8 | pbrook | #endif
|
101 | 851e67a1 | bellard | int used; /* non zero if used */ |
102 | 978efd6a | pbrook | struct image_info *info;
|
103 | 851e67a1 | bellard | uint8_t stack[0];
|
104 | 851e67a1 | bellard | } __attribute__((aligned(16))) TaskState;
|
105 | 851e67a1 | bellard | |
106 | 851e67a1 | bellard | extern TaskState *first_task_state;
|
107 | c5937220 | pbrook | extern const char *qemu_uname_release; |
108 | 851e67a1 | bellard | |
109 | e5fe0c52 | pbrook | /* ??? See if we can avoid exposing so much of the loader internals. */
|
110 | e5fe0c52 | pbrook | /*
|
111 | e5fe0c52 | pbrook | * MAX_ARG_PAGES defines the number of pages allocated for arguments
|
112 | e5fe0c52 | pbrook | * and envelope for the new program. 32 should suffice, this gives
|
113 | e5fe0c52 | pbrook | * a maximum env+arg of 128kB w/4KB pages!
|
114 | e5fe0c52 | pbrook | */
|
115 | e5fe0c52 | pbrook | #define MAX_ARG_PAGES 32 |
116 | e5fe0c52 | pbrook | |
117 | e5fe0c52 | pbrook | /*
|
118 | 5fafdf24 | ths | * This structure is used to hold the arguments that are
|
119 | e5fe0c52 | pbrook | * used when loading binaries.
|
120 | e5fe0c52 | pbrook | */
|
121 | e5fe0c52 | pbrook | struct linux_binprm {
|
122 | e5fe0c52 | pbrook | char buf[128]; |
123 | e5fe0c52 | pbrook | void *page[MAX_ARG_PAGES];
|
124 | 992f48a0 | blueswir1 | abi_ulong p; |
125 | e5fe0c52 | pbrook | int fd;
|
126 | e5fe0c52 | pbrook | int e_uid, e_gid;
|
127 | e5fe0c52 | pbrook | int argc, envc;
|
128 | e5fe0c52 | pbrook | char **argv;
|
129 | e5fe0c52 | pbrook | char **envp;
|
130 | e5fe0c52 | pbrook | char * filename; /* Name of binary */ |
131 | e5fe0c52 | pbrook | }; |
132 | e5fe0c52 | pbrook | |
133 | e5fe0c52 | pbrook | void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); |
134 | 992f48a0 | blueswir1 | abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, |
135 | 992f48a0 | blueswir1 | abi_ulong stringp, int push_ptr);
|
136 | 5fafdf24 | ths | int loader_exec(const char * filename, char ** argv, char ** envp, |
137 | 01ffc75b | bellard | struct target_pt_regs * regs, struct image_info *infop); |
138 | 31e31b8a | bellard | |
139 | e5fe0c52 | pbrook | int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, |
140 | e5fe0c52 | pbrook | struct image_info * info);
|
141 | e5fe0c52 | pbrook | int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, |
142 | e5fe0c52 | pbrook | struct image_info * info);
|
143 | cb33da57 | blueswir1 | #ifdef TARGET_HAS_ELFLOAD32
|
144 | cb33da57 | blueswir1 | int load_elf_binary_multi(struct linux_binprm *bprm, |
145 | cb33da57 | blueswir1 | struct target_pt_regs *regs,
|
146 | cb33da57 | blueswir1 | struct image_info *info);
|
147 | cb33da57 | blueswir1 | #endif
|
148 | e5fe0c52 | pbrook | |
149 | 579a97f7 | bellard | abi_long memcpy_to_target(abi_ulong dest, const void *src, |
150 | 579a97f7 | bellard | unsigned long len); |
151 | 992f48a0 | blueswir1 | void target_set_brk(abi_ulong new_brk);
|
152 | 992f48a0 | blueswir1 | abi_long do_brk(abi_ulong new_brk); |
153 | 31e31b8a | bellard | void syscall_init(void); |
154 | 992f48a0 | blueswir1 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1, |
155 | 992f48a0 | blueswir1 | abi_long arg2, abi_long arg3, abi_long arg4, |
156 | 992f48a0 | blueswir1 | abi_long arg5, abi_long arg6); |
157 | 31e31b8a | bellard | void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2))); |
158 | b346ff46 | bellard | extern CPUState *global_env;
|
159 | b346ff46 | bellard | void cpu_loop(CPUState *env);
|
160 | 32ce6337 | bellard | void init_paths(const char *prefix); |
161 | 32ce6337 | bellard | const char *path(const char *pathname); |
162 | b92c47c1 | ths | char *target_strerror(int err); |
163 | 6977fbfd | bellard | |
164 | 6977fbfd | bellard | extern int loglevel; |
165 | 631271d7 | bellard | extern FILE *logfile;
|
166 | 631271d7 | bellard | |
167 | b92c47c1 | ths | /* strace.c */
|
168 | b92c47c1 | ths | void print_syscall(int num, |
169 | c16f9ed3 | bellard | abi_long arg1, abi_long arg2, abi_long arg3, |
170 | c16f9ed3 | bellard | abi_long arg4, abi_long arg5, abi_long arg6); |
171 | c16f9ed3 | bellard | void print_syscall_ret(int num, abi_long arg1); |
172 | b92c47c1 | ths | extern int do_strace; |
173 | b92c47c1 | ths | |
174 | b346ff46 | bellard | /* signal.c */
|
175 | b346ff46 | bellard | void process_pending_signals(void *cpu_env); |
176 | b346ff46 | bellard | void signal_init(void); |
177 | b346ff46 | bellard | int queue_signal(int sig, target_siginfo_t *info); |
178 | b346ff46 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); |
179 | b346ff46 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); |
180 | b346ff46 | bellard | long do_sigreturn(CPUState *env);
|
181 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env);
|
182 | 579a97f7 | bellard | abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); |
183 | b346ff46 | bellard | |
184 | b346ff46 | bellard | #ifdef TARGET_I386
|
185 | 631271d7 | bellard | /* vm86.c */
|
186 | 631271d7 | bellard | void save_v86_state(CPUX86State *env);
|
187 | 447db213 | bellard | void handle_vm86_trap(CPUX86State *env, int trapno); |
188 | 631271d7 | bellard | void handle_vm86_fault(CPUX86State *env);
|
189 | 992f48a0 | blueswir1 | int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr); |
190 | 5bfb56b2 | blueswir1 | #elif defined(TARGET_SPARC64)
|
191 | 5bfb56b2 | blueswir1 | void sparc64_set_context(CPUSPARCState *env);
|
192 | 5bfb56b2 | blueswir1 | void sparc64_get_context(CPUSPARCState *env);
|
193 | b346ff46 | bellard | #endif
|
194 | 631271d7 | bellard | |
195 | 54936004 | bellard | /* mmap.c */
|
196 | 992f48a0 | blueswir1 | int target_mprotect(abi_ulong start, abi_ulong len, int prot); |
197 | 992f48a0 | blueswir1 | abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
|
198 | 992f48a0 | blueswir1 | int flags, int fd, abi_ulong offset); |
199 | 992f48a0 | blueswir1 | int target_munmap(abi_ulong start, abi_ulong len);
|
200 | 992f48a0 | blueswir1 | abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
201 | 992f48a0 | blueswir1 | abi_ulong new_size, unsigned long flags, |
202 | 992f48a0 | blueswir1 | abi_ulong new_addr); |
203 | 992f48a0 | blueswir1 | int target_msync(abi_ulong start, abi_ulong len, int flags); |
204 | 54936004 | bellard | |
205 | edf779ff | bellard | /* user access */
|
206 | edf779ff | bellard | |
207 | edf779ff | bellard | #define VERIFY_READ 0 |
208 | 579a97f7 | bellard | #define VERIFY_WRITE 1 /* implies read access */ |
209 | edf779ff | bellard | |
210 | 3d97b40b | ths | #define access_ok(type,addr,size) \
|
211 | 3d97b40b | ths | (page_check_range((target_ulong)addr,size,(type==VERIFY_READ)?PAGE_READ:PAGE_WRITE)==0)
|
212 | edf779ff | bellard | |
213 | 89343ecd | ths | /* NOTE __get_user and __put_user use host pointers and don't check access. */
|
214 | 579a97f7 | bellard | /* These are usually used to access struct data members once the
|
215 | 579a97f7 | bellard | * struct has been locked - usually with lock_user_struct().
|
216 | 579a97f7 | bellard | */
|
217 | 89343ecd | ths | #define __put_user(x, hptr)\
|
218 | edf779ff | bellard | ({\ |
219 | 89343ecd | ths | int size = sizeof(*hptr);\ |
220 | edf779ff | bellard | switch(size) {\
|
221 | edf779ff | bellard | case 1:\ |
222 | 89343ecd | ths | *(uint8_t *)(hptr) = (typeof(*hptr))(x);\ |
223 | edf779ff | bellard | break;\
|
224 | edf779ff | bellard | case 2:\ |
225 | 89343ecd | ths | *(uint16_t *)(hptr) = tswap16((typeof(*hptr))(x));\ |
226 | edf779ff | bellard | break;\
|
227 | edf779ff | bellard | case 4:\ |
228 | 89343ecd | ths | *(uint32_t *)(hptr) = tswap32((typeof(*hptr))(x));\ |
229 | edf779ff | bellard | break;\
|
230 | edf779ff | bellard | case 8:\ |
231 | 89343ecd | ths | *(uint64_t *)(hptr) = tswap64((typeof(*hptr))(x));\ |
232 | edf779ff | bellard | break;\
|
233 | edf779ff | bellard | default:\
|
234 | edf779ff | bellard | abort();\ |
235 | edf779ff | bellard | }\ |
236 | edf779ff | bellard | 0;\
|
237 | edf779ff | bellard | }) |
238 | edf779ff | bellard | |
239 | 89343ecd | ths | #define __get_user(x, hptr) \
|
240 | edf779ff | bellard | ({\ |
241 | 89343ecd | ths | int size = sizeof(*hptr);\ |
242 | edf779ff | bellard | switch(size) {\
|
243 | edf779ff | bellard | case 1:\ |
244 | 89343ecd | ths | x = (typeof(*hptr))*(uint8_t *)(hptr);\ |
245 | edf779ff | bellard | break;\
|
246 | edf779ff | bellard | case 2:\ |
247 | 89343ecd | ths | x = (typeof(*hptr))tswap16(*(uint16_t *)(hptr));\ |
248 | edf779ff | bellard | break;\
|
249 | edf779ff | bellard | case 4:\ |
250 | 89343ecd | ths | x = (typeof(*hptr))tswap32(*(uint32_t *)(hptr));\ |
251 | edf779ff | bellard | break;\
|
252 | edf779ff | bellard | case 8:\ |
253 | 89343ecd | ths | x = (typeof(*hptr))tswap64(*(uint64_t *)(hptr));\ |
254 | edf779ff | bellard | break;\
|
255 | edf779ff | bellard | default:\
|
256 | edf779ff | bellard | abort();\ |
257 | edf779ff | bellard | }\ |
258 | edf779ff | bellard | 0;\
|
259 | edf779ff | bellard | }) |
260 | edf779ff | bellard | |
261 | 579a97f7 | bellard | /* put_user()/get_user() take a guest address and check access */
|
262 | 579a97f7 | bellard | /* These are usually used to access an atomic data type, such as an int,
|
263 | 579a97f7 | bellard | * that has been passed by address. These internally perform locking
|
264 | 579a97f7 | bellard | * and unlocking on the data type.
|
265 | 579a97f7 | bellard | */
|
266 | 579a97f7 | bellard | #define put_user(x, gaddr, target_type) \
|
267 | 579a97f7 | bellard | ({ \ |
268 | 579a97f7 | bellard | abi_ulong __gaddr = (gaddr); \ |
269 | 579a97f7 | bellard | target_type *__hptr; \ |
270 | 579a97f7 | bellard | abi_long __ret; \ |
271 | 579a97f7 | bellard | if ((__hptr = lock_user(VERIFY_WRITE, __gaddr, sizeof(target_type), 0))) { \ |
272 | 579a97f7 | bellard | __ret = __put_user((x), __hptr); \ |
273 | 579a97f7 | bellard | unlock_user(__hptr, __gaddr, sizeof(target_type)); \
|
274 | 579a97f7 | bellard | } else \
|
275 | 579a97f7 | bellard | __ret = -TARGET_EFAULT; \ |
276 | 579a97f7 | bellard | __ret; \ |
277 | edf779ff | bellard | }) |
278 | edf779ff | bellard | |
279 | 579a97f7 | bellard | #define get_user(x, gaddr, target_type) \
|
280 | 579a97f7 | bellard | ({ \ |
281 | 579a97f7 | bellard | abi_ulong __gaddr = (gaddr); \ |
282 | 579a97f7 | bellard | target_type *__hptr; \ |
283 | 579a97f7 | bellard | abi_long __ret; \ |
284 | 579a97f7 | bellard | if ((__hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1))) { \ |
285 | 579a97f7 | bellard | __ret = __get_user((x), __hptr); \ |
286 | 579a97f7 | bellard | unlock_user(__hptr, __gaddr, 0); \
|
287 | 579a97f7 | bellard | } else \
|
288 | 579a97f7 | bellard | __ret = -TARGET_EFAULT; \ |
289 | 579a97f7 | bellard | __ret; \ |
290 | edf779ff | bellard | }) |
291 | edf779ff | bellard | |
292 | 579a97f7 | bellard | /* copy_from_user() and copy_to_user() are usually used to copy data
|
293 | 579a97f7 | bellard | * buffers between the target and host. These internally perform
|
294 | 579a97f7 | bellard | * locking/unlocking of the memory.
|
295 | 579a97f7 | bellard | */
|
296 | 579a97f7 | bellard | abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len);
|
297 | 579a97f7 | bellard | abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
|
298 | 579a97f7 | bellard | |
299 | 53a5960a | pbrook | /* Functions for accessing guest memory. The tget and tput functions
|
300 | 53a5960a | pbrook | read/write single values, byteswapping as neccessary. The lock_user
|
301 | 53a5960a | pbrook | gets a pointer to a contiguous area of guest memory, but does not perform
|
302 | 53a5960a | pbrook | and byteswapping. lock_user may return either a pointer to the guest
|
303 | 53a5960a | pbrook | memory, or a temporary buffer. */
|
304 | 53a5960a | pbrook | |
305 | 53a5960a | pbrook | /* Lock an area of guest memory into the host. If copy is true then the
|
306 | 53a5960a | pbrook | host area will have the same contents as the guest. */
|
307 | 579a97f7 | bellard | static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
308 | edf779ff | bellard | { |
309 | 579a97f7 | bellard | if (!access_ok(type, guest_addr, len))
|
310 | 579a97f7 | bellard | return NULL; |
311 | 53a5960a | pbrook | #ifdef DEBUG_REMAP
|
312 | 579a97f7 | bellard | { |
313 | 579a97f7 | bellard | void *addr;
|
314 | 579a97f7 | bellard | addr = malloc(len); |
315 | 579a97f7 | bellard | if (copy)
|
316 | 579a97f7 | bellard | memcpy(addr, g2h(guest_addr), len); |
317 | 579a97f7 | bellard | else
|
318 | 579a97f7 | bellard | memset(addr, 0, len);
|
319 | 579a97f7 | bellard | return addr;
|
320 | 579a97f7 | bellard | } |
321 | 53a5960a | pbrook | #else
|
322 | 53a5960a | pbrook | return g2h(guest_addr);
|
323 | 53a5960a | pbrook | #endif
|
324 | edf779ff | bellard | } |
325 | edf779ff | bellard | |
326 | 579a97f7 | bellard | /* Unlock an area of guest memory. The first LEN bytes must be
|
327 | 579a97f7 | bellard | flushed back to guest memory. host_ptr = NULL is explicitely
|
328 | 579a97f7 | bellard | allowed and does nothing. */
|
329 | 579a97f7 | bellard | static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, |
330 | 992f48a0 | blueswir1 | long len)
|
331 | edf779ff | bellard | { |
332 | 579a97f7 | bellard | |
333 | 53a5960a | pbrook | #ifdef DEBUG_REMAP
|
334 | 579a97f7 | bellard | if (!host_ptr)
|
335 | 579a97f7 | bellard | return;
|
336 | 579a97f7 | bellard | if (host_ptr == g2h(guest_addr))
|
337 | 53a5960a | pbrook | return;
|
338 | 53a5960a | pbrook | if (len > 0) |
339 | 579a97f7 | bellard | memcpy(g2h(guest_ptr), host_ptr, len); |
340 | 579a97f7 | bellard | free(host_ptr); |
341 | 53a5960a | pbrook | #endif
|
342 | edf779ff | bellard | } |
343 | edf779ff | bellard | |
344 | 579a97f7 | bellard | /* Return the length of a string in target memory or -TARGET_EFAULT if
|
345 | 579a97f7 | bellard | access error. */
|
346 | 579a97f7 | bellard | abi_long target_strlen(abi_ulong gaddr); |
347 | 53a5960a | pbrook | |
348 | 53a5960a | pbrook | /* Like lock_user but for null terminated strings. */
|
349 | 992f48a0 | blueswir1 | static inline void *lock_user_string(abi_ulong guest_addr) |
350 | 53a5960a | pbrook | { |
351 | 579a97f7 | bellard | abi_long len; |
352 | 579a97f7 | bellard | len = target_strlen(guest_addr); |
353 | 579a97f7 | bellard | if (len < 0) |
354 | 579a97f7 | bellard | return NULL; |
355 | 579a97f7 | bellard | return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
356 | edf779ff | bellard | } |
357 | edf779ff | bellard | |
358 | 53a5960a | pbrook | /* Helper macros for locking/ulocking a target struct. */
|
359 | 579a97f7 | bellard | #define lock_user_struct(type, host_ptr, guest_addr, copy) \
|
360 | 579a97f7 | bellard | (host_ptr = lock_user(type, guest_addr, sizeof(*host_ptr), copy))
|
361 | 579a97f7 | bellard | #define unlock_user_struct(host_ptr, guest_addr, copy) \
|
362 | 53a5960a | pbrook | unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) |
363 | 53a5960a | pbrook | |
364 | 53a5960a | pbrook | #define tget8(addr) ldub(addr)
|
365 | 53a5960a | pbrook | #define tput8(addr, val) stb(addr, val)
|
366 | 53a5960a | pbrook | #define tget16(addr) lduw(addr)
|
367 | 53a5960a | pbrook | #define tput16(addr, val) stw(addr, val)
|
368 | 53a5960a | pbrook | #define tget32(addr) ldl(addr)
|
369 | 53a5960a | pbrook | #define tput32(addr, val) stl(addr, val)
|
370 | 53a5960a | pbrook | #define tget64(addr) ldq(addr)
|
371 | 53a5960a | pbrook | #define tput64(addr, val) stq(addr, val)
|
372 | 992f48a0 | blueswir1 | #if TARGET_ABI_BITS == 64 |
373 | 53a5960a | pbrook | #define tgetl(addr) ldq(addr)
|
374 | 53a5960a | pbrook | #define tputl(addr, val) stq(addr, val)
|
375 | 53a5960a | pbrook | #else
|
376 | 53a5960a | pbrook | #define tgetl(addr) ldl(addr)
|
377 | 53a5960a | pbrook | #define tputl(addr, val) stl(addr, val)
|
378 | 53a5960a | pbrook | #endif
|
379 | 53a5960a | pbrook | |
380 | e88de099 | bellard | #endif /* QEMU_H */ |