Deleted Added
sdiff udiff text old ( 78161 ) new ( 83221 )
full compact
1/*-
2 * Copyright (c) 1994-1996 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/i386/linux/linux.h 78161 2001-06-13 10:58:39Z peter $
29 */
30
31#ifndef _I386_LINUX_LINUX_H_
32#define _I386_LINUX_LINUX_H_
33
34#include <sys/signal.h> /* for sigval union */
35
36#include <i386/linux/linux_syscall.h>
37
38/*
39 * debugging support
40 */
41extern u_char linux_debug_map[];
42#define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name)
43#define ARGS(nm, fmt) "Linux-emul(%ld): "#nm"("fmt")\n", (long)p->p_pid
44#define LMSG(fmt) "Linux-emul(%ld): "fmt"\n", (long)p->p_pid
45
46#ifdef MALLOC_DECLARE
47MALLOC_DECLARE(M_LINUX);
48#endif
49
50/*
51 * Miscellaneous
52 */
53#define LINUX_NAME_MAX 255
54#define LINUX_MAX_UTSNAME 65
55
56/* Scheduling policies */
57#define LINUX_SCHED_OTHER 0
58#define LINUX_SCHED_FIFO 1
59#define LINUX_SCHED_RR 2
60
61/* Resource limits */
62#define LINUX_RLIMIT_CPU 0
63#define LINUX_RLIMIT_FSIZE 1
64#define LINUX_RLIMIT_DATA 2
65#define LINUX_RLIMIT_STACK 3
66#define LINUX_RLIMIT_CORE 4
67#define LINUX_RLIMIT_RSS 5
68#define LINUX_RLIMIT_NPROC 6
69#define LINUX_RLIMIT_NOFILE 7
70#define LINUX_RLIMIT_MEMLOCK 8
71#define LINUX_RLIMIT_AS 9 /* address space limit */
72
73#define LINUX_RLIM_NLIMITS 10
74
75/* mmap options */
76#define LINUX_MAP_SHARED 0x0001
77#define LINUX_MAP_PRIVATE 0x0002
78#define LINUX_MAP_FIXED 0x0010
79#define LINUX_MAP_ANON 0x0020
80#define LINUX_MAP_GROWSDOWN 0x0100
81
82typedef char * linux_caddr_t;
83typedef long linux_clock_t;
84typedef u_short linux_dev_t;
85typedef u_short linux_gid_t;
86typedef u_long linux_ino_t;
87typedef int linux_key_t; /* XXX */
88typedef u_short linux_mode_t;
89typedef u_short linux_nlink_t;
90typedef long linux_off_t;
91typedef int linux_pid_t;
92typedef u_int linux_size_t;
93typedef long linux_time_t;
94typedef u_short linux_uid_t;
95
96typedef struct {
97 long val[2];
98} linux_fsid_t;
99
100struct linux_new_utsname {
101 char sysname[LINUX_MAX_UTSNAME];
102 char nodename[LINUX_MAX_UTSNAME];
103 char release[LINUX_MAX_UTSNAME];
104 char version[LINUX_MAX_UTSNAME];
105 char machine[LINUX_MAX_UTSNAME];
106 char domainname[LINUX_MAX_UTSNAME];
107};
108
109/*
110 * Signalling
111 */
112#define LINUX_SIGHUP 1
113#define LINUX_SIGINT 2
114#define LINUX_SIGQUIT 3
115#define LINUX_SIGILL 4
116#define LINUX_SIGTRAP 5
117#define LINUX_SIGABRT 6
118#define LINUX_SIGIOT LINUX_SIGABRT
119#define LINUX_SIGBUS 7
120#define LINUX_SIGFPE 8
121#define LINUX_SIGKILL 9
122#define LINUX_SIGUSR1 10
123#define LINUX_SIGSEGV 11
124#define LINUX_SIGUSR2 12
125#define LINUX_SIGPIPE 13
126#define LINUX_SIGALRM 14
127#define LINUX_SIGTERM 15
128#define LINUX_SIGSTKFLT 16
129#define LINUX_SIGCHLD 17
130#define LINUX_SIGCONT 18
131#define LINUX_SIGSTOP 19
132#define LINUX_SIGTSTP 20
133#define LINUX_SIGTTIN 21
134#define LINUX_SIGTTOU 22
135#define LINUX_SIGURG 23
136#define LINUX_SIGXCPU 24
137#define LINUX_SIGXFSZ 25
138#define LINUX_SIGVTALRM 26
139#define LINUX_SIGPROF 27
140#define LINUX_SIGWINCH 28
141#define LINUX_SIGIO 29
142#define LINUX_SIGPOLL LINUX_SIGIO
143#define LINUX_SIGPWR 30
144#define LINUX_SIGUNUSED 31
145
146#define LINUX_SIGTBLSZ 31
147#define LINUX_NSIG_WORDS 2
148#define LINUX_NBPW 32
149#define LINUX_NSIG (LINUX_NBPW * LINUX_NSIG_WORDS)
150
151/* sigaction flags */
152#define LINUX_SA_NOCLDSTOP 0x00000001
153#define LINUX_SA_NOCLDWAIT 0x00000002
154#define LINUX_SA_SIGINFO 0x00000004
155#define LINUX_SA_RESTORER 0x04000000
156#define LINUX_SA_ONSTACK 0x08000000
157#define LINUX_SA_RESTART 0x10000000
158#define LINUX_SA_INTERRUPT 0x20000000
159#define LINUX_SA_NOMASK 0x40000000
160#define LINUX_SA_ONESHOT 0x80000000
161
162/* sigprocmask actions */
163#define LINUX_SIG_BLOCK 0
164#define LINUX_SIG_UNBLOCK 1
165#define LINUX_SIG_SETMASK 2
166
167/* sigset_t macros */
168#define LINUX_SIGEMPTYSET(set) (set).__bits[0] = (set).__bits[1] = 0
169#define LINUX_SIGISMEMBER(set, sig) SIGISMEMBER(set, sig)
170#define LINUX_SIGADDSET(set, sig) SIGADDSET(set, sig)
171
172/* sigaltstack */
173#define LINUX_MINSIGSTKSZ 2048
174#define LINUX_SS_ONSTACK 1
175#define LINUX_SS_DISABLE 2
176
177
178int linux_to_bsd_sigaltstack(int lsa);
179int bsd_to_linux_sigaltstack(int bsa);
180
181
182typedef void (*linux_handler_t)(int);
183typedef u_long linux_osigset_t;
184
185typedef struct {
186 u_int __bits[LINUX_NSIG_WORDS];
187} linux_sigset_t;
188
189typedef struct {
190 linux_handler_t lsa_handler;
191 linux_osigset_t lsa_mask;
192 u_long lsa_flags;
193 void (*lsa_restorer)(void);
194} linux_osigaction_t;
195
196typedef struct {
197 linux_handler_t lsa_handler;
198 u_long lsa_flags;
199 void (*lsa_restorer)(void);
200 linux_sigset_t lsa_mask;
201} linux_sigaction_t;
202
203typedef struct {
204 void *ss_sp;
205 int ss_flags;
206 linux_size_t ss_size;
207} linux_stack_t;
208
209/* The Linux sigcontext, pretty much a standard 386 trapframe. */
210struct linux_sigcontext {
211 int sc_gs;
212 int sc_fs;
213 int sc_es;
214 int sc_ds;
215 int sc_edi;
216 int sc_esi;
217 int sc_ebp;
218 int sc_esp;
219 int sc_ebx;
220 int sc_edx;
221 int sc_ecx;
222 int sc_eax;
223 int sc_trapno;
224 int sc_err;
225 int sc_eip;
226 int sc_cs;
227 int sc_eflags;
228 int sc_esp_at_signal;
229 int sc_ss;
230 int sc_387;
231 int sc_mask;
232 int sc_cr2;
233};
234
235struct linux_ucontext {
236 unsigned long uc_flags;
237 void *uc_link;
238 linux_stack_t uc_stack;
239 struct linux_sigcontext uc_mcontext;
240 linux_sigset_t uc_sigmask;
241};
242
243
244#define LINUX_SI_MAX_SIZE 128
245#define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(int)) - 3)
246
247typedef struct siginfo {
248 int lsi_signo;
249 int lsi_errno;
250 int lsi_code;
251
252 union {
253 int _pad[LINUX_SI_PAD_SIZE];
254 struct {
255 linux_pid_t _pid;
256 linux_uid_t _uid;
257 } _kill;
258
259 struct {
260 unsigned int _timer1;
261 unsigned int _timer2;
262 } _timer;
263
264 struct {
265 linux_pid_t _pid; /* sender's pid */
266 linux_uid_t _uid; /* sender's uid */
267 union sigval _sigval;
268 } _rt;
269
270 struct {
271 linux_pid_t _pid; /* which child */
272 linux_uid_t _uid; /* sender's uid */
273 int _status; /* exit code */
274 linux_clock_t _utime;
275 linux_clock_t _stime;
276 } _sigchld;
277
278 struct {
279 void *_addr; /* faulting insn/memory ref. */
280 } _sigfault;
281
282 struct {
283 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
284 int _fd;
285 } _sigpoll;
286 } _sifields;
287} linux_siginfo_t;
288
289#define lsi_pid _sifields._kill._pid
290#define lsi_uid _sifields._kill._uid
291#define lsi_status _sifields._sigchld._status
292#define lsi_utime _sifields._sigchld._utime
293#define lsi_stime _sifields._sigchld._stime
294#define lsi_value _sifields._rt._sigval
295#define lsi_int _sifields._rt._sigval.sival_int
296#define lsi_ptr _sifields._rt._sigval.sival_ptr
297#define lsi_addr _sifields._sigfault._addr
298#define lsi_band _sifields._sigpoll._band
299#define lsi_fd _sifields._sigpoll._fd
300
301struct linux_fpreg {
302 u_int16_t significand[4];
303 u_int16_t exponent;
304};
305
306struct linux_fpxreg {
307 u_int16_t significand[4];
308 u_int16_t exponent;
309 u_int16_t padding[3];
310};
311
312struct linux_xmmreg {
313 u_int32_t element[4];
314};
315
316struct linux_fpstate {
317 /* Regular FPU environment */
318 u_int32_t cw;
319 u_int32_t sw;
320 u_int32_t tag;
321 u_int32_t ipoff;
322 u_int32_t cssel;
323 u_int32_t dataoff;
324 u_int32_t datasel;
325 struct linux_fpreg _st[8];
326 u_int16_t status;
327 u_int16_t magic; /* 0xffff = regular FPU data */
328
329 /* FXSR FPU environment */
330 u_int32_t _fxsr_env[6]; /* env is ignored */
331 u_int32_t mxcsr;
332 u_int32_t reserved;
333 struct linux_fpxreg _fxsr_st[8]; /* reg data is ignored */
334 struct linux_xmmreg _xmm[8];
335 u_int32_t padding[56];
336};
337
338/*
339 * We make the stack look like Linux expects it when calling a signal
340 * handler, but use the BSD way of calling the handler and sigreturn().
341 * This means that we need to pass the pointer to the handler too.
342 * It is appended to the frame to not interfere with the rest of it.
343 */
344struct linux_sigframe {
345 int sf_sig;
346 struct linux_sigcontext sf_sc;
347 struct linux_fpstate sf_fpstate;
348 u_int sf_extramask[LINUX_NSIG_WORDS-1];
349 linux_handler_t sf_handler;
350};
351
352struct linux_rt_sigframe {
353 int sf_sig;
354 linux_siginfo_t *sf_siginfo;
355 struct linux_ucontext *sf_ucontext;
356 linux_siginfo_t sf_si;
357 struct linux_ucontext sf_sc;
358 linux_handler_t sf_handler;
359};
360
361extern int bsd_to_linux_signal[];
362extern int linux_to_bsd_signal[];
363extern struct sysentvec linux_sysvec;
364extern struct sysentvec elf_linux_sysvec;
365
366/*
367 * Pluggable ioctl handlers
368 */
369struct linux_ioctl_args;
370struct proc;
371
372typedef int linux_ioctl_function_t(struct proc *, struct linux_ioctl_args *);
373
374struct linux_ioctl_handler {
375 linux_ioctl_function_t *func;
376 int low, high;
377};
378
379int linux_ioctl_register_handler(struct linux_ioctl_handler *h);
380int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h);
381
382/*
383 * open/fcntl flags
384 */
385#define LINUX_O_RDONLY 00
386#define LINUX_O_WRONLY 01
387#define LINUX_O_RDWR 02
388#define LINUX_O_CREAT 0100
389#define LINUX_O_EXCL 0200
390#define LINUX_O_NOCTTY 0400
391#define LINUX_O_TRUNC 01000
392#define LINUX_O_APPEND 02000
393#define LINUX_O_NONBLOCK 04000
394#define LINUX_O_NDELAY LINUX_O_NONBLOCK
395#define LINUX_O_SYNC 010000
396#define LINUX_FASYNC 020000
397
398#define LINUX_F_DUPFD 0
399#define LINUX_F_GETFD 1
400#define LINUX_F_SETFD 2
401#define LINUX_F_GETFL 3
402#define LINUX_F_SETFL 4
403#define LINUX_F_GETLK 5
404#define LINUX_F_SETLK 6
405#define LINUX_F_SETLKW 7
406#define LINUX_F_SETOWN 8
407#define LINUX_F_GETOWN 9
408
409#define LINUX_F_RDLCK 0
410#define LINUX_F_WRLCK 1
411#define LINUX_F_UNLCK 2
412
413/*
414 * mount flags
415 */
416#define LINUX_MS_RDONLY 0x0001
417#define LINUX_MS_NOSUID 0x0002
418#define LINUX_MS_NODEV 0x0004
419#define LINUX_MS_NOEXEC 0x0008
420#define LINUX_MS_REMOUNT 0x0020
421
422/*
423 * SystemV IPC defines
424 */
425#define LINUX_SEMOP 1
426#define LINUX_SEMGET 2
427#define LINUX_SEMCTL 3
428#define LINUX_MSGSND 11
429#define LINUX_MSGRCV 12
430#define LINUX_MSGGET 13
431#define LINUX_MSGCTL 14
432#define LINUX_SHMAT 21
433#define LINUX_SHMDT 22
434#define LINUX_SHMGET 23
435#define LINUX_SHMCTL 24
436
437#define LINUX_IPC_RMID 0
438#define LINUX_IPC_SET 1
439#define LINUX_IPC_STAT 2
440#define LINUX_IPC_INFO 3
441
442#define LINUX_SHM_LOCK 11
443#define LINUX_SHM_UNLOCK 12
444#define LINUX_SHM_STAT 13
445#define LINUX_SHM_INFO 14
446
447#define LINUX_SHM_RDONLY 0x1000
448#define LINUX_SHM_RND 0x2000
449#define LINUX_SHM_REMAP 0x4000
450
451/* semctl commands */
452#define LINUX_GETPID 11
453#define LINUX_GETVAL 12
454#define LINUX_GETALL 13
455#define LINUX_GETNCNT 14
456#define LINUX_GETZCNT 15
457#define LINUX_SETVAL 16
458#define LINUX_SETALL 17
459
460/*
461 * Socket defines
462 */
463#define LINUX_SOCKET 1
464#define LINUX_BIND 2
465#define LINUX_CONNECT 3
466#define LINUX_LISTEN 4
467#define LINUX_ACCEPT 5
468#define LINUX_GETSOCKNAME 6
469#define LINUX_GETPEERNAME 7
470#define LINUX_SOCKETPAIR 8
471#define LINUX_SEND 9
472#define LINUX_RECV 10
473#define LINUX_SENDTO 11
474#define LINUX_RECVFROM 12
475#define LINUX_SHUTDOWN 13
476#define LINUX_SETSOCKOPT 14
477#define LINUX_GETSOCKOPT 15
478#define LINUX_SENDMSG 16
479#define LINUX_RECVMSG 17
480
481#define LINUX_AF_UNSPEC 0
482#define LINUX_AF_UNIX 1
483#define LINUX_AF_INET 2
484#define LINUX_AF_AX25 3
485#define LINUX_AF_IPX 4
486#define LINUX_AF_APPLETALK 5
487
488#define LINUX_SOL_SOCKET 1
489#define LINUX_SOL_IP 0
490#define LINUX_SOL_IPX 256
491#define LINUX_SOL_AX25 257
492#define LINUX_SOL_TCP 6
493#define LINUX_SOL_UDP 17
494
495#define LINUX_SO_DEBUG 1
496#define LINUX_SO_REUSEADDR 2
497#define LINUX_SO_TYPE 3
498#define LINUX_SO_ERROR 4
499#define LINUX_SO_DONTROUTE 5
500#define LINUX_SO_BROADCAST 6
501#define LINUX_SO_SNDBUF 7
502#define LINUX_SO_RCVBUF 8
503#define LINUX_SO_KEEPALIVE 9
504#define LINUX_SO_OOBINLINE 10
505#define LINUX_SO_NO_CHECK 11
506#define LINUX_SO_PRIORITY 12
507#define LINUX_SO_LINGER 13
508
509#define LINUX_IP_TOS 1
510#define LINUX_IP_TTL 2
511#define LINUX_IP_HDRINCL 3
512#define LINUX_IP_OPTIONS 4
513
514#define LINUX_IP_MULTICAST_IF 32
515#define LINUX_IP_MULTICAST_TTL 33
516#define LINUX_IP_MULTICAST_LOOP 34
517#define LINUX_IP_ADD_MEMBERSHIP 35
518#define LINUX_IP_DROP_MEMBERSHIP 36
519
520struct linux_sockaddr {
521 u_short sa_family;
522 char sa_data[14];
523};
524
525struct linux_ifmap {
526 u_long mem_start;
527 u_long mem_end;
528 u_short base_addr;
529 u_char irq;
530 u_char dma;
531 u_char port;
532};
533
534#define LINUX_IFHWADDRLEN 6
535#define LINUX_IFNAMSIZ 16
536
537struct linux_ifreq {
538 union {
539 char ifrn_name[LINUX_IFNAMSIZ];
540 } ifr_ifrn;
541
542 union {
543 struct linux_sockaddr ifru_addr;
544 struct linux_sockaddr ifru_dstaddr;
545 struct linux_sockaddr ifru_broadaddr;
546 struct linux_sockaddr ifru_netmask;
547 struct linux_sockaddr ifru_hwaddr;
548 short ifru_flags;
549 int ifru_metric;
550 int ifru_mtu;
551 struct linux_ifmap ifru_map;
552 char ifru_slave[LINUX_IFNAMSIZ]; /* Just fits the size */
553 linux_caddr_t ifru_data;
554 } ifr_ifru;
555};
556
557#define ifr_name ifr_ifrn.ifrn_name /* interface name */
558#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
559
560#endif /* !_I386_LINUX_LINUX_H_ */