xref: /qemu/linux-user/user-internals.h (revision 7cef6d686309e2792186504ae17cf4f3eb57ef68)
1 /*
2  * user-internals.h: prototypes etc internal to the linux-user implementation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef LINUX_USER_USER_INTERNALS_H
19 #define LINUX_USER_USER_INTERNALS_H
20 
21 #include "user/thunk.h"
22 #include "qemu/log.h"
23 
24 extern char *exec_path;
25 void init_task_state(TaskState *ts);
26 void task_settid(TaskState *);
27 void stop_all_tasks(void);
28 extern const char *qemu_uname_release;
29 extern unsigned long mmap_min_addr;
30 
31 typedef struct IOCTLEntry IOCTLEntry;
32 
33 typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
34                              int fd, int cmd, abi_long arg);
35 
36 struct IOCTLEntry {
37     int target_cmd;
38     unsigned int host_cmd;
39     const char *name;
40     int access;
41     do_ioctl_fn *do_ioctl;
42     const argtype arg_type[5];
43 };
44 
45 extern IOCTLEntry ioctl_entries[];
46 
47 #define IOC_R 0x0001
48 #define IOC_W 0x0002
49 #define IOC_RW (IOC_R | IOC_W)
50 
51 /*
52  * Returns true if the image uses the FDPIC ABI. If this is the case,
53  * we have to provide some information (loadmap, pt_dynamic_info) such
54  * that the program can be relocated adequately. This is also useful
55  * when handling signals.
56  */
57 int info_is_fdpic(struct image_info *info);
58 
59 void target_set_brk(abi_ulong new_brk);
60 void syscall_init(void);
61 abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1,
62                     abi_long arg2, abi_long arg3, abi_long arg4,
63                     abi_long arg5, abi_long arg6, abi_long arg7,
64                     abi_long arg8);
65 extern __thread CPUState *thread_cpu;
66 abi_long get_errno(abi_long ret);
67 const char *target_strerror(int err);
68 int get_osversion(void);
69 void init_qemu_uname_release(void);
70 void fork_start(void);
71 void fork_end(pid_t pid);
72 
73 /**
74  * probe_guest_base:
75  * @image_name: the executable being loaded
76  * @loaddr: the lowest fixed address within the executable
77  * @hiaddr: the highest fixed address within the executable
78  *
79  * Creates the initial guest address space in the host memory space.
80  *
81  * If @loaddr == 0, then no address in the executable is fixed, i.e.
82  * it is fully relocatable.  In that case @hiaddr is the size of the
83  * executable minus one.
84  *
85  * This function will not return if a valid value for guest_base
86  * cannot be chosen.  On return, the executable loader can expect
87  *
88  *    target_mmap(loaddr, hiaddr - loaddr + 1, ...)
89  *
90  * to succeed.
91  */
92 void probe_guest_base(const char *image_name,
93                       abi_ulong loaddr, abi_ulong hiaddr);
94 
95 /* syscall.c */
96 int host_to_target_waitstatus(int status);
97 
98 #ifdef TARGET_I386
99 /* vm86.c */
100 void save_v86_state(CPUX86State *env);
101 void handle_vm86_trap(CPUX86State *env, int trapno);
102 int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr);
103 #elif defined(TARGET_SPARC64)
104 void sparc64_set_context(CPUSPARCState *env);
105 void sparc64_get_context(CPUSPARCState *env);
106 #endif
107 
is_error(abi_long ret)108 static inline int is_error(abi_long ret)
109 {
110     return (abi_ulong)ret >= (abi_ulong)(-4096);
111 }
112 
113 #if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32)
target_offset64(uint32_t word0,uint32_t word1)114 static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
115 {
116 #if TARGET_BIG_ENDIAN
117     return ((uint64_t)word0 << 32) | word1;
118 #else
119     return ((uint64_t)word1 << 32) | word0;
120 #endif
121 }
122 #else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */
target_offset64(uint64_t word0,uint64_t word1)123 static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
124 {
125     return word0;
126 }
127 #endif /* TARGET_ABI_BITS != 32 */
128 
129 void print_termios(void *arg);
130 
131 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
132 #ifdef TARGET_ARM
regpairs_aligned(CPUArchState * cpu_env,int num)133 static inline int regpairs_aligned(CPUArchState *cpu_env, int num)
134 {
135     return cpu_env->eabi;
136 }
137 #elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32)
regpairs_aligned(CPUArchState * cpu_env,int num)138 static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
139 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
140 /*
141  * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
142  * of registers which translates to the same as ARM/MIPS, because we start with
143  * r3 as arg1
144  */
regpairs_aligned(CPUArchState * cpu_env,int num)145 static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
146 #elif defined(TARGET_SH4)
147 /* SH4 doesn't align register pairs, except for p{read,write}64 */
regpairs_aligned(CPUArchState * cpu_env,int num)148 static inline int regpairs_aligned(CPUArchState *cpu_env, int num)
149 {
150     switch (num) {
151     case TARGET_NR_pread64:
152     case TARGET_NR_pwrite64:
153         return 1;
154 
155     default:
156         return 0;
157     }
158 }
159 #elif defined(TARGET_XTENSA)
regpairs_aligned(CPUArchState * cpu_env,int num)160 static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
161 #elif defined(TARGET_HEXAGON)
regpairs_aligned(CPUArchState * cpu_env,int num)162 static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
163 #else
regpairs_aligned(CPUArchState * cpu_env,int num)164 static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; }
165 #endif
166 
167 /**
168  * preexit_cleanup: housekeeping before the guest exits
169  *
170  * env: the CPU state
171  * code: the exit code
172  */
173 void preexit_cleanup(CPUArchState *env, int code);
174 
175 /*
176  * Include target-specific struct and function definitions;
177  * they may need access to the target-independent structures
178  * above, so include them last.
179  */
180 #include "target_cpu.h"
181 #include "target_structs.h"
182 
183 #endif
184