]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/amd64/linux/linux.h
Update our device tree files to a Linux 4.10
[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_uint          l_uid_t;
73 typedef l_ulong         l_ino_t;
74 typedef l_int           l_key_t;
75 typedef l_long          l_loff_t;
76 typedef l_uint          l_mode_t;
77 typedef l_long          l_off_t;
78 typedef l_int           l_pid_t;
79 typedef l_ulong         l_size_t;
80 typedef l_long          l_ssize_t;
81 typedef l_long          l_suseconds_t;
82 typedef l_long          l_time_t;
83 typedef l_int           l_timer_t;
84 typedef l_int           l_mqd_t;
85 typedef l_size_t        l_socklen_t;
86 typedef l_ulong         l_fd_mask;
87
88 typedef struct {
89         l_int           val[2];
90 } l_fsid_t;
91
92 typedef struct {
93         l_time_t        tv_sec;
94         l_suseconds_t   tv_usec;
95 } l_timeval;
96
97 #define l_fd_set        fd_set
98
99 /*
100  * Miscellaneous
101  */
102 #define LINUX_NAME_MAX          255
103 #define LINUX_CTL_MAXNAME       10
104
105 #define LINUX_AT_COUNT          19      /* Count of used aux entry types. */
106
107 struct l___sysctl_args
108 {
109         l_uintptr_t     name;
110         l_int           nlen;
111         l_uintptr_t     oldval;
112         l_uintptr_t     oldlenp;
113         l_uintptr_t     newval;
114         l_size_t        newlen;
115         l_ulong         __spare[4];
116 };
117
118 /* Scheduling policies */
119 #define LINUX_SCHED_OTHER       0
120 #define LINUX_SCHED_FIFO        1
121 #define LINUX_SCHED_RR          2
122
123 /* Resource limits */
124 #define LINUX_RLIMIT_CPU        0
125 #define LINUX_RLIMIT_FSIZE      1
126 #define LINUX_RLIMIT_DATA       2
127 #define LINUX_RLIMIT_STACK      3
128 #define LINUX_RLIMIT_CORE       4
129 #define LINUX_RLIMIT_RSS        5
130 #define LINUX_RLIMIT_NPROC      6
131 #define LINUX_RLIMIT_NOFILE     7
132 #define LINUX_RLIMIT_MEMLOCK    8
133 #define LINUX_RLIMIT_AS         9       /* Address space limit */
134
135 #define LINUX_RLIM_NLIMITS      10
136
137 struct l_rlimit {
138         l_ulong         rlim_cur;
139         l_ulong         rlim_max;
140 };
141
142 /*
143  * stat family of syscalls
144  */
145 struct l_timespec {
146         l_time_t        tv_sec;
147         l_long          tv_nsec;
148 };
149
150 struct l_newstat {
151         l_dev_t         st_dev;
152         l_ino_t         st_ino;
153         l_ulong         st_nlink;
154         l_uint          st_mode;
155         l_uid_t         st_uid;
156         l_gid_t         st_gid;
157         l_uint          __st_pad1;
158         l_dev_t         st_rdev;
159         l_off_t         st_size;
160         l_long          st_blksize;
161         l_long          st_blocks;
162         struct l_timespec       st_atim;
163         struct l_timespec       st_mtim;
164         struct l_timespec       st_ctim;
165         l_long          __unused1;
166         l_long          __unused2;
167         l_long          __unused3;
168 };
169
170 /* sigaction flags */
171 #define LINUX_SA_NOCLDSTOP      0x00000001
172 #define LINUX_SA_NOCLDWAIT      0x00000002
173 #define LINUX_SA_SIGINFO        0x00000004
174 #define LINUX_SA_RESTORER       0x04000000
175 #define LINUX_SA_ONSTACK        0x08000000
176 #define LINUX_SA_RESTART        0x10000000
177 #define LINUX_SA_INTERRUPT      0x20000000
178 #define LINUX_SA_NOMASK         0x40000000
179 #define LINUX_SA_ONESHOT        0x80000000
180
181 /* sigprocmask actions */
182 #define LINUX_SIG_BLOCK         0
183 #define LINUX_SIG_UNBLOCK       1
184 #define LINUX_SIG_SETMASK       2
185
186 /* sigaltstack */
187 #define LINUX_MINSIGSTKSZ       2048
188
189 typedef void    (*l_handler_t)(l_int);
190
191 typedef struct {
192         l_handler_t     lsa_handler;
193         l_ulong         lsa_flags;
194         l_uintptr_t     lsa_restorer;
195         l_sigset_t      lsa_mask;
196 } l_sigaction_t;
197
198 typedef struct {
199         l_uintptr_t     ss_sp;
200         l_int           ss_flags;
201         l_size_t        ss_size;
202 } l_stack_t;
203
204 struct l_fpstate {
205         u_int16_t cwd;
206         u_int16_t swd;
207         u_int16_t twd;
208         u_int16_t fop;
209         u_int64_t rip;
210         u_int64_t rdp;
211         u_int32_t mxcsr;
212         u_int32_t mxcsr_mask;
213         u_int32_t st_space[32];
214         u_int32_t xmm_space[64];
215         u_int32_t reserved2[24];
216 };
217
218 struct l_sigcontext {
219         l_ulong         sc_r8;
220         l_ulong         sc_r9;
221         l_ulong         sc_r10;
222         l_ulong         sc_r11;
223         l_ulong         sc_r12;
224         l_ulong         sc_r13;
225         l_ulong         sc_r14;
226         l_ulong         sc_r15;
227         l_ulong         sc_rdi;
228         l_ulong         sc_rsi;
229         l_ulong         sc_rbp;
230         l_ulong         sc_rbx;
231         l_ulong         sc_rdx;
232         l_ulong         sc_rax;
233         l_ulong         sc_rcx;
234         l_ulong         sc_rsp;
235         l_ulong         sc_rip;
236         l_ulong         sc_rflags;
237         l_ushort        sc_cs;
238         l_ushort        sc_gs;
239         l_ushort        sc_fs;
240         l_ushort        sc___pad0;
241         l_ulong         sc_err;
242         l_ulong         sc_trapno;
243         l_sigset_t      sc_mask;
244         l_ulong         sc_cr2;
245         struct l_fpstate *sc_fpstate;
246         l_ulong         sc_reserved1[8];
247 };
248
249 struct l_ucontext {
250         l_ulong         uc_flags;
251         l_uintptr_t     uc_link;
252         l_stack_t       uc_stack;
253         struct l_sigcontext     uc_mcontext;
254         l_sigset_t      uc_sigmask;
255 };
256
257 #define LINUX_SI_PREAMBLE_SIZE  (4 * sizeof(int))
258 #define LINUX_SI_MAX_SIZE       128
259 #define LINUX_SI_PAD_SIZE       ((LINUX_SI_MAX_SIZE - \
260                                     LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int))
261 typedef union l_sigval {
262         l_int           sival_int;
263         l_uintptr_t     sival_ptr;
264 } l_sigval_t;
265
266 typedef struct l_siginfo {
267         l_int           lsi_signo;
268         l_int           lsi_errno;
269         l_int           lsi_code;
270         union {
271                 l_int   _pad[LINUX_SI_PAD_SIZE];
272
273                 struct {
274                         l_pid_t         _pid;
275                         l_uid_t         _uid;
276                 } _kill;
277
278                 struct {
279                         l_timer_t       _tid;
280                         l_int           _overrun;
281                         char            _pad[sizeof(l_uid_t) - sizeof(int)];
282                         union l_sigval  _sigval;
283                         l_uint          _sys_private;
284                 } _timer;
285
286                 struct {
287                         l_pid_t         _pid;           /* sender's pid */
288                         l_uid_t         _uid;           /* sender's uid */
289                         union l_sigval  _sigval;
290                 } _rt;
291
292                 struct {
293                         l_pid_t         _pid;           /* which child */
294                         l_uid_t         _uid;           /* sender's uid */
295                         l_int           _status;        /* exit code */
296                         l_clock_t       _utime;
297                         l_clock_t       _stime;
298                 } _sigchld;
299
300                 struct {
301                         l_uintptr_t     _addr;  /* Faulting insn/memory ref. */
302                 } _sigfault;
303
304                 struct {
305                         l_long          _band;  /* POLL_IN,POLL_OUT,POLL_MSG */
306                         l_int           _fd;
307                 } _sigpoll;
308         } _sifields;
309 } l_siginfo_t;
310
311 #define lsi_pid         _sifields._kill._pid
312 #define lsi_uid         _sifields._kill._uid
313 #define lsi_tid         _sifields._timer._tid
314 #define lsi_overrun     _sifields._timer._overrun
315 #define lsi_sys_private _sifields._timer._sys_private
316 #define lsi_status      _sifields._sigchld._status
317 #define lsi_utime       _sifields._sigchld._utime
318 #define lsi_stime       _sifields._sigchld._stime
319 #define lsi_value       _sifields._rt._sigval
320 #define lsi_int         _sifields._rt._sigval.sival_int
321 #define lsi_ptr         _sifields._rt._sigval.sival_ptr
322 #define lsi_addr        _sifields._sigfault._addr
323 #define lsi_band        _sifields._sigpoll._band
324 #define lsi_fd          _sifields._sigpoll._fd
325
326 /*
327  * We make the stack look like Linux expects it when calling a signal
328  * handler, but use the BSD way of calling the handler and sigreturn().
329  * This means that we need to pass the pointer to the handler too.
330  * It is appended to the frame to not interfere with the rest of it.
331  */
332
333 struct l_rt_sigframe {
334         struct l_ucontext       sf_sc;
335         struct l_siginfo        sf_si;
336         l_handler_t             sf_handler;
337 };
338
339 /*
340  * mount flags
341  */
342 #define LINUX_MS_RDONLY         0x0001
343 #define LINUX_MS_NOSUID         0x0002
344 #define LINUX_MS_NODEV          0x0004
345 #define LINUX_MS_NOEXEC         0x0008
346 #define LINUX_MS_REMOUNT        0x0020
347
348 /*
349  * SystemV IPC defines
350  */
351 #define LINUX_IPC_RMID          0
352 #define LINUX_IPC_SET           1
353 #define LINUX_IPC_STAT          2
354 #define LINUX_IPC_INFO          3
355
356 #define LINUX_SHM_LOCK          11
357 #define LINUX_SHM_UNLOCK        12
358 #define LINUX_SHM_STAT          13
359 #define LINUX_SHM_INFO          14
360
361 #define LINUX_SHM_RDONLY        0x1000
362 #define LINUX_SHM_RND           0x2000
363 #define LINUX_SHM_REMAP         0x4000
364
365 /* semctl commands */
366 #define LINUX_GETPID            11
367 #define LINUX_GETVAL            12
368 #define LINUX_GETALL            13
369 #define LINUX_GETNCNT           14
370 #define LINUX_GETZCNT           15
371 #define LINUX_SETVAL            16
372 #define LINUX_SETALL            17
373 #define LINUX_SEM_STAT          18
374 #define LINUX_SEM_INFO          19
375
376 union l_semun {
377         l_int           val;
378         l_uintptr_t     buf;
379         l_uintptr_t     array;
380         l_uintptr_t     __buf;
381         l_uintptr_t     __pad;
382 };
383
384 struct l_ipc_perm {
385         l_key_t         key;
386         l_uid_t         uid;
387         l_gid_t         gid;
388         l_uid_t         cuid;
389         l_gid_t         cgid;
390         l_ushort        mode;
391         l_ushort        seq;
392 };
393
394 /*
395  * Socket defines
396  */
397
398 #define LINUX_SOL_SOCKET        1
399 #define LINUX_SOL_IP            0
400 #define LINUX_SOL_IPX           256
401 #define LINUX_SOL_AX25          257
402 #define LINUX_SOL_TCP           6
403 #define LINUX_SOL_UDP           17
404
405 #define LINUX_SO_DEBUG          1
406 #define LINUX_SO_REUSEADDR      2
407 #define LINUX_SO_TYPE           3
408 #define LINUX_SO_ERROR          4
409 #define LINUX_SO_DONTROUTE      5
410 #define LINUX_SO_BROADCAST      6
411 #define LINUX_SO_SNDBUF         7
412 #define LINUX_SO_RCVBUF         8
413 #define LINUX_SO_KEEPALIVE      9
414 #define LINUX_SO_OOBINLINE      10
415 #define LINUX_SO_NO_CHECK       11
416 #define LINUX_SO_PRIORITY       12
417 #define LINUX_SO_LINGER         13
418 #define LINUX_SO_PASSCRED       16
419 #define LINUX_SO_PEERCRED       17
420 #define LINUX_SO_RCVLOWAT       18
421 #define LINUX_SO_SNDLOWAT       19
422 #define LINUX_SO_RCVTIMEO       20
423 #define LINUX_SO_SNDTIMEO       21
424 #define LINUX_SO_TIMESTAMP      29
425 #define LINUX_SO_ACCEPTCONN     30
426
427 #define LINUX_IP_TOS            1
428 #define LINUX_IP_TTL            2
429 #define LINUX_IP_HDRINCL        3
430 #define LINUX_IP_OPTIONS        4
431
432 #define LINUX_IP_MULTICAST_IF           32
433 #define LINUX_IP_MULTICAST_TTL          33
434 #define LINUX_IP_MULTICAST_LOOP         34
435 #define LINUX_IP_ADD_MEMBERSHIP         35
436 #define LINUX_IP_DROP_MEMBERSHIP        36
437
438 struct l_sockaddr {
439         l_ushort        sa_family;
440         char            sa_data[14];
441 };
442
443 struct l_ifmap {
444         l_ulong         mem_start;
445         l_ulong         mem_end;
446         l_ushort        base_addr;
447         u_char          irq;
448         u_char          dma;
449         u_char          port;
450 } __packed;
451
452 #define LINUX_IFHWADDRLEN       6
453 #define LINUX_IFNAMSIZ          16
454
455 struct l_ifreq {
456         union {
457                 char    ifrn_name[LINUX_IFNAMSIZ];
458         } ifr_ifrn;
459
460         union {
461                 struct l_sockaddr       ifru_addr;
462                 struct l_sockaddr       ifru_dstaddr;
463                 struct l_sockaddr       ifru_broadaddr;
464                 struct l_sockaddr       ifru_netmask;
465                 struct l_sockaddr       ifru_hwaddr;
466                 l_short         ifru_flags[1];
467                 l_int           ifru_metric;
468                 l_int           ifru_mtu;
469                 struct l_ifmap  ifru_map;
470                 char            ifru_slave[LINUX_IFNAMSIZ];
471                 l_uintptr_t     ifru_data;
472         } ifr_ifru;
473 } __packed;
474
475 #define ifr_name        ifr_ifrn.ifrn_name      /* Interface name */
476 #define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* MAC address */
477
478 struct l_ifconf {
479         int     ifc_len;
480         union {
481                 l_uintptr_t     ifcu_buf;
482                 l_uintptr_t     ifcu_req;
483         } ifc_ifcu;
484 };
485
486 #define ifc_buf         ifc_ifcu.ifcu_buf
487 #define ifc_req         ifc_ifcu.ifcu_req
488
489 /*
490  * poll()
491  */
492 #define LINUX_POLLIN            0x0001
493 #define LINUX_POLLPRI           0x0002
494 #define LINUX_POLLOUT           0x0004
495 #define LINUX_POLLERR           0x0008
496 #define LINUX_POLLHUP           0x0010
497 #define LINUX_POLLNVAL          0x0020
498 #define LINUX_POLLRDNORM        0x0040
499 #define LINUX_POLLRDBAND        0x0080
500 #define LINUX_POLLWRNORM        0x0100
501 #define LINUX_POLLWRBAND        0x0200
502 #define LINUX_POLLMSG           0x0400
503
504 struct l_pollfd {
505         l_int           fd;
506         l_short         events;
507         l_short         revents;
508 };
509
510
511 #define LINUX_CLONE_VM                  0x00000100
512 #define LINUX_CLONE_FS                  0x00000200
513 #define LINUX_CLONE_FILES               0x00000400
514 #define LINUX_CLONE_SIGHAND             0x00000800
515 #define LINUX_CLONE_PID                 0x00001000      /* No longer exist in Linux */
516 #define LINUX_CLONE_VFORK               0x00004000
517 #define LINUX_CLONE_PARENT              0x00008000
518 #define LINUX_CLONE_THREAD              0x00010000
519 #define LINUX_CLONE_SETTLS              0x00080000
520 #define LINUX_CLONE_PARENT_SETTID       0x00100000
521 #define LINUX_CLONE_CHILD_CLEARTID      0x00200000
522 #define LINUX_CLONE_CHILD_SETTID        0x01000000
523
524 #define LINUX_ARCH_SET_GS               0x1001
525 #define LINUX_ARCH_SET_FS               0x1002
526 #define LINUX_ARCH_GET_FS               0x1003
527 #define LINUX_ARCH_GET_GS               0x1004
528
529 #define linux_copyout_rusage(r, u)      copyout(r, u, sizeof(*r))
530
531 /* robust futexes */
532 struct linux_robust_list {
533         l_uintptr_t                     next;
534 };
535  
536 struct linux_robust_list_head {
537         struct linux_robust_list        list;
538         l_long                          futex_offset;
539         l_uintptr_t                     pending_list;
540 };
541
542 #endif /* !_AMD64_LINUX_H_ */