]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/amd64/linux/linux.h
Merge libc++ trunk r300890, and update build glue.
[FreeBSD/FreeBSD.git] / sys / amd64 / linux / linux.h
1 /*-
2  * Copyright (c) 2013 Dmitry Chagin
3  * Copyright (c) 1994-1996 Søren Schmidt
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer
11  *    in this position and unchanged.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #ifndef _AMD64_LINUX_H_
33 #define _AMD64_LINUX_H_
34
35 #include <compat/linux/linux.h>
36 #include <amd64/linux/linux_syscall.h>
37
38 /*
39  * debugging support
40  */
41 extern u_char linux_debug_map[];
42 #define ldebug(name)    isclr(linux_debug_map, LINUX_SYS_linux_ ## name)
43 #define ARGS(nm, fmt)   "linux(%ld/%ld): "#nm"("fmt")\n",                       \
44                         (long)td->td_proc->p_pid, (long)td->td_tid
45 #define LMSG(fmt)       "linux(%ld/%ld): "fmt"\n",                              \
46                         (long)td->td_proc->p_pid, (long)td->td_tid
47 #define LINUX_DTRACE    linuxulator
48
49 #define PTRIN(v)        (void *)(v)
50 #define PTROUT(v)       (uintptr_t)(v)
51
52 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
53 #define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
54 #define PTRIN_CP(src,dst,fld) \
55         do { (dst).fld = PTRIN((src).fld); } while (0)
56
57 /*
58  * Provide a separate set of types for the Linux types.
59  */
60 typedef int32_t         l_int;
61 typedef int64_t         l_long;
62 typedef int16_t         l_short;
63 typedef uint32_t        l_uint;
64 typedef uint64_t        l_ulong;
65 typedef uint16_t        l_ushort;
66
67 typedef l_ulong         l_uintptr_t;
68 typedef l_long          l_clock_t;
69 typedef l_int           l_daddr_t;
70 typedef l_ulong         l_dev_t;
71 typedef l_uint          l_gid_t;
72 typedef l_ushort        l_gid16_t;
73 typedef l_uint          l_uid_t;
74 typedef l_ushort        l_uid16_t;
75 typedef l_ulong         l_ino_t;
76 typedef l_int           l_key_t;
77 typedef l_long          l_loff_t;
78 typedef l_uint          l_mode_t;
79 typedef l_long          l_off_t;
80 typedef l_int           l_pid_t;
81 typedef l_ulong         l_size_t;
82 typedef l_long          l_ssize_t;
83 typedef l_long          l_suseconds_t;
84 typedef l_long          l_time_t;
85 typedef l_int           l_timer_t;
86 typedef l_int           l_mqd_t;
87 typedef l_size_t        l_socklen_t;
88 typedef l_ulong         l_fd_mask;
89
90 typedef struct {
91         l_int           val[2];
92 } l_fsid_t;
93
94 typedef struct {
95         l_time_t        tv_sec;
96         l_suseconds_t   tv_usec;
97 } l_timeval;
98
99 #define l_fd_set        fd_set
100
101 /*
102  * Miscellaneous
103  */
104 #define LINUX_NAME_MAX          255
105 #define LINUX_CTL_MAXNAME       10
106
107 #define LINUX_AT_COUNT          19      /* Count of used aux entry types. */
108
109 struct l___sysctl_args
110 {
111         l_uintptr_t     name;
112         l_int           nlen;
113         l_uintptr_t     oldval;
114         l_uintptr_t     oldlenp;
115         l_uintptr_t     newval;
116         l_size_t        newlen;
117         l_ulong         __spare[4];
118 };
119
120 /* Scheduling policies */
121 #define LINUX_SCHED_OTHER       0
122 #define LINUX_SCHED_FIFO        1
123 #define LINUX_SCHED_RR          2
124
125 /* Resource limits */
126 #define LINUX_RLIMIT_CPU        0
127 #define LINUX_RLIMIT_FSIZE      1
128 #define LINUX_RLIMIT_DATA       2
129 #define LINUX_RLIMIT_STACK      3
130 #define LINUX_RLIMIT_CORE       4
131 #define LINUX_RLIMIT_RSS        5
132 #define LINUX_RLIMIT_NPROC      6
133 #define LINUX_RLIMIT_NOFILE     7
134 #define LINUX_RLIMIT_MEMLOCK    8
135 #define LINUX_RLIMIT_AS         9       /* Address space limit */
136
137 #define LINUX_RLIM_NLIMITS      10
138
139 struct l_rlimit {
140         l_ulong         rlim_cur;
141         l_ulong         rlim_max;
142 };
143
144 /*
145  * stat family of syscalls
146  */
147 struct l_timespec {
148         l_time_t        tv_sec;
149         l_long          tv_nsec;
150 };
151
152 struct l_newstat {
153         l_dev_t         st_dev;
154         l_ino_t         st_ino;
155         l_ulong         st_nlink;
156         l_uint          st_mode;
157         l_uid_t         st_uid;
158         l_gid_t         st_gid;
159         l_uint          __st_pad1;
160         l_dev_t         st_rdev;
161         l_off_t         st_size;
162         l_long          st_blksize;
163         l_long          st_blocks;
164         struct l_timespec       st_atim;
165         struct l_timespec       st_mtim;
166         struct l_timespec       st_ctim;
167         l_long          __unused1;
168         l_long          __unused2;
169         l_long          __unused3;
170 };
171
172 /* sigaction flags */
173 #define LINUX_SA_NOCLDSTOP      0x00000001
174 #define LINUX_SA_NOCLDWAIT      0x00000002
175 #define LINUX_SA_SIGINFO        0x00000004
176 #define LINUX_SA_RESTORER       0x04000000
177 #define LINUX_SA_ONSTACK        0x08000000
178 #define LINUX_SA_RESTART        0x10000000
179 #define LINUX_SA_INTERRUPT      0x20000000
180 #define LINUX_SA_NOMASK         0x40000000
181 #define LINUX_SA_ONESHOT        0x80000000
182
183 /* sigprocmask actions */
184 #define LINUX_SIG_BLOCK         0
185 #define LINUX_SIG_UNBLOCK       1
186 #define LINUX_SIG_SETMASK       2
187
188 /* sigaltstack */
189 #define LINUX_MINSIGSTKSZ       2048
190
191 typedef void    (*l_handler_t)(l_int);
192
193 typedef struct {
194         l_handler_t     lsa_handler;
195         l_ulong         lsa_flags;
196         l_uintptr_t     lsa_restorer;
197         l_sigset_t      lsa_mask;
198 } l_sigaction_t;
199
200 typedef struct {
201         l_uintptr_t     ss_sp;
202         l_int           ss_flags;
203         l_size_t        ss_size;
204 } l_stack_t;
205
206 struct l_fpstate {
207         u_int16_t cwd;
208         u_int16_t swd;
209         u_int16_t twd;
210         u_int16_t fop;
211         u_int64_t rip;
212         u_int64_t rdp;
213         u_int32_t mxcsr;
214         u_int32_t mxcsr_mask;
215         u_int32_t st_space[32];
216         u_int32_t xmm_space[64];
217         u_int32_t reserved2[24];
218 };
219
220 struct l_sigcontext {
221         l_ulong         sc_r8;
222         l_ulong         sc_r9;
223         l_ulong         sc_r10;
224         l_ulong         sc_r11;
225         l_ulong         sc_r12;
226         l_ulong         sc_r13;
227         l_ulong         sc_r14;
228         l_ulong         sc_r15;
229         l_ulong         sc_rdi;
230         l_ulong         sc_rsi;
231         l_ulong         sc_rbp;
232         l_ulong         sc_rbx;
233         l_ulong         sc_rdx;
234         l_ulong         sc_rax;
235         l_ulong         sc_rcx;
236         l_ulong         sc_rsp;
237         l_ulong         sc_rip;
238         l_ulong         sc_rflags;
239         l_ushort        sc_cs;
240         l_ushort        sc_gs;
241         l_ushort        sc_fs;
242         l_ushort        sc___pad0;
243         l_ulong         sc_err;
244         l_ulong         sc_trapno;
245         l_sigset_t      sc_mask;
246         l_ulong         sc_cr2;
247         struct l_fpstate *sc_fpstate;
248         l_ulong         sc_reserved1[8];
249 };
250
251 struct l_ucontext {
252         l_ulong         uc_flags;
253         l_uintptr_t     uc_link;
254         l_stack_t       uc_stack;
255         struct l_sigcontext     uc_mcontext;
256         l_sigset_t      uc_sigmask;
257 };
258
259 #define LINUX_SI_PREAMBLE_SIZE  (4 * sizeof(int))
260 #define LINUX_SI_MAX_SIZE       128
261 #define LINUX_SI_PAD_SIZE       ((LINUX_SI_MAX_SIZE - \
262                                     LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int))
263 typedef union l_sigval {
264         l_int           sival_int;
265         l_uintptr_t     sival_ptr;
266 } l_sigval_t;
267
268 typedef struct l_siginfo {
269         l_int           lsi_signo;
270         l_int           lsi_errno;
271         l_int           lsi_code;
272         union {
273                 l_int   _pad[LINUX_SI_PAD_SIZE];
274
275                 struct {
276                         l_pid_t         _pid;
277                         l_uid_t         _uid;
278                 } _kill;
279
280                 struct {
281                         l_timer_t       _tid;
282                         l_int           _overrun;
283                         char            _pad[sizeof(l_uid_t) - sizeof(int)];
284                         union l_sigval  _sigval;
285                         l_uint          _sys_private;
286                 } _timer;
287
288                 struct {
289                         l_pid_t         _pid;           /* sender's pid */
290                         l_uid_t         _uid;           /* sender's uid */
291                         union l_sigval  _sigval;
292                 } _rt;
293
294                 struct {
295                         l_pid_t         _pid;           /* which child */
296                         l_uid_t         _uid;           /* sender's uid */
297                         l_int           _status;        /* exit code */
298                         l_clock_t       _utime;
299                         l_clock_t       _stime;
300                 } _sigchld;
301
302                 struct {
303                         l_uintptr_t     _addr;  /* Faulting insn/memory ref. */
304                 } _sigfault;
305
306                 struct {
307                         l_long          _band;  /* POLL_IN,POLL_OUT,POLL_MSG */
308                         l_int           _fd;
309                 } _sigpoll;
310         } _sifields;
311 } l_siginfo_t;
312
313 #define lsi_pid         _sifields._kill._pid
314 #define lsi_uid         _sifields._kill._uid
315 #define lsi_tid         _sifields._timer._tid
316 #define lsi_overrun     _sifields._timer._overrun
317 #define lsi_sys_private _sifields._timer._sys_private
318 #define lsi_status      _sifields._sigchld._status
319 #define lsi_utime       _sifields._sigchld._utime
320 #define lsi_stime       _sifields._sigchld._stime
321 #define lsi_value       _sifields._rt._sigval
322 #define lsi_int         _sifields._rt._sigval.sival_int
323 #define lsi_ptr         _sifields._rt._sigval.sival_ptr
324 #define lsi_addr        _sifields._sigfault._addr
325 #define lsi_band        _sifields._sigpoll._band
326 #define lsi_fd          _sifields._sigpoll._fd
327
328 /*
329  * We make the stack look like Linux expects it when calling a signal
330  * handler, but use the BSD way of calling the handler and sigreturn().
331  * This means that we need to pass the pointer to the handler too.
332  * It is appended to the frame to not interfere with the rest of it.
333  */
334
335 struct l_rt_sigframe {
336         struct l_ucontext       sf_sc;
337         struct l_siginfo        sf_si;
338         l_handler_t             sf_handler;
339 };
340
341 /*
342  * mount flags
343  */
344 #define LINUX_MS_RDONLY         0x0001
345 #define LINUX_MS_NOSUID         0x0002
346 #define LINUX_MS_NODEV          0x0004
347 #define LINUX_MS_NOEXEC         0x0008
348 #define LINUX_MS_REMOUNT        0x0020
349
350 /*
351  * SystemV IPC defines
352  */
353 #define LINUX_IPC_RMID          0
354 #define LINUX_IPC_SET           1
355 #define LINUX_IPC_STAT          2
356 #define LINUX_IPC_INFO          3
357
358 #define LINUX_SHM_LOCK          11
359 #define LINUX_SHM_UNLOCK        12
360 #define LINUX_SHM_STAT          13
361 #define LINUX_SHM_INFO          14
362
363 #define LINUX_SHM_RDONLY        0x1000
364 #define LINUX_SHM_RND           0x2000
365 #define LINUX_SHM_REMAP         0x4000
366
367 /* semctl commands */
368 #define LINUX_GETPID            11
369 #define LINUX_GETVAL            12
370 #define LINUX_GETALL            13
371 #define LINUX_GETNCNT           14
372 #define LINUX_GETZCNT           15
373 #define LINUX_SETVAL            16
374 #define LINUX_SETALL            17
375 #define LINUX_SEM_STAT          18
376 #define LINUX_SEM_INFO          19
377
378 union l_semun {
379         l_int           val;
380         l_uintptr_t     buf;
381         l_uintptr_t     array;
382         l_uintptr_t     __buf;
383         l_uintptr_t     __pad;
384 };
385
386 struct l_sockaddr {
387         l_ushort        sa_family;
388         char            sa_data[14];
389 };
390
391 struct l_ifmap {
392         l_ulong         mem_start;
393         l_ulong         mem_end;
394         l_ushort        base_addr;
395         u_char          irq;
396         u_char          dma;
397         u_char          port;
398 } __packed;
399
400 #define LINUX_IFHWADDRLEN       6
401 #define LINUX_IFNAMSIZ          16
402
403 struct l_ifreq {
404         union {
405                 char    ifrn_name[LINUX_IFNAMSIZ];
406         } ifr_ifrn;
407
408         union {
409                 struct l_sockaddr       ifru_addr;
410                 struct l_sockaddr       ifru_dstaddr;
411                 struct l_sockaddr       ifru_broadaddr;
412                 struct l_sockaddr       ifru_netmask;
413                 struct l_sockaddr       ifru_hwaddr;
414                 l_short         ifru_flags[1];
415                 l_int           ifru_ivalue;
416                 l_int           ifru_mtu;
417                 struct l_ifmap  ifru_map;
418                 char            ifru_slave[LINUX_IFNAMSIZ];
419                 l_uintptr_t     ifru_data;
420         } ifr_ifru;
421 } __packed;
422
423 #define ifr_name        ifr_ifrn.ifrn_name      /* Interface name */
424 #define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* MAC address */
425 #define ifr_ifindex     ifr_ifru.ifru_ivalue    /* Interface index */
426
427 struct l_ifconf {
428         int     ifc_len;
429         union {
430                 l_uintptr_t     ifcu_buf;
431                 l_uintptr_t     ifcu_req;
432         } ifc_ifcu;
433 };
434
435 #define ifc_buf         ifc_ifcu.ifcu_buf
436 #define ifc_req         ifc_ifcu.ifcu_req
437
438 /*
439  * poll()
440  */
441 #define LINUX_POLLIN            0x0001
442 #define LINUX_POLLPRI           0x0002
443 #define LINUX_POLLOUT           0x0004
444 #define LINUX_POLLERR           0x0008
445 #define LINUX_POLLHUP           0x0010
446 #define LINUX_POLLNVAL          0x0020
447 #define LINUX_POLLRDNORM        0x0040
448 #define LINUX_POLLRDBAND        0x0080
449 #define LINUX_POLLWRNORM        0x0100
450 #define LINUX_POLLWRBAND        0x0200
451 #define LINUX_POLLMSG           0x0400
452
453 struct l_pollfd {
454         l_int           fd;
455         l_short         events;
456         l_short         revents;
457 };
458
459
460 #define LINUX_CLONE_VM                  0x00000100
461 #define LINUX_CLONE_FS                  0x00000200
462 #define LINUX_CLONE_FILES               0x00000400
463 #define LINUX_CLONE_SIGHAND             0x00000800
464 #define LINUX_CLONE_PID                 0x00001000      /* No longer exist in Linux */
465 #define LINUX_CLONE_VFORK               0x00004000
466 #define LINUX_CLONE_PARENT              0x00008000
467 #define LINUX_CLONE_THREAD              0x00010000
468 #define LINUX_CLONE_SETTLS              0x00080000
469 #define LINUX_CLONE_PARENT_SETTID       0x00100000
470 #define LINUX_CLONE_CHILD_CLEARTID      0x00200000
471 #define LINUX_CLONE_CHILD_SETTID        0x01000000
472
473 #define LINUX_ARCH_SET_GS               0x1001
474 #define LINUX_ARCH_SET_FS               0x1002
475 #define LINUX_ARCH_GET_FS               0x1003
476 #define LINUX_ARCH_GET_GS               0x1004
477
478 #define linux_copyout_rusage(r, u)      copyout(r, u, sizeof(*r))
479
480 /* robust futexes */
481 struct linux_robust_list {
482         l_uintptr_t                     next;
483 };
484  
485 struct linux_robust_list_head {
486         struct linux_robust_list        list;
487         l_long                          futex_offset;
488         l_uintptr_t                     pending_list;
489 };
490
491 #endif /* !_AMD64_LINUX_H_ */