aboutsummaryrefslogtreecommitdiff
path: root/bsd-user/freebsd/target_os_user.h
blob: 95b1fa9f998006f67e6eccc8ef9c3fbbeac195ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
 *  sys/user.h definitions
 *
 *  Copyright (c) 2015 Stacey D. Son (sson at FreeBSD)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _TARGET_OS_USER_H_
#define _TARGET_OS_USER_H_

/*
 * from sys/priority.h
 */
struct target_priority {
    uint8_t     pri_class;      /* Scheduling class. */
    uint8_t     pri_level;      /* Normal priority level. */
    uint8_t     pri_native;     /* Priority before propogation. */
    uint8_t     pri_user;       /* User priority based on p_cpu and p_nice. */
};

/*
 * sys/caprights.h
 */
#define TARGET_CAP_RIGHTS_VERSION  0

typedef struct target_cap_rights {
    uint64_t    cr_rights[TARGET_CAP_RIGHTS_VERSION + 2];
} target_cap_rights_t;

/*
 * From sys/_socketaddr_storage.h
 *
 */
#define TARGET_SS_MAXSIZE     128U
#define TARGET_SS_ALIGNSIZE   (sizeof(__int64_t))
#define TARGET_SS_PAD1SIZE    (TARGET_SS_ALIGNSIZE - sizeof(unsigned char) - \
        sizeof(uint8_t))
#define TARGET_SS_PAD2SIZE    (TARGET_SS_MAXSIZE - sizeof(unsigned char) - \
        sizeof(uint8_t) - TARGET_SS_PAD1SIZE - TARGET_SS_ALIGNSIZE)

struct target_sockaddr_storage {
    unsigned char   ss_len;         /* address length */
    uint8_t         ss_family;      /* address family */
    char            __ss_pad1[TARGET_SS_PAD1SIZE];
    __int64_t       __ss_align;     /* force desired struct alignment */
    char            __ss_pad2[TARGET_SS_PAD2SIZE];
};

/*
 * from sys/user.h
 */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
#define TARGET_KI_NSPARE_INT        2
#elif defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
#define TARGET_KI_NSPARE_INT        4
#elif defined(__FreeBSD_version) && __FreeBSD_version >= 1000000
#define TARGET_KI_NSPARE_INT        7
#else
#define TARGET_KI_NSPARE_INT        9
#endif /* ! __FreeBSD_version >= 1000000 */
#define TARGET_KI_NSPARE_LONG       12
#define TARGET_KI_NSPARE_PTR        6

#define TARGET_WMESGLEN             8
#define TARGET_LOCKNAMELEN          8
#define TARGET_TDNAMLEN             16
#define TARGET_COMMLEN              19
#define TARGET_KI_EMULNAMELEN       16
#define TARGET_KI_NGROUPS           16
#define TARGET_LOGNAMELEN           17
#define TARGET_LOGINCLASSLEN        17

#define TARGET_KF_TYPE_NONE         0
#define TARGET_KF_TYPE_VNODE        1
#define TARGET_KF_TYPE_SOCKET       2
#define TARGET_KF_TYPE_PIPE         3
#define TARGET_KF_TYPE_FIFO         4
#define TARGET_KF_TYPE_KQUEUE       5
#define TARGET_KF_TYPE_CRYPTO       6
#define TARGET_KF_TYPE_MQUEUE       7
#define TARGET_KF_TYPE_SHM          8
#define TARGET_KF_TYPE_SEM          9
#define TARGET_KF_TYPE_PTS          10
#define TARGET_KF_TYPE_PROCDESC     11
#define TARGET_KF_TYPE_DEV          12
#define TARGET_KF_TYPE_UNKNOWN      255

struct target_kinfo_proc {
    int32_t     ki_structsize;      /* size of this structure */
    int32_t     ki_layout;          /* reserved: layout identifier */
    abi_ulong   ki_args;            /* address of command arguments */
    abi_ulong   ki_paddr;           /* address of proc */
    abi_ulong   ki_addr;            /* kernel virtual addr of u-area */
    abi_ulong   ki_tracep;          /* pointer to trace file */
    abi_ulong   ki_textvp;          /* pointer to executable file */
    abi_ulong   ki_fd;              /* pointer to open file info */
    abi_ulong   ki_vmspace;         /* pointer to kernel vmspace struct */
    abi_ulong   ki_wchan;           /* sleep address */
    int32_t     ki_pid;             /* Process identifier */
    int32_t     ki_ppid;            /* parent process id */
    int32_t     ki_pgid;            /* process group id */
    int32_t     ki_tpgid;           /* tty process group id */
    int32_t     ki_sid;             /* Process session ID */
    int32_t     ki_tsid;            /* Terminal session ID */
    int16_t     ki_jobc;            /* job control counter */
    int16_t     ki_spare_short1;    /* unused (just here for alignment) */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
    int32_t     ki_tdev__freebsd11; /* controlling tty dev */
#else
    int32_t     ki_tdev;            /* controlling tty dev */
#endif
    target_sigset_t ki_siglist;     /* Signals arrived but not delivered */
    target_sigset_t ki_sigmask;     /* Current signal mask */
    target_sigset_t ki_sigignore;   /* Signals being ignored */
    target_sigset_t ki_sigcatch;    /* Signals being caught by user */

    int32_t     ki_uid;             /* effective user id */
    int32_t     ki_ruid;            /* Real user id */
    int32_t     ki_svuid;           /* Saved effective user id */
    int32_t     ki_rgid;            /* Real group id */
    int32_t     ki_svgid;           /* Saved effective group id */
    int16_t     ki_ngroups;         /* number of groups */
    int16_t     ki_spare_short2;    /* unused (just here for alignment) */
    int32_t     ki_groups[TARGET_KI_NGROUPS];  /* groups */

    abi_long    ki_size;            /* virtual size */

    abi_long    ki_rssize;          /* current resident set size in pages */
    abi_long    ki_swrss;           /* resident set size before last swap */
    abi_long    ki_tsize;           /* text size (pages) XXX */
    abi_long    ki_dsize;           /* data size (pages) XXX */
    abi_long    ki_ssize;           /* stack size (pages) */

    uint16_t    ki_xstat;           /* Exit status for wait & stop signal */
    uint16_t    ki_acflag;          /* Accounting flags */

    uint32_t    ki_pctcpu;          /* %cpu for process during ki_swtime */

    uint32_t    ki_estcpu;          /* Time averaged value of ki_cpticks */
    uint32_t    ki_slptime;         /* Time since last blocked */
    uint32_t    ki_swtime;          /* Time swapped in or out */
    uint32_t    ki_cow;             /* number of copy-on-write faults */
    uint64_t    ki_runtime;         /* Real time in microsec */

    struct  target_freebsd_timeval ki_start;  /* starting time */
    struct  target_freebsd_timeval ki_childtime; /* time used by process children */

    abi_long    ki_flag;            /* P_* flags */
    abi_long    ki_kiflag;          /* KI_* flags (below) */
    int32_t     ki_traceflag;       /* Kernel trace points */
    char        ki_stat;            /* S* process status */
    int8_t      ki_nice;            /* Process "nice" value */
    char        ki_lock;            /* Process lock (prevent swap) count */
    char        ki_rqindex;         /* Run queue index */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
    u_char      ki_oncpu_old;       /* Which cpu we are on (legacy) */
    u_char      ki_lastcpu_old;     /* Last cpu we were on (legacy) */
#else
    u_char      ki_oncpu;           /* Which cpu we are on */
    u_char      ki_lastcpu;         /* Last cpu we were on */
#endif /* ! __FreeBSD_version >= 1100000 */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    char        ki_tdname[TARGET_TDNAMLEN + 1];  /* thread name */
#else
    char        ki_ocomm[TARGET_TDNAMLEN + 1];   /* thread name */
#endif /* ! __FreeBSD_version >= 900000 */
    char        ki_wmesg[TARGET_WMESGLEN + 1];   /* wchan message */
    char        ki_login[TARGET_LOGNAMELEN + 1]; /* setlogin name */
    char        ki_lockname[TARGET_LOCKNAMELEN + 1]; /* lock name */
    char        ki_comm[TARGET_COMMLEN + 1];     /* command name */
    char        ki_emul[TARGET_KI_EMULNAMELEN + 1];  /* emulation name */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    char        ki_loginclass[TARGET_LOGINCLASSLEN + 1]; /* login class */
#endif /* ! __FreeBSD_version >= 900000 */

#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    char        ki_sparestrings[50];    /* spare string space */
#else
    char        ki_sparestrings[68];    /* spare string space */
#endif /* ! __FreeBSD_version >= 900000 */
    int32_t     ki_spareints[TARGET_KI_NSPARE_INT]; /* spare room for growth */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
 uint64_t ki_tdev;  /* controlling tty dev */
#endif
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1100000
    int32_t     ki_oncpu;           /* Which cpu we are on */
    int32_t     ki_lastcpu;         /* Last cpu we were on */
    int32_t     ki_tracer;          /* Pid of tracing process */
#endif /* __FreeBSD_version >= 1100000 */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    int32_t     ki_flag2;           /* P2_* flags */
    int32_t     ki_fibnum;          /* Default FIB number */
#endif /* ! __FreeBSD_version >= 900000 */
    uint32_t    ki_cr_flags;        /* Credential flags */
    int32_t     ki_jid;             /* Process jail ID */
    int32_t     ki_numthreads;      /* XXXKSE number of threads in total */

    int32_t     ki_tid;             /* XXXKSE thread id */

    struct  target_priority ki_pri; /* process priority */
    struct  target_freebsd_rusage ki_rusage;  /* process rusage statistics */
        /* XXX - most fields in ki_rusage_ch are not (yet) filled in */
    struct  target_freebsd_rusage ki_rusage_ch; /* rusage of children processes */


    abi_ulong   ki_pcb;             /* kernel virtual addr of pcb */
    abi_ulong   ki_kstack;          /* kernel virtual addr of stack */
    abi_ulong   ki_udata;           /* User convenience pointer */
    abi_ulong   ki_tdaddr;          /* address of thread */

    abi_ulong   ki_spareptrs[TARGET_KI_NSPARE_PTR];  /* spare room for growth */
    abi_long    ki_sparelongs[TARGET_KI_NSPARE_LONG];/* spare room for growth */
    abi_long    ki_sflag;           /* PS_* flags */
    abi_long    ki_tdflags;         /* XXXKSE kthread flag */
};

struct target_kinfo_file {
    int32_t  kf_structsize;  /* Variable size of record. */
    int32_t  kf_type;  /* Descriptor type. */
    int32_t  kf_fd;   /* Array index. */
    int32_t  kf_ref_count;  /* Reference count. */
    int32_t  kf_flags;  /* Flags. */
    int32_t  kf_pad0;  /* Round to 64 bit alignment. */
    int64_t  kf_offset;  /* Seek location. */
#if defined(__FreeBSD_version) && __FreeBSD_version < 1200031
    int32_t  kf_vnode_type;  /* Vnode type. */
    int32_t  kf_sock_domain;  /* Socket domain. */
    int32_t  kf_sock_type;  /* Socket type. */
    int32_t  kf_sock_protocol; /* Socket protocol. */
    struct target_sockaddr_storage kf_sa_local; /* Socket address. */
    struct target_sockaddr_storage kf_sa_peer; /* Peer address. */
#endif
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    union {
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            uint32_t kf_spareint;
            /* Socket domain. */
            int  kf_sock_domain0;
            /* Socket type. */
            int  kf_sock_type0;
            /* Socket protocol. */
            int  kf_sock_protocol0;
            /* Socket address. */
            struct sockaddr_storage kf_sa_local;
            /* Peer address. */
            struct sockaddr_storage kf_sa_peer;
#endif
            /* Address of so_pcb. */
            uint64_t kf_sock_pcb;
            /* Address of inp_ppcb. */
            uint64_t kf_sock_inpcb;
            /* Address of unp_conn. */
            uint64_t kf_sock_unpconn;
            /* Send buffer state. */
            uint16_t kf_sock_snd_sb_state;
            /* Receive buffer state. */
            uint16_t kf_sock_rcv_sb_state;
            /* Round to 64 bit alignment. */
            uint32_t kf_sock_pad0;
        } kf_sock;
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            /* Vnode type. */
            int  kf_file_type;
            /* Space for future use */
            int  kf_spareint[3];
            uint64_t kf_spareint64[30];
            /* Vnode filesystem id. */
            uint64_t kf_file_fsid;
            /* File device. */
            uint64_t kf_file_rdev;
            /* Global file id. */
            uint64_t kf_file_fileid;
            /* File size. */
            uint64_t kf_file_size;
            /* Vnode filesystem id, FreeBSD 11 compat. */
            uint32_t kf_file_fsid_freebsd11;
            /* File device, FreeBSD 11 compat. */
            uint32_t kf_file_rdev_freebsd11;
#else
            /* Global file id. */
            uint64_t kf_file_fileid;
            /* File size. */
            uint64_t kf_file_size;
            /* Vnode filesystem id. */
            uint32_t kf_file_fsid;
            /* File device. */
            uint32_t kf_file_rdev;
#endif
            /* File mode. */
            uint16_t kf_file_mode;
            /* Round to 64 bit alignment. */
            uint16_t kf_file_pad0;
            uint32_t kf_file_pad1;
        } kf_file;
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            uint32_t kf_spareint[4];
            uint64_t kf_spareint64[32];
#endif
            uint32_t kf_sem_value;
            uint16_t kf_sem_mode;
        } kf_sem;
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            uint32_t kf_spareint[4];
            uint64_t kf_spareint64[32];
#endif
            uint64_t kf_pipe_addr;
            uint64_t kf_pipe_peer;
            uint32_t kf_pipe_buffer_cnt;
            /* Round to 64 bit alignment. */
            uint32_t kf_pipe_pad0[3];
        } kf_pipe;
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            uint32_t kf_spareint[4];
            uint64_t kf_spareint64[32];
            uint32_t kf_pts_dev_freebsd11;
            uint32_t kf_pts_pad0;
            uint64_t kf_pts_dev;
            /* Round to 64 bit alignment. */
            uint32_t kf_pts_pad1[4];
#else
            uint32_t kf_pts_dev;
            /* Round to 64 bit alignment. */
            uint32_t kf_pts_pad0[7];
#endif
        } kf_pts;
        struct {
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
            uint32_t kf_spareint[4];
            uint64_t kf_spareint64[32];
#endif
            int32_t  kf_pid;
        } kf_proc;
    } kf_un;
    uint16_t kf_status;  /* Status flags. */
    uint16_t kf_pad1;  /* Round to 32 bit alignment. */
    int32_t  _kf_ispare0;  /* Space for more stuff. */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1000000
    target_cap_rights_t kf_cap_rights; /* Capability rights. */
    uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */
#else /* ! __FreeBSD_version >= 1000000 */
    uint64_t        kf_cap_rights;
    int  _kf_ispare[4];
#endif /* ! __FreeBSD_version >= 1000000 */

#else /* ! __FreeBSD_version >= 900000 */
    int  _kf_ispare[16];
#endif /* ! __FreeBSD_version >= 900000 */
    /* Truncated before copyout in sysctl */
    char  kf_path[PATH_MAX]; /* Path to file, if any. */
};

struct target_kinfo_vmentry {
    int32_t  kve_structsize;  /* Variable size of record. */
    int32_t  kve_type;   /* Type of map entry. */
    uint64_t kve_start;   /* Starting address. */
    uint64_t kve_end;   /* Finishing address. */
    uint64_t kve_offset;   /* Mapping offset in object */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    uint64_t kve_vn_fileid;   /* inode number if vnode */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
    uint32_t kve_vn_fsid_freebsd11;  /* dev_t of vnode location */
#else
    uint32_t kve_vn_fsid;   /* dev_t of vnode location */
#endif
#else /* !  __FreeBSD_version >= 900000 */
    uint64_t kve_fileid;   /* inode number if vnode */
    uint32_t kve_fsid;   /* dev_t of vnode location */
#endif /* !  __FreeBSD_version >= 900000 */
    int32_t  kve_flags;   /* Flags on map entry. */
    int32_t  kve_resident;   /* Number of resident pages. */
    int32_t  kve_private_resident;  /* Number of private pages. */
    int32_t  kve_protection;  /* Protection bitmask. */
    int32_t  kve_ref_count;   /* VM obj ref count. */
    int32_t  kve_shadow_count;  /* VM obj shadow count. */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
    int32_t  kve_vn_type;   /* Vnode type. */
    uint64_t kve_vn_size;   /* File size. */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
    uint32_t kve_vn_rdev_freebsd11;  /* Device id if device. */
#else
    uint32_t kve_vn_rdev;   /* Device id if device. */
#endif
    uint16_t kve_vn_mode;   /* File mode. */
    uint16_t kve_status;   /* Status flags. */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
#if (__FreeBSD_version >= 1300501 && __FreeBSD_version < 1400000) ||    \
    __FreeBSD_version >= 1400009
    union {
        uint64_t _kve_vn_fsid;  /* dev_t of vnode location */
        uint64_t _kve_obj;  /* handle of anon obj */
    } kve_type_spec;
#define kve_vn_fsid kve_type_spec._kve_vn_fsid
#define kve_obj  kve_type_spec._kve_obj
#else
    uint64_t kve_vn_fsid;   /* dev_t of vnode location */
#endif
    uint64_t kve_vn_rdev;   /* Device id if device. */
    int  _kve_ispare[8];  /* Space for more stuff. */
#else
    int32_t  _kve_ispare[12];  /* Space for more stuff. */
#endif
#else /* !  __FreeBSD_version >= 900000 */
    int  _kve_pad0;
    int32_t  _kve_ispare[16];  /* Space for more stuff. */
#endif /* !  __FreeBSD_version >= 900000 */
    /* Truncated before copyout in sysctl */
    char  kve_path[PATH_MAX];  /* Path to VM obj, if any. */
};

#endif /* ! _TARGET_OS_USER_H_ */