user-internals.h 5.6 KB

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