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 <compat/linux/linux.h>
36 #include <amd64/linux/linux_syscall.h>
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
49 #define PTRIN(v) (void *)(v)
50 #define PTROUT(v) (uintptr_t)(v)
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)
58 * Provide a separate set of types for the Linux types.
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;
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;
96 l_suseconds_t tv_usec;
99 #define l_fd_set fd_set
104 #define LINUX_NAME_MAX 255
105 #define LINUX_CTL_MAXNAME 10
107 #define LINUX_AT_COUNT 19 /* Count of used aux entry types. */
109 struct l___sysctl_args
120 /* Scheduling policies */
121 #define LINUX_SCHED_OTHER 0
122 #define LINUX_SCHED_FIFO 1
123 #define LINUX_SCHED_RR 2
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 */
137 #define LINUX_RLIM_NLIMITS 10
145 * stat family of syscalls
164 struct l_timespec st_atim;
165 struct l_timespec st_mtim;
166 struct l_timespec st_ctim;
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
183 /* sigprocmask actions */
184 #define LINUX_SIG_BLOCK 0
185 #define LINUX_SIG_UNBLOCK 1
186 #define LINUX_SIG_SETMASK 2
189 #define LINUX_MINSIGSTKSZ 2048
191 typedef void (*l_handler_t)(l_int);
194 l_handler_t lsa_handler;
196 l_uintptr_t lsa_restorer;
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];
220 struct l_sigcontext {
247 struct l_fpstate *sc_fpstate;
248 l_ulong sc_reserved1[8];
255 struct l_sigcontext uc_mcontext;
256 l_sigset_t uc_sigmask;
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 {
265 l_uintptr_t sival_ptr;
268 typedef struct l_siginfo {
273 l_int _pad[LINUX_SI_PAD_SIZE];
283 char _pad[sizeof(l_uid_t) - sizeof(int)];
284 union l_sigval _sigval;
289 l_pid_t _pid; /* sender's pid */
290 l_uid_t _uid; /* sender's uid */
291 union l_sigval _sigval;
295 l_pid_t _pid; /* which child */
296 l_uid_t _uid; /* sender's uid */
297 l_int _status; /* exit code */
303 l_uintptr_t _addr; /* Faulting insn/memory ref. */
307 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */
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
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.
335 struct l_rt_sigframe {
336 struct l_ucontext sf_sc;
337 struct l_siginfo sf_si;
338 l_handler_t sf_handler;
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
351 * SystemV IPC defines
353 #define LINUX_IPC_RMID 0
354 #define LINUX_IPC_SET 1
355 #define LINUX_IPC_STAT 2
356 #define LINUX_IPC_INFO 3
358 #define LINUX_SHM_LOCK 11
359 #define LINUX_SHM_UNLOCK 12
360 #define LINUX_SHM_STAT 13
361 #define LINUX_SHM_INFO 14
363 #define LINUX_SHM_RDONLY 0x1000
364 #define LINUX_SHM_RND 0x2000
365 #define LINUX_SHM_REMAP 0x4000
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
400 #define LINUX_IFHWADDRLEN 6
401 #define LINUX_IFNAMSIZ 16
405 char ifrn_name[LINUX_IFNAMSIZ];
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];
417 struct l_ifmap ifru_map;
418 char ifru_slave[LINUX_IFNAMSIZ];
419 l_uintptr_t ifru_data;
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 */
430 l_uintptr_t ifcu_buf;
431 l_uintptr_t ifcu_req;
435 #define ifc_buf ifc_ifcu.ifcu_buf
436 #define ifc_req ifc_ifcu.ifcu_req
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
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
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
478 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r))
481 struct linux_robust_list {
485 struct linux_robust_list_head {
486 struct linux_robust_list list;
488 l_uintptr_t pending_list;
491 #endif /* !_AMD64_LINUX_H_ */