2 * Copyright (c) 2013 Dmitry Chagin
3 * Copyright (c) 1994-1996 Søren Schmidt
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
32 #ifndef _AMD64_LINUX_H_
33 #define _AMD64_LINUX_H_
35 #include <amd64/linux/linux_syscall.h>
40 extern u_char linux_debug_map[];
41 #define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name)
42 #define ARGS(nm, fmt) "linux(%ld/%ld): "#nm"("fmt")\n", \
43 (long)td->td_proc->p_pid, (long)td->td_tid
44 #define LMSG(fmt) "linux(%ld/%ld): "fmt"\n", \
45 (long)td->td_proc->p_pid, (long)td->td_tid
46 #define LINUX_DTRACE linuxulator
48 #define PTRIN(v) (void *)(v)
49 #define PTROUT(v) (uintptr_t)(v)
51 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
52 #define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
53 #define PTRIN_CP(src,dst,fld) \
54 do { (dst).fld = PTRIN((src).fld); } while (0)
57 * Provide a separate set of types for the Linux types.
59 typedef int32_t l_int;
60 typedef int64_t l_long;
61 typedef int16_t l_short;
62 typedef uint32_t l_uint;
63 typedef uint64_t l_ulong;
64 typedef uint16_t l_ushort;
66 typedef l_ulong l_uintptr_t;
67 typedef l_long l_clock_t;
68 typedef l_int l_daddr_t;
69 typedef l_ulong l_dev_t;
70 typedef l_uint l_gid_t;
71 typedef l_uint l_uid_t;
72 typedef l_ulong l_ino_t;
73 typedef l_int l_key_t;
74 typedef l_long l_loff_t;
75 typedef l_uint l_mode_t;
76 typedef l_long l_off_t;
77 typedef l_int l_pid_t;
78 typedef l_ulong l_size_t;
79 typedef l_long l_ssize_t;
80 typedef l_long l_suseconds_t;
81 typedef l_long l_time_t;
82 typedef l_int l_timer_t;
83 typedef l_int l_mqd_t;
84 typedef l_size_t l_socklen_t;
92 l_suseconds_t tv_usec;
95 #define l_fd_set fd_set
100 #define LINUX_NAME_MAX 255
101 #define LINUX_CTL_MAXNAME 10
103 #define LINUX_AT_COUNT 19 /* Count of used aux entry types. */
105 struct l___sysctl_args
116 /* Scheduling policies */
117 #define LINUX_SCHED_OTHER 0
118 #define LINUX_SCHED_FIFO 1
119 #define LINUX_SCHED_RR 2
121 /* Resource limits */
122 #define LINUX_RLIMIT_CPU 0
123 #define LINUX_RLIMIT_FSIZE 1
124 #define LINUX_RLIMIT_DATA 2
125 #define LINUX_RLIMIT_STACK 3
126 #define LINUX_RLIMIT_CORE 4
127 #define LINUX_RLIMIT_RSS 5
128 #define LINUX_RLIMIT_NPROC 6
129 #define LINUX_RLIMIT_NOFILE 7
130 #define LINUX_RLIMIT_MEMLOCK 8
131 #define LINUX_RLIMIT_AS 9 /* Address space limit */
133 #define LINUX_RLIM_NLIMITS 10
141 #define LINUX_MAP_SHARED 0x0001
142 #define LINUX_MAP_PRIVATE 0x0002
143 #define LINUX_MAP_FIXED 0x0010
144 #define LINUX_MAP_ANON 0x0020
145 #define LINUX_MAP_GROWSDOWN 0x0100
148 * stat family of syscalls
167 struct l_timespec st_atim;
168 struct l_timespec st_mtim;
169 struct l_timespec st_ctim;
178 #define LINUX_SIGHUP 1
179 #define LINUX_SIGINT 2
180 #define LINUX_SIGQUIT 3
181 #define LINUX_SIGILL 4
182 #define LINUX_SIGTRAP 5
183 #define LINUX_SIGABRT 6
184 #define LINUX_SIGIOT LINUX_SIGABRT
185 #define LINUX_SIGBUS 7
186 #define LINUX_SIGFPE 8
187 #define LINUX_SIGKILL 9
188 #define LINUX_SIGUSR1 10
189 #define LINUX_SIGSEGV 11
190 #define LINUX_SIGUSR2 12
191 #define LINUX_SIGPIPE 13
192 #define LINUX_SIGALRM 14
193 #define LINUX_SIGTERM 15
194 #define LINUX_SIGSTKFLT 16
195 #define LINUX_SIGCHLD 17
196 #define LINUX_SIGCONT 18
197 #define LINUX_SIGSTOP 19
198 #define LINUX_SIGTSTP 20
199 #define LINUX_SIGTTIN 21
200 #define LINUX_SIGTTOU 22
201 #define LINUX_SIGURG 23
202 #define LINUX_SIGXCPU 24
203 #define LINUX_SIGXFSZ 25
204 #define LINUX_SIGVTALRM 26
205 #define LINUX_SIGPROF 27
206 #define LINUX_SIGWINCH 28
207 #define LINUX_SIGIO 29
208 #define LINUX_SIGPOLL LINUX_SIGIO
209 #define LINUX_SIGPWR 30
210 #define LINUX_SIGSYS 31
211 #define LINUX_SIGRTMIN 32
213 #define LINUX_SIGTBLSZ 31
214 #define LINUX_NSIG 64
215 #define LINUX_NBPW 64
216 #define LINUX_NSIG_WORDS (LINUX_NSIG / LINUX_NBPW)
218 /* sigaction flags */
219 #define LINUX_SA_NOCLDSTOP 0x00000001
220 #define LINUX_SA_NOCLDWAIT 0x00000002
221 #define LINUX_SA_SIGINFO 0x00000004
222 #define LINUX_SA_RESTORER 0x04000000
223 #define LINUX_SA_ONSTACK 0x08000000
224 #define LINUX_SA_RESTART 0x10000000
225 #define LINUX_SA_INTERRUPT 0x20000000
226 #define LINUX_SA_NOMASK 0x40000000
227 #define LINUX_SA_ONESHOT 0x80000000
229 /* sigprocmask actions */
230 #define LINUX_SIG_BLOCK 0
231 #define LINUX_SIG_UNBLOCK 1
232 #define LINUX_SIG_SETMASK 2
234 /* primitives to manipulate sigset_t */
236 #define LINUX_SIGEMPTYSET(set) \
238 (set).__bits[0] = 0; \
241 #define LINUX_SIGISMEMBER(set, sig) \
242 (1UL & ((set).__bits[0] >> _SIG_IDX(sig)))
244 #define LINUX_SIGADDSET(set, sig) \
245 (set).__bits[0] |= 1UL << _SIG_IDX(sig)
248 #define LINUX_MINSIGSTKSZ 2048
249 #define LINUX_SS_ONSTACK 1
250 #define LINUX_SS_DISABLE 2
252 int linux_to_bsd_sigaltstack(int lsa);
253 int bsd_to_linux_sigaltstack(int bsa);
255 typedef void (*l_handler_t)(l_int);
258 l_ulong __bits[LINUX_NSIG_WORDS];
262 l_handler_t lsa_handler;
264 l_uintptr_t lsa_restorer;
282 u_int32_t mxcsr_mask;
283 u_int32_t st_space[32];
284 u_int32_t xmm_space[64];
285 u_int32_t reserved2[24];
288 struct l_sigcontext {
315 struct l_fpstate *sc_fpstate;
316 l_ulong sc_reserved1[8];
323 struct l_sigcontext uc_mcontext;
324 l_sigset_t uc_sigmask;
327 #define LINUX_SI_PREAMBLE_SIZE (4 * sizeof(int))
328 #define LINUX_SI_MAX_SIZE 128
329 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE - \
330 LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int))
331 typedef union l_sigval {
333 l_uintptr_t sival_ptr;
336 typedef struct l_siginfo {
341 l_int _pad[LINUX_SI_PAD_SIZE];
351 char _pad[sizeof(l_uid_t) - sizeof(int)];
352 union l_sigval _sigval;
357 l_pid_t _pid; /* sender's pid */
358 l_uid_t _uid; /* sender's uid */
359 union l_sigval _sigval;
363 l_pid_t _pid; /* which child */
364 l_uid_t _uid; /* sender's uid */
365 l_int _status; /* exit code */
371 l_uintptr_t _addr; /* Faulting insn/memory ref. */
375 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */
381 #define lsi_pid _sifields._kill._pid
382 #define lsi_uid _sifields._kill._uid
383 #define lsi_tid _sifields._timer._tid
384 #define lsi_overrun _sifields._timer._overrun
385 #define lsi_sys_private _sifields._timer._sys_private
386 #define lsi_status _sifields._sigchld._status
387 #define lsi_utime _sifields._sigchld._utime
388 #define lsi_stime _sifields._sigchld._stime
389 #define lsi_value _sifields._rt._sigval
390 #define lsi_int _sifields._rt._sigval.sival_int
391 #define lsi_ptr _sifields._rt._sigval.sival_ptr
392 #define lsi_addr _sifields._sigfault._addr
393 #define lsi_band _sifields._sigpoll._band
394 #define lsi_fd _sifields._sigpoll._fd
397 * We make the stack look like Linux expects it when calling a signal
398 * handler, but use the BSD way of calling the handler and sigreturn().
399 * This means that we need to pass the pointer to the handler too.
400 * It is appended to the frame to not interfere with the rest of it.
403 struct l_rt_sigframe {
404 struct l_ucontext sf_sc;
405 struct l_siginfo sf_si;
406 l_handler_t sf_handler;
412 #define LINUX_MS_RDONLY 0x0001
413 #define LINUX_MS_NOSUID 0x0002
414 #define LINUX_MS_NODEV 0x0004
415 #define LINUX_MS_NOEXEC 0x0008
416 #define LINUX_MS_REMOUNT 0x0020
419 * SystemV IPC defines
421 #define LINUX_IPC_RMID 0
422 #define LINUX_IPC_SET 1
423 #define LINUX_IPC_STAT 2
424 #define LINUX_IPC_INFO 3
426 #define LINUX_SHM_LOCK 11
427 #define LINUX_SHM_UNLOCK 12
428 #define LINUX_SHM_STAT 13
429 #define LINUX_SHM_INFO 14
431 #define LINUX_SHM_RDONLY 0x1000
432 #define LINUX_SHM_RND 0x2000
433 #define LINUX_SHM_REMAP 0x4000
435 /* semctl commands */
436 #define LINUX_GETPID 11
437 #define LINUX_GETVAL 12
438 #define LINUX_GETALL 13
439 #define LINUX_GETNCNT 14
440 #define LINUX_GETZCNT 15
441 #define LINUX_SETVAL 16
442 #define LINUX_SETALL 17
443 #define LINUX_SEM_STAT 18
444 #define LINUX_SEM_INFO 19
468 #define LINUX_SOL_SOCKET 1
469 #define LINUX_SOL_IP 0
470 #define LINUX_SOL_IPX 256
471 #define LINUX_SOL_AX25 257
472 #define LINUX_SOL_TCP 6
473 #define LINUX_SOL_UDP 17
475 #define LINUX_SO_DEBUG 1
476 #define LINUX_SO_REUSEADDR 2
477 #define LINUX_SO_TYPE 3
478 #define LINUX_SO_ERROR 4
479 #define LINUX_SO_DONTROUTE 5
480 #define LINUX_SO_BROADCAST 6
481 #define LINUX_SO_SNDBUF 7
482 #define LINUX_SO_RCVBUF 8
483 #define LINUX_SO_KEEPALIVE 9
484 #define LINUX_SO_OOBINLINE 10
485 #define LINUX_SO_NO_CHECK 11
486 #define LINUX_SO_PRIORITY 12
487 #define LINUX_SO_LINGER 13
488 #define LINUX_SO_PASSCRED 16
489 #define LINUX_SO_PEERCRED 17
490 #define LINUX_SO_RCVLOWAT 18
491 #define LINUX_SO_SNDLOWAT 19
492 #define LINUX_SO_RCVTIMEO 20
493 #define LINUX_SO_SNDTIMEO 21
494 #define LINUX_SO_TIMESTAMP 29
495 #define LINUX_SO_ACCEPTCONN 30
497 #define LINUX_IP_TOS 1
498 #define LINUX_IP_TTL 2
499 #define LINUX_IP_HDRINCL 3
500 #define LINUX_IP_OPTIONS 4
502 #define LINUX_IP_MULTICAST_IF 32
503 #define LINUX_IP_MULTICAST_TTL 33
504 #define LINUX_IP_MULTICAST_LOOP 34
505 #define LINUX_IP_ADD_MEMBERSHIP 35
506 #define LINUX_IP_DROP_MEMBERSHIP 36
514 l_uintptr_t msg_name;
518 l_uintptr_t msg_control;
519 l_size_t msg_controllen;
538 #define LINUX_IFHWADDRLEN 6
539 #define LINUX_IFNAMSIZ 16
543 char ifrn_name[LINUX_IFNAMSIZ];
547 struct l_sockaddr ifru_addr;
548 struct l_sockaddr ifru_dstaddr;
549 struct l_sockaddr ifru_broadaddr;
550 struct l_sockaddr ifru_netmask;
551 struct l_sockaddr ifru_hwaddr;
552 l_short ifru_flags[1];
555 struct l_ifmap ifru_map;
556 char ifru_slave[LINUX_IFNAMSIZ];
557 l_uintptr_t ifru_data;
561 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */
562 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
567 l_uintptr_t ifcu_buf;
568 l_uintptr_t ifcu_req;
572 #define ifc_buf ifc_ifcu.ifcu_buf
573 #define ifc_req ifc_ifcu.ifcu_req
578 #define LINUX_POLLIN 0x0001
579 #define LINUX_POLLPRI 0x0002
580 #define LINUX_POLLOUT 0x0004
581 #define LINUX_POLLERR 0x0008
582 #define LINUX_POLLHUP 0x0010
583 #define LINUX_POLLNVAL 0x0020
584 #define LINUX_POLLRDNORM 0x0040
585 #define LINUX_POLLRDBAND 0x0080
586 #define LINUX_POLLWRNORM 0x0100
587 #define LINUX_POLLWRBAND 0x0200
588 #define LINUX_POLLMSG 0x0400
597 #define LINUX_CLONE_VM 0x00000100
598 #define LINUX_CLONE_FS 0x00000200
599 #define LINUX_CLONE_FILES 0x00000400
600 #define LINUX_CLONE_SIGHAND 0x00000800
601 #define LINUX_CLONE_PID 0x00001000 /* No longer exist in Linux */
602 #define LINUX_CLONE_VFORK 0x00004000
603 #define LINUX_CLONE_PARENT 0x00008000
604 #define LINUX_CLONE_THREAD 0x00010000
605 #define LINUX_CLONE_SETTLS 0x00080000
606 #define LINUX_CLONE_PARENT_SETTID 0x00100000
607 #define LINUX_CLONE_CHILD_CLEARTID 0x00200000
608 #define LINUX_CLONE_CHILD_SETTID 0x01000000
610 #define LINUX_ARCH_SET_GS 0x1001
611 #define LINUX_ARCH_SET_FS 0x1002
612 #define LINUX_ARCH_GET_GS 0x1003
613 #define LINUX_ARCH_GET_FS 0x1004
615 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r))
618 struct linux_robust_list {
622 struct linux_robust_list_head {
623 struct linux_robust_list list;
625 l_uintptr_t pending_list;
628 #endif /* !_AMD64_LINUX_H_ */