linux.h revision 161461
1/*-
2 * Copyright (c) 2004 Tim J. Robbins
3 * Copyright (c) 2001 Doug Rabson
4 * Copyright (c) 1994-1996 S�ren Schmidt
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
18 *
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.
29 *
30 * $FreeBSD: head/sys/amd64/linux32/linux.h 161461 2006-08-19 15:13:01Z netchild $
31 */
32
33#ifndef _AMD64_LINUX_LINUX_H_
34#define	_AMD64_LINUX_LINUX_H_
35
36#include <sys/signal.h> /* for sigval union */
37
38#include <amd64/linux32/linux32_syscall.h>
39
40/*
41 * debugging support
42 */
43extern u_char linux_debug_map[];
44#define ldebug(name)	isclr(linux_debug_map, LINUX_SYS_linux_ ## name)
45#define ARGS(nm, fmt)	"linux(%ld): "#nm"("fmt")\n", (long)td->td_proc->p_pid
46#define LMSG(fmt)	"linux(%ld): "fmt"\n", (long)td->td_proc->p_pid
47
48#ifdef MALLOC_DECLARE
49MALLOC_DECLARE(M_LINUX);
50#endif
51
52#define LINUX32_USRSTACK	((1ul << 32) - PAGE_SIZE)
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 */
58
59#define	PTRIN(v)	(void *)(uintptr_t)(v)
60#define	PTROUT(v)	(l_uintptr_t)(uintptr_t)(v)
61
62/*
63 * Provide a separate set of types for the Linux types.
64 */
65typedef int		l_int;
66typedef int32_t		l_long;
67typedef int64_t		l_longlong;
68typedef short		l_short;
69typedef unsigned int	l_uint;
70typedef uint32_t	l_ulong;
71typedef uint64_t	l_ulonglong;
72typedef unsigned short	l_ushort;
73
74typedef l_ulong		l_uintptr_t;
75typedef l_long		l_clock_t;
76typedef l_int		l_daddr_t;
77typedef l_ushort	l_dev_t;
78typedef l_uint		l_gid_t;
79typedef l_ushort	l_gid16_t;
80typedef l_ulong		l_ino_t;
81typedef l_int		l_key_t;
82typedef l_longlong	l_loff_t;
83typedef l_ushort	l_mode_t;
84typedef l_long		l_off_t;
85typedef l_int		l_pid_t;
86typedef l_uint		l_size_t;
87typedef l_long		l_suseconds_t;
88typedef l_long		l_time_t;
89typedef l_uint		l_uid_t;
90typedef l_ushort	l_uid16_t;
91
92typedef struct {
93	l_int		val[2];
94} __packed l_fsid_t;
95
96typedef struct {
97	l_time_t	tv_sec;
98	l_suseconds_t	tv_usec;
99} __packed l_timeval;
100
101#define	l_fd_set	fd_set
102
103/*
104 * Miscellaneous
105 */
106#define	LINUX_NAME_MAX		255
107#define	LINUX_MAX_UTSNAME	65
108
109#define	LINUX_CTL_MAXNAME	10
110
111struct l___sysctl_args
112{
113	l_uintptr_t	name;
114	l_int		nlen;
115	l_uintptr_t	oldval;
116	l_uintptr_t	oldlenp;
117	l_uintptr_t	newval;
118	l_size_t	newlen;
119	l_ulong		__spare[4];
120} __packed;
121
122/* Scheduling policies */
123#define	LINUX_SCHED_OTHER	0
124#define	LINUX_SCHED_FIFO	1
125#define	LINUX_SCHED_RR		2
126
127/* Resource limits */
128#define	LINUX_RLIMIT_CPU	0
129#define	LINUX_RLIMIT_FSIZE	1
130#define	LINUX_RLIMIT_DATA	2
131#define	LINUX_RLIMIT_STACK	3
132#define	LINUX_RLIMIT_CORE	4
133#define	LINUX_RLIMIT_RSS	5
134#define	LINUX_RLIMIT_NPROC	6
135#define	LINUX_RLIMIT_NOFILE	7
136#define	LINUX_RLIMIT_MEMLOCK	8
137#define	LINUX_RLIMIT_AS		9       /* address space limit */
138
139#define	LINUX_RLIM_NLIMITS	10
140
141struct l_rlimit {
142	l_ulong rlim_cur;
143	l_ulong rlim_max;
144} __packed;
145
146struct l_rusage {
147	l_timeval ru_utime;
148	l_timeval ru_stime;
149	l_long	ru_maxrss;
150	l_long	ru_ixrss;
151	l_long	ru_idrss;
152	l_long	ru_isrss;
153	l_long	ru_minflt;
154	l_long	ru_majflt;
155	l_long	ru_nswap;
156	l_long	ru_inblock;
157	l_long	ru_oublock;
158	l_long	ru_msgsnd;
159	l_long	ru_msgrcv;
160	l_long	ru_nsignals;
161	l_long	ru_nvcsw;
162	l_long	ru_nivcsw;
163} __packed;
164
165/* mmap options */
166#define	LINUX_MAP_SHARED	0x0001
167#define	LINUX_MAP_PRIVATE	0x0002
168#define	LINUX_MAP_FIXED		0x0010
169#define	LINUX_MAP_ANON		0x0020
170#define	LINUX_MAP_GROWSDOWN	0x0100
171
172/*
173 * stat family of syscalls
174 */
175struct l_timespec {
176	l_ulong		tv_sec;
177	l_ulong		tv_nsec;
178} __packed;
179
180struct l_newstat {
181	l_ushort	st_dev;
182	l_ushort	__pad1;
183	l_ulong		st_ino;
184	l_ushort	st_mode;
185	l_ushort	st_nlink;
186	l_ushort	st_uid;
187	l_ushort	st_gid;
188	l_ushort	st_rdev;
189	l_ushort	__pad2;
190	l_ulong		st_size;
191	l_ulong		st_blksize;
192	l_ulong		st_blocks;
193	struct l_timespec	st_atimespec;
194	struct l_timespec	st_mtimespec;
195	struct l_timespec	st_ctimespec;
196	l_ulong		__unused4;
197	l_ulong		__unused5;
198} __packed;
199
200struct l_stat {
201       l_ushort        st_dev;
202       l_ulong         st_ino;
203       l_ushort        st_mode;
204       l_ushort        st_nlink;
205       l_ushort        st_uid;
206       l_ushort        st_gid;
207       l_ushort        st_rdev;
208       l_long          st_size;
209       struct l_timespec       st_atimespec;
210       struct l_timespec       st_mtimespec;
211       struct l_timespec       st_ctimespec;
212       l_long          st_blksize;
213       l_long          st_blocks;
214       l_ulong         st_flags;
215       l_ulong         st_gen;
216};
217
218struct l_stat64 {
219	l_ushort	st_dev;
220	u_char		__pad0[10];
221	l_ulong		__st_ino;
222	l_uint		st_mode;
223	l_uint		st_nlink;
224	l_ulong		st_uid;
225	l_ulong		st_gid;
226	l_ushort	st_rdev;
227	u_char		__pad3[10];
228	l_longlong	st_size;
229	l_ulong		st_blksize;
230	l_ulong		st_blocks;
231	l_ulong		__pad4;
232	struct l_timespec	st_atimespec;
233	struct l_timespec	st_mtimespec;
234	struct l_timespec	st_ctimespec;
235	l_ulonglong	st_ino;
236} __packed;
237
238struct l_new_utsname {
239	char	sysname[LINUX_MAX_UTSNAME];
240	char	nodename[LINUX_MAX_UTSNAME];
241	char	release[LINUX_MAX_UTSNAME];
242	char	version[LINUX_MAX_UTSNAME];
243	char	machine[LINUX_MAX_UTSNAME];
244	char	domainname[LINUX_MAX_UTSNAME];
245} __packed;
246
247/*
248 * Signalling
249 */
250#define	LINUX_SIGHUP		1
251#define	LINUX_SIGINT		2
252#define	LINUX_SIGQUIT		3
253#define	LINUX_SIGILL		4
254#define	LINUX_SIGTRAP		5
255#define	LINUX_SIGABRT		6
256#define	LINUX_SIGIOT		LINUX_SIGABRT
257#define	LINUX_SIGBUS		7
258#define	LINUX_SIGFPE		8
259#define	LINUX_SIGKILL		9
260#define	LINUX_SIGUSR1		10
261#define	LINUX_SIGSEGV		11
262#define	LINUX_SIGUSR2		12
263#define	LINUX_SIGPIPE		13
264#define	LINUX_SIGALRM		14
265#define	LINUX_SIGTERM		15
266#define	LINUX_SIGSTKFLT		16
267#define	LINUX_SIGCHLD		17
268#define	LINUX_SIGCONT		18
269#define	LINUX_SIGSTOP		19
270#define	LINUX_SIGTSTP		20
271#define	LINUX_SIGTTIN		21
272#define	LINUX_SIGTTOU		22
273#define	LINUX_SIGURG		23
274#define	LINUX_SIGXCPU		24
275#define	LINUX_SIGXFSZ		25
276#define	LINUX_SIGVTALRM		26
277#define	LINUX_SIGPROF		27
278#define	LINUX_SIGWINCH		28
279#define	LINUX_SIGIO		29
280#define	LINUX_SIGPOLL		LINUX_SIGIO
281#define	LINUX_SIGPWR		30
282#define	LINUX_SIGSYS		31
283
284#define	LINUX_SIGTBLSZ		31
285#define	LINUX_NSIG_WORDS	2
286#define	LINUX_NBPW		32
287#define	LINUX_NSIG		(LINUX_NBPW * LINUX_NSIG_WORDS)
288
289/* sigaction flags */
290#define	LINUX_SA_NOCLDSTOP	0x00000001
291#define	LINUX_SA_NOCLDWAIT	0x00000002
292#define	LINUX_SA_SIGINFO	0x00000004
293#define	LINUX_SA_RESTORER	0x04000000
294#define	LINUX_SA_ONSTACK	0x08000000
295#define	LINUX_SA_RESTART	0x10000000
296#define	LINUX_SA_INTERRUPT	0x20000000
297#define	LINUX_SA_NOMASK		0x40000000
298#define	LINUX_SA_ONESHOT	0x80000000
299
300/* sigprocmask actions */
301#define	LINUX_SIG_BLOCK		0
302#define	LINUX_SIG_UNBLOCK	1
303#define	LINUX_SIG_SETMASK	2
304
305/* sigset_t macros */
306#define	LINUX_SIGEMPTYSET(set)		(set).__bits[0] = (set).__bits[1] = 0
307#define	LINUX_SIGISMEMBER(set, sig)	SIGISMEMBER(set, sig)
308#define	LINUX_SIGADDSET(set, sig)	SIGADDSET(set, sig)
309
310/* sigaltstack */
311#define LINUX_MINSIGSTKSZ	2048
312#define LINUX_SS_ONSTACK	1
313#define LINUX_SS_DISABLE	2
314
315int linux_to_bsd_sigaltstack(int lsa);
316int bsd_to_linux_sigaltstack(int bsa);
317
318typedef l_uintptr_t l_handler_t;
319typedef l_ulong	l_osigset_t;
320
321typedef struct {
322	l_uint	__bits[LINUX_NSIG_WORDS];
323} __packed l_sigset_t;
324
325typedef struct {
326	l_handler_t	lsa_handler;
327	l_osigset_t	lsa_mask;
328	l_ulong		lsa_flags;
329	l_uintptr_t	lsa_restorer;
330} __packed l_osigaction_t;
331
332typedef struct {
333	l_handler_t	lsa_handler;
334	l_ulong		lsa_flags;
335	l_uintptr_t	lsa_restorer;
336	l_sigset_t	lsa_mask;
337} __packed l_sigaction_t;
338
339typedef struct {
340	l_uintptr_t	ss_sp;
341	l_int		ss_flags;
342	l_size_t	ss_size;
343} __packed l_stack_t;
344
345/* The Linux sigcontext, pretty much a standard 386 trapframe. */
346struct l_sigcontext {
347	l_int		sc_gs;
348	l_int		sc_fs;
349	l_int		sc_es;
350	l_int		sc_ds;
351	l_int		sc_edi;
352	l_int		sc_esi;
353	l_int		sc_ebp;
354	l_int		sc_esp;
355	l_int		sc_ebx;
356	l_int		sc_edx;
357	l_int		sc_ecx;
358	l_int		sc_eax;
359	l_int		sc_trapno;
360	l_int		sc_err;
361	l_int		sc_eip;
362	l_int		sc_cs;
363	l_int		sc_eflags;
364	l_int		sc_esp_at_signal;
365	l_int		sc_ss;
366	l_int		sc_387;
367	l_int		sc_mask;
368	l_int		sc_cr2;
369} __packed;
370
371struct l_ucontext {
372	l_ulong		uc_flags;
373	l_uintptr_t	uc_link;
374	l_stack_t	uc_stack;
375	struct l_sigcontext	uc_mcontext;
376        l_sigset_t	uc_sigmask;
377} __packed;
378
379#define LINUX_SI_MAX_SIZE     128
380#define LINUX_SI_PAD_SIZE     ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3)
381
382typedef struct l_siginfo {
383	l_int		lsi_signo;
384	l_int		lsi_errno;
385	l_int		lsi_code;
386	union {
387		l_int	_pad[LINUX_SI_PAD_SIZE];
388
389		struct {
390			l_pid_t		_pid;
391			l_uid16_t	_uid;
392		} __packed _kill;
393
394		struct {
395			l_uint		_timer1;
396			l_uint		_timer2;
397		} __packed _timer;
398
399		struct {
400			l_pid_t		_pid;		/* sender's pid */
401			l_uid16_t	_uid;		/* sender's uid */
402			union sigval _sigval;
403		} __packed _rt;
404
405		struct {
406			l_pid_t		_pid;		/* which child */
407			l_uid16_t	_uid;		/* sender's uid */
408			l_int		_status;	/* exit code */
409			l_clock_t	_utime;
410			l_clock_t	_stime;
411		} __packed _sigchld;
412
413		struct {
414			l_uintptr_t	_addr; /* faulting insn/memory ref. */
415		} __packed _sigfault;
416
417		struct {
418			l_int		_band;  /* POLL_IN,POLL_OUT,POLL_MSG */
419			l_int		_fd;
420		} __packed _sigpoll;
421	} _sifields;
422} __packed l_siginfo_t;
423
424#define lsi_pid          _sifields._kill._pid
425#define lsi_uid          _sifields._kill._uid
426#define lsi_status       _sifields._sigchld._status
427#define lsi_utime        _sifields._sigchld._utime
428#define lsi_stime        _sifields._sigchld._stime
429#define lsi_value        _sifields._rt._sigval
430#define lsi_int          _sifields._rt._sigval.sival_int
431#define lsi_ptr          _sifields._rt._sigval.sival_ptr
432#define lsi_addr         _sifields._sigfault._addr
433#define lsi_band         _sifields._sigpoll._band
434#define lsi_fd           _sifields._sigpoll._fd
435
436struct l_fpreg {
437	u_int16_t significand[4];
438	u_int16_t exponent;
439} __packed;
440
441struct l_fpxreg {
442	u_int16_t significand[4];
443	u_int16_t exponent;
444	u_int16_t padding[3];
445} __packed;
446
447struct l_xmmreg {
448	u_int32_t element[4];
449} __packed;
450
451struct l_fpstate {
452	/* Regular FPU environment */
453	u_int32_t		cw;
454	u_int32_t		sw;
455	u_int32_t		tag;
456	u_int32_t		ipoff;
457	u_int32_t		cssel;
458	u_int32_t		dataoff;
459	u_int32_t		datasel;
460	struct l_fpreg		_st[8];
461	u_int16_t		status;
462	u_int16_t		magic;  /* 0xffff = regular FPU data */
463
464	/* FXSR FPU environment */
465	u_int32_t		_fxsr_env[6]; /* env is ignored */
466	u_int32_t		mxcsr;
467	u_int32_t		reserved;
468	struct l_fpxreg		_fxsr_st[8];  /* reg data is ignored */
469	struct l_xmmreg		_xmm[8];
470	u_int32_t		padding[56];
471} __packed;
472
473/*
474 * We make the stack look like Linux expects it when calling a signal
475 * handler, but use the BSD way of calling the handler and sigreturn().
476 * This means that we need to pass the pointer to the handler too.
477 * It is appended to the frame to not interfere with the rest of it.
478 */
479struct l_sigframe {
480	l_int			sf_sig;
481	struct l_sigcontext	sf_sc;
482	struct l_fpstate	sf_fpstate;
483	l_uint			sf_extramask[LINUX_NSIG_WORDS-1];
484	l_handler_t		sf_handler;
485} __packed;
486
487struct l_rt_sigframe {
488	l_int			sf_sig;
489	l_uintptr_t 		sf_siginfo;
490	l_uintptr_t		sf_ucontext;
491	l_siginfo_t		sf_si;
492	struct l_ucontext 	sf_sc;
493	l_handler_t 		sf_handler;
494} __packed;
495
496extern int bsd_to_linux_signal[];
497extern int linux_to_bsd_signal[];
498extern struct sysentvec elf_linux_sysvec;
499
500/*
501 * Pluggable ioctl handlers
502 */
503struct linux_ioctl_args;
504struct thread;
505
506typedef int linux_ioctl_function_t(struct thread *, struct linux_ioctl_args *);
507
508struct linux_ioctl_handler {
509	linux_ioctl_function_t *func;
510	int	low, high;
511};
512
513int	linux_ioctl_register_handler(struct linux_ioctl_handler *h);
514int	linux_ioctl_unregister_handler(struct linux_ioctl_handler *h);
515
516/*
517 * open/fcntl flags
518 */
519#define	LINUX_O_RDONLY		00
520#define	LINUX_O_WRONLY		01
521#define	LINUX_O_RDWR		02
522#define	LINUX_O_CREAT		0100
523#define	LINUX_O_EXCL		0200
524#define	LINUX_O_NOCTTY		0400
525#define	LINUX_O_TRUNC		01000
526#define	LINUX_O_APPEND		02000
527#define	LINUX_O_NONBLOCK	04000
528#define	LINUX_O_NDELAY		LINUX_O_NONBLOCK
529#define	LINUX_O_SYNC		010000
530#define	LINUX_FASYNC		020000
531#define	LINUX_O_DIRECT		040000	/* direct disk access hint */
532#define	LINUX_O_LARGEFILE	0100000
533#define	LINUX_O_DIRECTORY	0200000	/* must be a directory */
534#define	LINUX_O_NOFOLLOW	0400000	/* don't follow links */
535#define	LINUX_O_NOATIME		01000000
536
537#define	LINUX_F_DUPFD		0
538#define	LINUX_F_GETFD		1
539#define	LINUX_F_SETFD		2
540#define	LINUX_F_GETFL		3
541#define	LINUX_F_SETFL		4
542#define	LINUX_F_GETLK		5
543#define	LINUX_F_SETLK		6
544#define	LINUX_F_SETLKW		7
545#define	LINUX_F_SETOWN		8
546#define	LINUX_F_GETOWN		9
547
548#define	LINUX_F_GETLK64		12
549#define	LINUX_F_SETLK64		13
550#define	LINUX_F_SETLKW64	14
551
552#define	LINUX_F_RDLCK		0
553#define	LINUX_F_WRLCK		1
554#define	LINUX_F_UNLCK		2
555
556/*
557 * mount flags
558 */
559#define LINUX_MS_RDONLY         0x0001
560#define LINUX_MS_NOSUID         0x0002
561#define LINUX_MS_NODEV          0x0004
562#define LINUX_MS_NOEXEC         0x0008
563#define LINUX_MS_REMOUNT        0x0020
564
565/*
566 * SystemV IPC defines
567 */
568#define	LINUX_SEMOP		1
569#define	LINUX_SEMGET		2
570#define	LINUX_SEMCTL		3
571#define	LINUX_MSGSND		11
572#define	LINUX_MSGRCV		12
573#define	LINUX_MSGGET		13
574#define	LINUX_MSGCTL		14
575#define	LINUX_SHMAT		21
576#define	LINUX_SHMDT		22
577#define	LINUX_SHMGET		23
578#define	LINUX_SHMCTL		24
579
580#define	LINUX_IPC_RMID		0
581#define	LINUX_IPC_SET		1
582#define	LINUX_IPC_STAT		2
583#define	LINUX_IPC_INFO		3
584
585#define	LINUX_SHM_LOCK		11
586#define	LINUX_SHM_UNLOCK	12
587#define	LINUX_SHM_STAT		13
588#define	LINUX_SHM_INFO		14
589
590#define	LINUX_SHM_RDONLY	0x1000
591#define	LINUX_SHM_RND		0x2000
592#define	LINUX_SHM_REMAP		0x4000
593
594/* semctl commands */
595#define	LINUX_GETPID		11
596#define	LINUX_GETVAL		12
597#define	LINUX_GETALL		13
598#define	LINUX_GETNCNT		14
599#define	LINUX_GETZCNT		15
600#define	LINUX_SETVAL		16
601#define	LINUX_SETALL		17
602#define	LINUX_SEM_STAT		18
603#define	LINUX_SEM_INFO		19
604
605union l_semun {
606	l_int		val;
607	l_uintptr_t	buf;
608	l_uintptr_t	array;
609	l_uintptr_t	__buf;
610	l_uintptr_t	__pad;
611} __packed;
612
613/*
614 * Socket defines
615 */
616#define	LINUX_SOCKET 		1
617#define	LINUX_BIND		2
618#define	LINUX_CONNECT 		3
619#define	LINUX_LISTEN 		4
620#define	LINUX_ACCEPT 		5
621#define	LINUX_GETSOCKNAME	6
622#define	LINUX_GETPEERNAME	7
623#define	LINUX_SOCKETPAIR	8
624#define	LINUX_SEND		9
625#define	LINUX_RECV		10
626#define	LINUX_SENDTO 		11
627#define	LINUX_RECVFROM 		12
628#define	LINUX_SHUTDOWN 		13
629#define	LINUX_SETSOCKOPT	14
630#define	LINUX_GETSOCKOPT	15
631#define	LINUX_SENDMSG		16
632#define	LINUX_RECVMSG		17
633
634#define	LINUX_AF_UNSPEC		0
635#define	LINUX_AF_UNIX		1
636#define	LINUX_AF_INET		2
637#define	LINUX_AF_AX25		3
638#define	LINUX_AF_IPX		4
639#define	LINUX_AF_APPLETALK	5
640#define	LINUX_AF_INET6		10
641
642#define	LINUX_SOL_SOCKET	1
643#define	LINUX_SOL_IP		0
644#define	LINUX_SOL_IPX		256
645#define	LINUX_SOL_AX25		257
646#define	LINUX_SOL_TCP		6
647#define	LINUX_SOL_UDP		17
648
649#define	LINUX_SO_DEBUG		1
650#define	LINUX_SO_REUSEADDR	2
651#define	LINUX_SO_TYPE		3
652#define	LINUX_SO_ERROR		4
653#define	LINUX_SO_DONTROUTE	5
654#define	LINUX_SO_BROADCAST	6
655#define	LINUX_SO_SNDBUF		7
656#define	LINUX_SO_RCVBUF		8
657#define	LINUX_SO_KEEPALIVE	9
658#define	LINUX_SO_OOBINLINE	10
659#define	LINUX_SO_NO_CHECK	11
660#define	LINUX_SO_PRIORITY	12
661#define	LINUX_SO_LINGER		13
662
663#define	LINUX_IP_TOS		1
664#define	LINUX_IP_TTL		2
665#define	LINUX_IP_HDRINCL	3
666#define	LINUX_IP_OPTIONS	4
667
668#define	LINUX_IP_MULTICAST_IF		32
669#define	LINUX_IP_MULTICAST_TTL		33
670#define	LINUX_IP_MULTICAST_LOOP		34
671#define	LINUX_IP_ADD_MEMBERSHIP		35
672#define	LINUX_IP_DROP_MEMBERSHIP	36
673
674struct l_sockaddr {
675	l_ushort	sa_family;
676	char		sa_data[14];
677} __packed;
678
679struct l_ifmap {
680	l_ulong		mem_start;
681	l_ulong		mem_end;
682	l_ushort	base_addr;
683	u_char		irq;
684	u_char		dma;
685	u_char		port;
686} __packed;
687
688#define	LINUX_IFHWADDRLEN	6
689#define	LINUX_IFNAMSIZ		16
690
691struct l_ifreq {
692	union {
693		char	ifrn_name[LINUX_IFNAMSIZ];
694	} ifr_ifrn;
695
696	union {
697		struct l_sockaddr	ifru_addr;
698		struct l_sockaddr	ifru_dstaddr;
699		struct l_sockaddr	ifru_broadaddr;
700		struct l_sockaddr	ifru_netmask;
701		struct l_sockaddr	ifru_hwaddr;
702		l_short		ifru_flags[1];
703		l_int		ifru_metric;
704		l_int		ifru_mtu;
705		struct l_ifmap	ifru_map;
706		char		ifru_slave[LINUX_IFNAMSIZ];
707		l_uintptr_t	ifru_data;
708	} ifr_ifru;
709} __packed;
710
711#define	ifr_name	ifr_ifrn.ifrn_name	/* interface name */
712#define	ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address */
713
714struct l_ifconf {
715	int	ifc_len;
716	union {
717		l_uintptr_t	ifcu_buf;
718		l_uintptr_t	ifcu_req;
719	} ifc_ifcu;
720} __packed;
721
722#define	ifc_buf		ifc_ifcu.ifcu_buf
723#define	ifc_req		ifc_ifcu.ifcu_req
724
725/*
726 * poll()
727 */
728#define	LINUX_POLLIN		0x0001
729#define	LINUX_POLLPRI		0x0002
730#define	LINUX_POLLOUT		0x0004
731#define	LINUX_POLLERR		0x0008
732#define	LINUX_POLLHUP		0x0010
733#define	LINUX_POLLNVAL		0x0020
734#define	LINUX_POLLRDNORM	0x0040
735#define	LINUX_POLLRDBAND	0x0080
736#define	LINUX_POLLWRNORM	0x0100
737#define	LINUX_POLLWRBAND	0x0200
738#define	LINUX_POLLMSG		0x0400
739
740struct l_pollfd {
741	l_int		fd;
742	l_short		events;
743	l_short		revents;
744} __packed;
745
746struct l_user_desc {
747	l_uint		entry_number;
748	l_uint		base_addr;
749	l_uint		limit;
750	l_uint		seg_32bit:1;
751	l_uint		contents:2;
752	l_uint		read_exec_only:1;
753	l_uint		limit_in_pages:1;
754	l_uint		seg_not_present:1;
755	l_uint		useable:1;
756};
757
758struct l_desc_struct {
759           unsigned long a,b;
760};
761
762
763#define LINUX_LOWERWORD	0x0000ffff
764
765/*
766 * macros which does the same thing as those in linux include/asm-um/ldt-i386.h
767 * these convert linux user-space descriptor to machine one
768 */
769#define LDT_entry_a(info) \
770        ((((info)->base_addr & LINUX_LOWERWORD) << 16) | ((info)->limit & LINUX_LOWERWORD))
771
772#define ENTRY_B_READ_EXEC_ONLY	9
773#define ENTRY_B_CONTENTS	10
774#define ENTRY_B_SEG_NOT_PRESENT	15
775#define ENTRY_B_BASE_ADDR	16
776#define ENTRY_B_USEABLE		20
777#define ENTRY_B_SEG32BIT	22
778#define ENTRY_B_LIMIT		23
779
780#define LDT_entry_b(info) \
781        (((info)->base_addr & 0xff000000) | \
782        ((info)->limit & 0xf0000) | \
783        ((info)->contents << ENTRY_B_CONTENTS) | \
784        (((info)->seg_not_present == 0) << ENTRY_B_SEG_NOT_PRESENT) | \
785        (((info)->base_addr & 0x00ff0000) >> ENTRY_B_BASE_ADDR) | \
786        (((info)->read_exec_only == 0) << ENTRY_B_READ_EXEC_ONLY) | \
787        ((info)->seg_32bit << ENTRY_B_SEG32BIT) | \
788        ((info)->useable << ENTRY_B_USEABLE) | \
789        ((info)->limit_in_pages << ENTRY_B_LIMIT) | 0x7000)
790
791#define LDT_empty(info) (\
792        (info)->base_addr       == 0    && \
793        (info)->limit           == 0    && \
794        (info)->contents        == 0    && \
795        (info)->seg_not_present == 1    && \
796        (info)->read_exec_only  == 1    && \
797        (info)->seg_32bit       == 0    && \
798        (info)->limit_in_pages  == 0    && \
799        (info)->useable         == 0    )
800
801/* macros for converting segments, they do the same as those in arch/i386/kernel/process.c */
802#define GET_BASE(desc) ( \
803        (((desc)->a >> 16) & LINUX_LOWERWORD) | \
804        (((desc)->b << 16) & 0x00ff0000) | \
805        ( (desc)->b        & 0xff000000)   )
806
807#define GET_LIMIT(desc) ( \
808        ((desc)->a & LINUX_LOWERWORD) | \
809         ((desc)->b & 0xf0000) )
810
811#define GET_32BIT(desc)         (((desc)->b >> ENTRY_B_SEG32BIT) & 1)
812#define GET_CONTENTS(desc)      (((desc)->b >> ENTRY_B_CONTENTS) & 3)
813#define GET_WRITABLE(desc)      (((desc)->b >> ENTRY_B_READ_EXEC_ONLY) & 1)
814#define GET_LIMIT_PAGES(desc)   (((desc)->b >> ENTRY_B_LIMIT) & 1)
815#define GET_PRESENT(desc)       (((desc)->b >> ENTRY_B_SEG_NOT_PRESENT) & 1)
816#define GET_USEABLE(desc)       (((desc)->b >> ENTRY_B_USEABLE) & 1)
817
818#define LINUX_CLOCK_REALTIME            0
819#define LINUX_CLOCK_MONOTONIC           1
820#define LINUX_CLOCK_PROCESS_CPUTIME_ID  2
821#define LINUX_CLOCK_THREAD_CPUTIME_ID   3
822#define LINUX_CLOCK_REALTIME_HR         4
823#define LINUX_CLOCK_MONOTONIC_HR        5
824
825typedef int l_timer_t;
826typedef int l_mqd_t;
827
828#define CLONE_VM        0x100
829#define CLONE_FS        0x200
830#define CLONE_FILES     0x400
831#define CLONE_SIGHAND   0x800
832#define CLONE_PID       0x1000          /* this flag does not exist in linux anymore */
833#define CLONE_PARENT    0x00008000
834#define CLONE_THREAD    0x10000
835#define CLONE_SETTLS    0x80000
836#define CLONE_CHILD_CLEARTID    0x00200000
837#define CLONE_CHILD_SETTID      0x01000000
838#define CLONE_PARENT_SETTID     0x00100000
839
840#define THREADING_FLAGS (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
841
842#endif /* !_AMD64_LINUX_LINUX_H_ */
843