2
0

target_os_user.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * sys/user.h definitions
  3. *
  4. * Copyright (c) 2015 Stacey D. Son (sson at FreeBSD)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TARGET_OS_USER_H
  20. #define TARGET_OS_USER_H
  21. /*
  22. * from sys/priority.h
  23. */
  24. struct target_priority {
  25. uint8_t pri_class; /* Scheduling class. */
  26. uint8_t pri_level; /* Normal priority level. */
  27. uint8_t pri_native; /* Priority before propagation. */
  28. uint8_t pri_user; /* User priority based on p_cpu and p_nice. */
  29. };
  30. /*
  31. * sys/caprights.h
  32. */
  33. #define TARGET_CAP_RIGHTS_VERSION 0
  34. typedef struct target_cap_rights {
  35. uint64_t cr_rights[TARGET_CAP_RIGHTS_VERSION + 2];
  36. } target_cap_rights_t;
  37. /*
  38. * From sys/_socketaddr_storage.h
  39. *
  40. */
  41. #define TARGET_SS_MAXSIZE 128U
  42. #define TARGET_SS_ALIGNSIZE (sizeof(__int64_t))
  43. #define TARGET_SS_PAD1SIZE (TARGET_SS_ALIGNSIZE - sizeof(unsigned char) - \
  44. sizeof(uint8_t))
  45. #define TARGET_SS_PAD2SIZE (TARGET_SS_MAXSIZE - sizeof(unsigned char) - \
  46. sizeof(uint8_t) - TARGET_SS_PAD1SIZE - TARGET_SS_ALIGNSIZE)
  47. struct target_sockaddr_storage {
  48. unsigned char ss_len; /* address length */
  49. uint8_t ss_family; /* address family */
  50. char __ss_pad1[TARGET_SS_PAD1SIZE];
  51. __int64_t __ss_align; /* force desired struct alignment */
  52. char __ss_pad2[TARGET_SS_PAD2SIZE];
  53. };
  54. /*
  55. * from sys/user.h
  56. */
  57. #define TARGET_KI_NSPARE_INT 2
  58. #define TARGET_KI_NSPARE_LONG 12
  59. #define TARGET_KI_NSPARE_PTR 6
  60. #define TARGET_WMESGLEN 8
  61. #define TARGET_LOCKNAMELEN 8
  62. #define TARGET_TDNAMLEN 16
  63. #define TARGET_COMMLEN 19
  64. #define TARGET_KI_EMULNAMELEN 16
  65. #define TARGET_KI_NGROUPS 16
  66. #define TARGET_LOGNAMELEN 17
  67. #define TARGET_LOGINCLASSLEN 17
  68. #define TARGET_KF_TYPE_NONE 0
  69. #define TARGET_KF_TYPE_VNODE 1
  70. #define TARGET_KF_TYPE_SOCKET 2
  71. #define TARGET_KF_TYPE_PIPE 3
  72. #define TARGET_KF_TYPE_FIFO 4
  73. #define TARGET_KF_TYPE_KQUEUE 5
  74. #define TARGET_KF_TYPE_CRYPTO 6
  75. #define TARGET_KF_TYPE_MQUEUE 7
  76. #define TARGET_KF_TYPE_SHM 8
  77. #define TARGET_KF_TYPE_SEM 9
  78. #define TARGET_KF_TYPE_PTS 10
  79. #define TARGET_KF_TYPE_PROCDESC 11
  80. #define TARGET_KF_TYPE_DEV 12
  81. #define TARGET_KF_TYPE_UNKNOWN 255
  82. struct target_kinfo_proc {
  83. int32_t ki_structsize; /* size of this structure */
  84. int32_t ki_layout; /* reserved: layout identifier */
  85. abi_ulong ki_args; /* address of command arguments */
  86. abi_ulong ki_paddr; /* address of proc */
  87. abi_ulong ki_addr; /* kernel virtual addr of u-area */
  88. abi_ulong ki_tracep; /* pointer to trace file */
  89. abi_ulong ki_textvp; /* pointer to executable file */
  90. abi_ulong ki_fd; /* pointer to open file info */
  91. abi_ulong ki_vmspace; /* pointer to kernel vmspace struct */
  92. abi_ulong ki_wchan; /* sleep address */
  93. int32_t ki_pid; /* Process identifier */
  94. int32_t ki_ppid; /* parent process id */
  95. int32_t ki_pgid; /* process group id */
  96. int32_t ki_tpgid; /* tty process group id */
  97. int32_t ki_sid; /* Process session ID */
  98. int32_t ki_tsid; /* Terminal session ID */
  99. int16_t ki_jobc; /* job control counter */
  100. int16_t ki_spare_short1; /* unused (just here for alignment) */
  101. int32_t ki_tdev__freebsd11; /* controlling tty dev */
  102. target_sigset_t ki_siglist; /* Signals arrived but not delivered */
  103. target_sigset_t ki_sigmask; /* Current signal mask */
  104. target_sigset_t ki_sigignore; /* Signals being ignored */
  105. target_sigset_t ki_sigcatch; /* Signals being caught by user */
  106. int32_t ki_uid; /* effective user id */
  107. int32_t ki_ruid; /* Real user id */
  108. int32_t ki_svuid; /* Saved effective user id */
  109. int32_t ki_rgid; /* Real group id */
  110. int32_t ki_svgid; /* Saved effective group id */
  111. int16_t ki_ngroups; /* number of groups */
  112. int16_t ki_spare_short2; /* unused (just here for alignment) */
  113. int32_t ki_groups[TARGET_KI_NGROUPS]; /* groups */
  114. abi_long ki_size; /* virtual size */
  115. abi_long ki_rssize; /* current resident set size in pages */
  116. abi_long ki_swrss; /* resident set size before last swap */
  117. abi_long ki_tsize; /* text size (pages) XXX */
  118. abi_long ki_dsize; /* data size (pages) XXX */
  119. abi_long ki_ssize; /* stack size (pages) */
  120. uint16_t ki_xstat; /* Exit status for wait & stop signal */
  121. uint16_t ki_acflag; /* Accounting flags */
  122. uint32_t ki_pctcpu; /* %cpu for process during ki_swtime */
  123. uint32_t ki_estcpu; /* Time averaged value of ki_cpticks */
  124. uint32_t ki_slptime; /* Time since last blocked */
  125. uint32_t ki_swtime; /* Time swapped in or out */
  126. uint32_t ki_cow; /* number of copy-on-write faults */
  127. uint64_t ki_runtime; /* Real time in microsec */
  128. struct target_freebsd_timeval ki_start; /* starting time */
  129. struct target_freebsd_timeval ki_childtime; /* time used by process children */
  130. abi_long ki_flag; /* P_* flags */
  131. abi_long ki_kiflag; /* KI_* flags (below) */
  132. int32_t ki_traceflag; /* Kernel trace points */
  133. char ki_stat; /* S* process status */
  134. int8_t ki_nice; /* Process "nice" value */
  135. char ki_lock; /* Process lock (prevent swap) count */
  136. char ki_rqindex; /* Run queue index */
  137. u_char ki_oncpu_old; /* Which cpu we are on (legacy) */
  138. u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */
  139. char ki_tdname[TARGET_TDNAMLEN + 1]; /* thread name */
  140. char ki_wmesg[TARGET_WMESGLEN + 1]; /* wchan message */
  141. char ki_login[TARGET_LOGNAMELEN + 1]; /* setlogin name */
  142. char ki_lockname[TARGET_LOCKNAMELEN + 1]; /* lock name */
  143. char ki_comm[TARGET_COMMLEN + 1]; /* command name */
  144. char ki_emul[TARGET_KI_EMULNAMELEN + 1]; /* emulation name */
  145. char ki_loginclass[TARGET_LOGINCLASSLEN + 1]; /* login class */
  146. char ki_sparestrings[50]; /* spare string space */
  147. int32_t ki_spareints[TARGET_KI_NSPARE_INT]; /* spare room for growth */
  148. uint64_t ki_tdev; /* controlling tty dev */
  149. int32_t ki_oncpu; /* Which cpu we are on */
  150. int32_t ki_lastcpu; /* Last cpu we were on */
  151. int32_t ki_tracer; /* Pid of tracing process */
  152. int32_t ki_flag2; /* P2_* flags */
  153. int32_t ki_fibnum; /* Default FIB number */
  154. uint32_t ki_cr_flags; /* Credential flags */
  155. int32_t ki_jid; /* Process jail ID */
  156. int32_t ki_numthreads; /* XXXKSE number of threads in total */
  157. int32_t ki_tid; /* XXXKSE thread id */
  158. struct target_priority ki_pri; /* process priority */
  159. struct target_freebsd_rusage ki_rusage; /* process rusage statistics */
  160. /* XXX - most fields in ki_rusage_ch are not (yet) filled in */
  161. struct target_freebsd_rusage ki_rusage_ch; /* rusage of children processes */
  162. abi_ulong ki_pcb; /* kernel virtual addr of pcb */
  163. abi_ulong ki_kstack; /* kernel virtual addr of stack */
  164. abi_ulong ki_udata; /* User convenience pointer */
  165. abi_ulong ki_tdaddr; /* address of thread */
  166. abi_ulong ki_spareptrs[TARGET_KI_NSPARE_PTR]; /* spare room for growth */
  167. abi_long ki_sparelongs[TARGET_KI_NSPARE_LONG];/* spare room for growth */
  168. abi_long ki_sflag; /* PS_* flags */
  169. abi_long ki_tdflags; /* XXXKSE kthread flag */
  170. };
  171. struct target_kinfo_file {
  172. int32_t kf_structsize; /* Variable size of record. */
  173. int32_t kf_type; /* Descriptor type. */
  174. int32_t kf_fd; /* Array index. */
  175. int32_t kf_ref_count; /* Reference count. */
  176. int32_t kf_flags; /* Flags. */
  177. int32_t kf_pad0; /* Round to 64 bit alignment. */
  178. int64_t kf_offset; /* Seek location. */
  179. union {
  180. struct {
  181. uint32_t kf_spareint;
  182. /* Socket domain. */
  183. int kf_sock_domain0;
  184. /* Socket type. */
  185. int kf_sock_type0;
  186. /* Socket protocol. */
  187. int kf_sock_protocol0;
  188. /* Socket address. */
  189. struct sockaddr_storage kf_sa_local;
  190. /* Peer address. */
  191. struct sockaddr_storage kf_sa_peer;
  192. /* Address of so_pcb. */
  193. uint64_t kf_sock_pcb;
  194. /* Address of inp_ppcb. */
  195. uint64_t kf_sock_inpcb;
  196. /* Address of unp_conn. */
  197. uint64_t kf_sock_unpconn;
  198. /* Send buffer state. */
  199. uint16_t kf_sock_snd_sb_state;
  200. /* Receive buffer state. */
  201. uint16_t kf_sock_rcv_sb_state;
  202. /* Round to 64 bit alignment. */
  203. uint32_t kf_sock_pad0;
  204. } kf_sock;
  205. struct {
  206. /* Vnode type. */
  207. int kf_file_type;
  208. /* Space for future use */
  209. int kf_spareint[3];
  210. uint64_t kf_spareint64[30];
  211. /* Vnode filesystem id. */
  212. uint64_t kf_file_fsid;
  213. /* File device. */
  214. uint64_t kf_file_rdev;
  215. /* Global file id. */
  216. uint64_t kf_file_fileid;
  217. /* File size. */
  218. uint64_t kf_file_size;
  219. /* Vnode filesystem id, FreeBSD 11 compat. */
  220. uint32_t kf_file_fsid_freebsd11;
  221. /* File device, FreeBSD 11 compat. */
  222. uint32_t kf_file_rdev_freebsd11;
  223. /* File mode. */
  224. uint16_t kf_file_mode;
  225. /* Round to 64 bit alignment. */
  226. uint16_t kf_file_pad0;
  227. uint32_t kf_file_pad1;
  228. } kf_file;
  229. struct {
  230. uint32_t kf_spareint[4];
  231. uint64_t kf_spareint64[32];
  232. uint32_t kf_sem_value;
  233. uint16_t kf_sem_mode;
  234. } kf_sem;
  235. struct {
  236. uint32_t kf_spareint[4];
  237. uint64_t kf_spareint64[32];
  238. uint64_t kf_pipe_addr;
  239. uint64_t kf_pipe_peer;
  240. uint32_t kf_pipe_buffer_cnt;
  241. /* Round to 64 bit alignment. */
  242. uint32_t kf_pipe_pad0[3];
  243. } kf_pipe;
  244. struct {
  245. uint32_t kf_spareint[4];
  246. uint64_t kf_spareint64[32];
  247. uint32_t kf_pts_dev_freebsd11;
  248. uint32_t kf_pts_pad0;
  249. uint64_t kf_pts_dev;
  250. /* Round to 64 bit alignment. */
  251. uint32_t kf_pts_pad1[4];
  252. } kf_pts;
  253. struct {
  254. uint32_t kf_spareint[4];
  255. uint64_t kf_spareint64[32];
  256. int32_t kf_pid;
  257. } kf_proc;
  258. } kf_un;
  259. uint16_t kf_status; /* Status flags. */
  260. uint16_t kf_pad1; /* Round to 32 bit alignment. */
  261. int32_t _kf_ispare0; /* Space for more stuff. */
  262. target_cap_rights_t kf_cap_rights; /* Capability rights. */
  263. uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */
  264. /* Truncated before copyout in sysctl */
  265. char kf_path[PATH_MAX]; /* Path to file, if any. */
  266. };
  267. struct target_kinfo_vmentry {
  268. int32_t kve_structsize; /* Variable size of record. */
  269. int32_t kve_type; /* Type of map entry. */
  270. uint64_t kve_start; /* Starting address. */
  271. uint64_t kve_end; /* Finishing address. */
  272. uint64_t kve_offset; /* Mapping offset in object */
  273. uint64_t kve_vn_fileid; /* inode number if vnode */
  274. uint32_t kve_vn_fsid_freebsd11; /* dev_t of vnode location */
  275. int32_t kve_flags; /* Flags on map entry. */
  276. int32_t kve_resident; /* Number of resident pages. */
  277. int32_t kve_private_resident; /* Number of private pages. */
  278. int32_t kve_protection; /* Protection bitmask. */
  279. int32_t kve_ref_count; /* VM obj ref count. */
  280. int32_t kve_shadow_count; /* VM obj shadow count. */
  281. int32_t kve_vn_type; /* Vnode type. */
  282. uint64_t kve_vn_size; /* File size. */
  283. uint32_t kve_vn_rdev_freebsd11; /* Device id if device. */
  284. uint16_t kve_vn_mode; /* File mode. */
  285. uint16_t kve_status; /* Status flags. */
  286. #if (__FreeBSD_version >= 1300501 && __FreeBSD_version < 1400000) || \
  287. __FreeBSD_version >= 1400009
  288. union {
  289. uint64_t _kve_vn_fsid; /* dev_t of vnode location */
  290. uint64_t _kve_obj; /* handle of anon obj */
  291. } kve_type_spec;
  292. #define kve_vn_fsid kve_type_spec._kve_vn_fsid
  293. #define kve_obj kve_type_spec._kve_obj
  294. #else
  295. uint64_t kve_vn_fsid; /* dev_t of vnode location */
  296. #endif
  297. uint64_t kve_vn_rdev; /* Device id if device. */
  298. int _kve_ispare[8]; /* Space for more stuff. */
  299. /* Truncated before copyout in sysctl */
  300. char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
  301. };
  302. #endif /* TARGET_OS_USER_H */