2 * Copyright (c) 2004 Tim J. Robbins
3 * Copyright (c) 2001 Doug Rabson
4 * Copyright (c) 1994-1996 Søren Schmidt
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _AMD64_LINUX_H_
34 #define _AMD64_LINUX_H_
36 #include <amd64/linux32/linux32_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 linuxulator32
49 #define LINUX32_MAXUSER ((1ul << 32) - PAGE_SIZE)
50 #define LINUX32_SHAREDPAGE (LINUX32_MAXUSER - PAGE_SIZE)
51 #define LINUX32_USRSTACK LINUX32_SHAREDPAGE
53 /* XXX 16 = sizeof(linux32_ps_strings) */
54 #define LINUX32_PS_STRINGS (LINUX32_USRSTACK - 16)
55 #define LINUX32_MAXDSIZ (512 * 1024 * 1024) /* 512MB */
56 #define LINUX32_MAXSSIZ (64 * 1024 * 1024) /* 64MB */
57 #define LINUX32_MAXVMEM 0 /* Unlimited */
59 #define PTRIN(v) (void *)(uintptr_t)(v)
60 #define PTROUT(v) (l_uintptr_t)(uintptr_t)(v)
62 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
63 #define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
64 #define PTRIN_CP(src,dst,fld) \
65 do { (dst).fld = PTRIN((src).fld); } while (0)
68 * Provide a separate set of types for the Linux types.
71 typedef int32_t l_long;
72 typedef int64_t l_longlong;
73 typedef short l_short;
74 typedef unsigned int l_uint;
75 typedef uint32_t l_ulong;
76 typedef uint64_t l_ulonglong;
77 typedef unsigned short l_ushort;
79 typedef l_ulong l_uintptr_t;
80 typedef l_long l_clock_t;
81 typedef l_int l_daddr_t;
82 typedef l_ushort l_dev_t;
83 typedef l_uint l_gid_t;
84 typedef l_ushort l_gid16_t;
85 typedef l_ulong l_ino_t;
86 typedef l_int l_key_t;
87 typedef l_longlong l_loff_t;
88 typedef l_ushort l_mode_t;
89 typedef l_long l_off_t;
90 typedef l_int l_pid_t;
91 typedef l_uint l_size_t;
92 typedef l_long l_suseconds_t;
93 typedef l_long l_time_t;
94 typedef l_uint l_uid_t;
95 typedef l_ushort l_uid16_t;
96 typedef l_int l_timer_t;
97 typedef l_int l_mqd_t;
105 l_suseconds_t tv_usec;
108 #define l_fd_set fd_set
113 #define LINUX_AT_COUNT 20 /* Count of used aux entry types.
114 * Keep this synchronized with
115 * elf_linux_fixup() code.
117 struct l___sysctl_args
128 /* Resource limits */
129 #define LINUX_RLIMIT_CPU 0
130 #define LINUX_RLIMIT_FSIZE 1
131 #define LINUX_RLIMIT_DATA 2
132 #define LINUX_RLIMIT_STACK 3
133 #define LINUX_RLIMIT_CORE 4
134 #define LINUX_RLIMIT_RSS 5
135 #define LINUX_RLIMIT_NPROC 6
136 #define LINUX_RLIMIT_NOFILE 7
137 #define LINUX_RLIMIT_MEMLOCK 8
138 #define LINUX_RLIMIT_AS 9 /* Address space limit */
140 #define LINUX_RLIM_NLIMITS 10
167 #define LINUX_MAP_SHARED 0x0001
168 #define LINUX_MAP_PRIVATE 0x0002
169 #define LINUX_MAP_FIXED 0x0010
170 #define LINUX_MAP_ANON 0x0020
171 #define LINUX_MAP_GROWSDOWN 0x0100
183 * stat family of syscalls
203 struct l_timespec st_atim;
204 struct l_timespec st_mtim;
205 struct l_timespec st_ctim;
219 struct l_timespec st_atim;
220 struct l_timespec st_mtim;
221 struct l_timespec st_ctim;
242 struct l_timespec st_atim;
243 struct l_timespec st_mtim;
244 struct l_timespec st_ctim;
264 #define LINUX_SIGHUP 1
265 #define LINUX_SIGINT 2
266 #define LINUX_SIGQUIT 3
267 #define LINUX_SIGILL 4
268 #define LINUX_SIGTRAP 5
269 #define LINUX_SIGABRT 6
270 #define LINUX_SIGIOT LINUX_SIGABRT
271 #define LINUX_SIGBUS 7
272 #define LINUX_SIGFPE 8
273 #define LINUX_SIGKILL 9
274 #define LINUX_SIGUSR1 10
275 #define LINUX_SIGSEGV 11
276 #define LINUX_SIGUSR2 12
277 #define LINUX_SIGPIPE 13
278 #define LINUX_SIGALRM 14
279 #define LINUX_SIGTERM 15
280 #define LINUX_SIGSTKFLT 16
281 #define LINUX_SIGCHLD 17
282 #define LINUX_SIGCONT 18
283 #define LINUX_SIGSTOP 19
284 #define LINUX_SIGTSTP 20
285 #define LINUX_SIGTTIN 21
286 #define LINUX_SIGTTOU 22
287 #define LINUX_SIGURG 23
288 #define LINUX_SIGXCPU 24
289 #define LINUX_SIGXFSZ 25
290 #define LINUX_SIGVTALRM 26
291 #define LINUX_SIGPROF 27
292 #define LINUX_SIGWINCH 28
293 #define LINUX_SIGIO 29
294 #define LINUX_SIGPOLL LINUX_SIGIO
295 #define LINUX_SIGPWR 30
296 #define LINUX_SIGSYS 31
297 #define LINUX_SIGRTMIN 32
299 #define LINUX_SIGTBLSZ 31
300 #define LINUX_NSIG_WORDS 2
301 #define LINUX_NBPW 32
302 #define LINUX_NSIG (LINUX_NBPW * LINUX_NSIG_WORDS)
304 /* sigaction flags */
305 #define LINUX_SA_NOCLDSTOP 0x00000001
306 #define LINUX_SA_NOCLDWAIT 0x00000002
307 #define LINUX_SA_SIGINFO 0x00000004
308 #define LINUX_SA_RESTORER 0x04000000
309 #define LINUX_SA_ONSTACK 0x08000000
310 #define LINUX_SA_RESTART 0x10000000
311 #define LINUX_SA_INTERRUPT 0x20000000
312 #define LINUX_SA_NOMASK 0x40000000
313 #define LINUX_SA_ONESHOT 0x80000000
315 /* sigprocmask actions */
316 #define LINUX_SIG_BLOCK 0
317 #define LINUX_SIG_UNBLOCK 1
318 #define LINUX_SIG_SETMASK 2
320 /* sigset_t macros */
321 #define LINUX_SIGEMPTYSET(set) (set).__bits[0] = (set).__bits[1] = 0
322 #define LINUX_SIGISMEMBER(set, sig) SIGISMEMBER(set, sig)
323 #define LINUX_SIGADDSET(set, sig) SIGADDSET(set, sig)
326 #define LINUX_MINSIGSTKSZ 2048
327 #define LINUX_SS_ONSTACK 1
328 #define LINUX_SS_DISABLE 2
330 int linux_to_bsd_sigaltstack(int lsa);
331 int bsd_to_linux_sigaltstack(int bsa);
333 typedef l_uintptr_t l_handler_t;
334 typedef l_ulong l_osigset_t;
337 l_uint __bits[LINUX_NSIG_WORDS];
338 } __packed l_sigset_t;
341 l_handler_t lsa_handler;
342 l_osigset_t lsa_mask;
344 l_uintptr_t lsa_restorer;
345 } __packed l_osigaction_t;
348 l_handler_t lsa_handler;
350 l_uintptr_t lsa_restorer;
352 } __packed l_sigaction_t;
358 } __packed l_stack_t;
360 /* The Linux sigcontext, pretty much a standard 386 trapframe. */
361 struct l_sigcontext {
379 l_uint sc_esp_at_signal;
390 struct l_sigcontext uc_mcontext;
391 l_sigset_t uc_sigmask;
394 #define LINUX_SI_MAX_SIZE 128
395 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3)
397 typedef union l_sigval {
399 l_uintptr_t sival_ptr;
402 typedef struct l_siginfo {
407 l_int _pad[LINUX_SI_PAD_SIZE];
417 char _pad[sizeof(l_uid_t) - sizeof(l_int)];
423 l_pid_t _pid; /* sender's pid */
424 l_uid_t _uid; /* sender's uid */
429 l_pid_t _pid; /* which child */
430 l_uid_t _uid; /* sender's uid */
431 l_int _status; /* exit code */
437 l_uintptr_t _addr; /* Faulting insn/memory ref. */
438 } __packed _sigfault;
441 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */
445 } __packed l_siginfo_t;
447 #define lsi_pid _sifields._kill._pid
448 #define lsi_uid _sifields._kill._uid
449 #define lsi_tid _sifields._timer._tid
450 #define lsi_overrun _sifields._timer._overrun
451 #define lsi_sys_private _sifields._timer._sys_private
452 #define lsi_status _sifields._sigchld._status
453 #define lsi_utime _sifields._sigchld._utime
454 #define lsi_stime _sifields._sigchld._stime
455 #define lsi_value _sifields._rt._sigval
456 #define lsi_int _sifields._rt._sigval.sival_int
457 #define lsi_ptr _sifields._rt._sigval.sival_ptr
458 #define lsi_addr _sifields._sigfault._addr
459 #define lsi_band _sifields._sigpoll._band
460 #define lsi_fd _sifields._sigpoll._fd
463 u_int16_t significand[4];
468 u_int16_t significand[4];
470 u_int16_t padding[3];
474 u_int32_t element[4];
478 /* Regular FPU environment */
486 struct l_fpreg _st[8];
488 u_int16_t magic; /* 0xffff = regular FPU data */
490 /* FXSR FPU environment */
491 u_int32_t _fxsr_env[6]; /* env is ignored. */
494 struct l_fpxreg _fxsr_st[8]; /* reg data is ignored. */
495 struct l_xmmreg _xmm[8];
496 u_int32_t padding[56];
500 * We make the stack look like Linux expects it when calling a signal
501 * handler, but use the BSD way of calling the handler and sigreturn().
502 * This means that we need to pass the pointer to the handler too.
503 * It is appended to the frame to not interfere with the rest of it.
507 struct l_sigcontext sf_sc;
508 struct l_fpstate sf_fpstate;
509 l_uint sf_extramask[LINUX_NSIG_WORDS-1];
510 l_handler_t sf_handler;
513 struct l_rt_sigframe {
515 l_uintptr_t sf_siginfo;
516 l_uintptr_t sf_ucontext;
518 struct l_ucontext sf_sc;
519 l_handler_t sf_handler;
523 * arch specific open/fcntl flags
525 #define LINUX_F_GETLK64 12
526 #define LINUX_F_SETLK64 13
527 #define LINUX_F_SETLKW64 14
550 #define LINUX_SOL_SOCKET 1
551 #define LINUX_SOL_IP 0
552 #define LINUX_SOL_IPX 256
553 #define LINUX_SOL_AX25 257
554 #define LINUX_SOL_TCP 6
555 #define LINUX_SOL_UDP 17
557 #define LINUX_SO_DEBUG 1
558 #define LINUX_SO_REUSEADDR 2
559 #define LINUX_SO_TYPE 3
560 #define LINUX_SO_ERROR 4
561 #define LINUX_SO_DONTROUTE 5
562 #define LINUX_SO_BROADCAST 6
563 #define LINUX_SO_SNDBUF 7
564 #define LINUX_SO_RCVBUF 8
565 #define LINUX_SO_KEEPALIVE 9
566 #define LINUX_SO_OOBINLINE 10
567 #define LINUX_SO_NO_CHECK 11
568 #define LINUX_SO_PRIORITY 12
569 #define LINUX_SO_LINGER 13
570 #define LINUX_SO_PEERCRED 17
571 #define LINUX_SO_RCVLOWAT 18
572 #define LINUX_SO_SNDLOWAT 19
573 #define LINUX_SO_RCVTIMEO 20
574 #define LINUX_SO_SNDTIMEO 21
575 #define LINUX_SO_TIMESTAMP 29
576 #define LINUX_SO_ACCEPTCONN 30
584 l_uintptr_t msg_name;
588 l_uintptr_t msg_control;
589 l_size_t msg_controllen;
608 #define LINUX_IFHWADDRLEN 6
609 #define LINUX_IFNAMSIZ 16
613 char ifrn_name[LINUX_IFNAMSIZ];
617 struct l_sockaddr ifru_addr;
618 struct l_sockaddr ifru_dstaddr;
619 struct l_sockaddr ifru_broadaddr;
620 struct l_sockaddr ifru_netmask;
621 struct l_sockaddr ifru_hwaddr;
622 l_short ifru_flags[1];
625 struct l_ifmap ifru_map;
626 char ifru_slave[LINUX_IFNAMSIZ];
627 l_uintptr_t ifru_data;
631 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */
632 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
637 l_uintptr_t ifcu_buf;
638 l_uintptr_t ifcu_req;
642 #define ifc_buf ifc_ifcu.ifcu_buf
643 #define ifc_req ifc_ifcu.ifcu_req
648 #define LINUX_POLLIN 0x0001
649 #define LINUX_POLLPRI 0x0002
650 #define LINUX_POLLOUT 0x0004
651 #define LINUX_POLLERR 0x0008
652 #define LINUX_POLLHUP 0x0010
653 #define LINUX_POLLNVAL 0x0020
654 #define LINUX_POLLRDNORM 0x0040
655 #define LINUX_POLLRDBAND 0x0080
656 #define LINUX_POLLWRNORM 0x0100
657 #define LINUX_POLLWRBAND 0x0200
658 #define LINUX_POLLMSG 0x0400
672 l_uint read_exec_only:1;
673 l_uint limit_in_pages:1;
674 l_uint seg_not_present:1;
678 #define LINUX_LOWERWORD 0x0000ffff
681 * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h.
682 * These convert Linux user space descriptor to machine one.
684 #define LINUX_LDT_entry_a(info) \
685 ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \
686 ((info)->limit & LINUX_LOWERWORD))
688 #define LINUX_ENTRY_B_READ_EXEC_ONLY 9
689 #define LINUX_ENTRY_B_CONTENTS 10
690 #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15
691 #define LINUX_ENTRY_B_BASE_ADDR 16
692 #define LINUX_ENTRY_B_USEABLE 20
693 #define LINUX_ENTRY_B_SEG32BIT 22
694 #define LINUX_ENTRY_B_LIMIT 23
696 #define LINUX_LDT_entry_b(info) \
697 (((info)->base_addr & 0xff000000) | \
698 ((info)->limit & 0xf0000) | \
699 ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \
700 (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \
701 (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \
702 (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \
703 ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \
704 ((info)->useable << LINUX_ENTRY_B_USEABLE) | \
705 ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000)
707 #define LINUX_LDT_empty(info) \
708 ((info)->base_addr == 0 && \
709 (info)->limit == 0 && \
710 (info)->contents == 0 && \
711 (info)->seg_not_present == 1 && \
712 (info)->read_exec_only == 1 && \
713 (info)->seg_32bit == 0 && \
714 (info)->limit_in_pages == 0 && \
715 (info)->useable == 0)
718 * Macros for converting segments.
719 * They do the same as those in arch/i386/kernel/process.c in Linux.
721 #define LINUX_GET_BASE(desc) \
722 ((((desc)->a >> 16) & LINUX_LOWERWORD) | \
723 (((desc)->b << 16) & 0x00ff0000) | \
724 ((desc)->b & 0xff000000))
726 #define LINUX_GET_LIMIT(desc) \
727 (((desc)->a & LINUX_LOWERWORD) | \
728 ((desc)->b & 0xf0000))
730 #define LINUX_GET_32BIT(desc) \
731 (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1)
732 #define LINUX_GET_CONTENTS(desc) \
733 (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3)
734 #define LINUX_GET_WRITABLE(desc) \
735 (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1)
736 #define LINUX_GET_LIMIT_PAGES(desc) \
737 (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1)
738 #define LINUX_GET_PRESENT(desc) \
739 (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1)
740 #define LINUX_GET_USEABLE(desc) \
741 (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1)
750 int linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt,
751 struct iovec **iovp, int error);
752 int linux_copyout_rusage(struct rusage *ru, void *uaddr);
755 struct linux_robust_list {
759 struct linux_robust_list_head {
760 struct linux_robust_list list;
762 l_uintptr_t pending_list;
765 #endif /* !_AMD64_LINUX_H_ */