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