blob: 9ec236acb545a490ce9eebdab0a42a64fc261825 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
3/*--- A header file defining structures and constants which are ---*/
4/*--- important at the kernel boundary for this platform. ---*/
5/*--- vg_kerneliface.h ---*/
6/*--------------------------------------------------------------------*/
7
8/*
9 This file is part of Valgrind, an x86 protected-mode emulator
10 designed for debugging and profiling binaries on x86-Unixes.
11
12 Copyright (C) 2000-2002 Julian Seward
13 jseward@acm.org
14 Julian_Seward@muraroa.demon.co.uk
15
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License as
18 published by the Free Software Foundation; either version 2 of the
19 License, or (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 02111-1307, USA.
30
31 The GNU General Public License is contained in the file LICENSE.
32*/
33
34#ifndef __VG_KERNELIFACE_H
35#define __VG_KERNELIFACE_H
36
37/* This file is ONLY to be included into vg_include.h. Do not include
38 it directly into valgrind source .c files. This file defines types
39 and constants for the kernel interface, and to make that clear
40 everything is prefixed VKI. */
41
42/*--- All the following stuff is correct for Linux kernels 2.2.X and
43 2.4.X.
44---*/
45
46/* Should really get this from an include file somewhere. */
47#define VKI_BYTES_PER_PAGE_BITS 12
48#define VKI_BYTES_PER_PAGE (1 << VKI_BYTES_PER_PAGE_BITS)
49
50#define VKI_BYTES_PER_WORD 4
51#define VKI_WORDS_PER_PAGE (VKI_BYTES_PER_PAGE / VKI_BYTES_PER_WORD)
52
53
54/* For system call numbers __NR_... */
55#include <asm/unistd.h>
56
57/* An implementation of signal sets. These are the same as the sigset
58 implementations in the relevant Linux kernels. Note carefully that
59 this has nothing to do with glibc's signal sets. We work entirely
60 at the kernel boundary, so the libc stuff is invisible and
61 irrelevant. */
62
63/* The following is copied from
64 /usr/src/linux-2.4.9-13/include/asm-i386/signal.h */
65#define VKI_KNSIG 64 /* true for linux 2.2.X and 2.4.X */
66#define VKI_KNSIG_BPW 32 /* since we're using UInts */
67#define VKI_KNSIG_WORDS (VKI_KNSIG / VKI_KNSIG_BPW)
68
69typedef
70 struct {
71 UInt ws[VKI_KNSIG_WORDS];
72 }
73 vki_ksigset_t;
74
75typedef
76 struct {
77 void* ksa_handler;
78 unsigned long ksa_flags;
79 void (*ksa_restorer)(void);
80 vki_ksigset_t ksa_mask;
81 }
82 vki_ksigaction;
83
84typedef
85 struct {
86 void* ss_sp;
87 Int ss_flags;
88 UInt ss_size;
89 }
90 vki_kstack_t;
91
92
93#define VKI_SIG_BLOCK 0 /* for blocking signals */
94#define VKI_SIG_UNBLOCK 1 /* for unblocking signals */
95#define VKI_SIG_SETMASK 2 /* for setting the signal mask */
96
97#define VKI_SIG_DFL ((void*)0) /* default signal handling */
98#define VKI_SIG_IGN ((void*)1) /* ignore signal */
99#define VKI_SIG_ERR ((void*)-1) /* error return from signal */
100
101#define VKI_SA_ONSTACK 0x08000000
102#define VKI_SA_RESTART 0x10000000
103#if 0
104#define VKI_SA_NOCLDSTOP 0x00000001
105#define VKI_SA_NOCLDWAIT 0x00000002 /* not supported yet */
106#define VKI_SA_SIGINFO 0x00000004
107#define VKI_SA_NODEFER 0x40000000
108#define VKI_SA_RESETHAND 0x80000000
109#define VKI_SA_NOMASK SA_NODEFER
110#define VKI_SA_ONESHOT SA_RESETHAND
111#define VKI_SA_INTERRUPT 0x20000000 /* dummy -- ignored */
112#define VKI_SA_RESTORER 0x04000000
113#endif
114
115#define VKI_SIGABRT 6
116#define VKI_SIGSEGV 11
117#define VKI_SIGBUS 7
118#define VKI_SIGILL 4
119#define VKI_SIGFPE 8
120#define VKI_SIGKILL 9
121#define VKI_SIGABRT 6
122#define VKI_SIGSTOP 19
123#define VKI_SIGTERM 15
124
125/* The following are copied from /usr/include/bits/mman.h, which in
126 turn claims to have got them from the kernel headers. */
127
128#define VKI_PROT_READ 0x1 /* Page can be read. */
129#define VKI_PROT_WRITE 0x2 /* Page can be written. */
130#define VKI_PROT_EXEC 0x4 /* Page can be executed. */
131#define VKI_MAP_ANONYMOUS 0x20 /* Don't use a file. */
132#define VKI_MAP_PRIVATE 0x02 /* Changes are private. */
133
134
sewardj0ca2a6b2002-03-29 14:02:34 +0000135/* Copied from /usr/src/linux-2.4.9-13/include/asm/errno.h */
136
137#define VKI_EINVAL 22 /* Invalid argument */
sewardj2e93c502002-04-12 11:12:52 +0000138#define VKI_ENOMEM 12 /* Out of memory */
139
140#define VKI_EWOULDBLOCK VKI_EAGAIN /* Operation would block */
141#define VKI_EAGAIN 11 /* Try again */
sewardj0ca2a6b2002-03-29 14:02:34 +0000142
143
sewardjde4a1d02002-03-22 01:27:54 +0000144/* Gawd ... hack ... */
145
146typedef struct vki__user_cap_header_struct {
147 UInt version;
148 int pid;
149} vki_cap_user_header_t;
150
151typedef struct vki__user_cap_data_struct {
152 UInt effective;
153 UInt permitted;
154 UInt inheritable;
155} vki_cap_user_data_t;
156
157
158/* "Byrial Jensen" <byrial@image.dk> says:
159 [various] ioctls take a pointer to a "struct
160 termios" but this is another and shorter "struct
161 termios" than the one defined in <termios.h> and used
162 by tcgetattr(3) and tcsetattr(3) and other library
163 functions. GNU libc translate between its library
164 termios and the kernel termios.
165*/
166
167#define VKI_SIZEOF_STRUCT_TERMIOS 36
168
sewardj2f0de322002-03-24 10:17:25 +0000169/* Adam Gundy <arg@cyberscience.com>, 20 Mar 2002, says: */
170#define VKI_SIZEOF_STRUCT_TERMIO 17
171
sewardjde4a1d02002-03-22 01:27:54 +0000172
sewardj2e93c502002-04-12 11:12:52 +0000173/* File descriptor sets, for doing select(). Copied from
174 /usr/src/linux-2.4.9-31/include/linux/posix_types.h
175*/
176/*
177 * This allows for 1024 file descriptors: if NR_OPEN is ever grown
178 * beyond that you'll have to change this too. But 1024 fd's seem to be
179 * enough even for such "real" unices like OSF/1, so hopefully this is
180 * one limit that doesn't have to be changed [again].
181 *
182 * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in
183 * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical
184 * place for them. Solved by having dummy defines in <sys/time.h>.
185 */
186
187/*
188 * Those macros may have been defined in <gnu/types.h>. But we always
189 * use the ones here.
190 */
191#undef VKI_NFDBITS
192#define VKI_NFDBITS (8 * sizeof(unsigned long))
193
194#undef VKI_FD_SETSIZE
195#define VKI_FD_SETSIZE 1024
196
197#undef VKI_FDSET_LONGS
198#define VKI_FDSET_LONGS (VKI_FD_SETSIZE/VKI_NFDBITS)
199
200#undef VKI_FDELT
201#define VKI_FDELT(d) ((d) / VKI_NFDBITS)
202
203#undef VKI_FDMASK
204#define VKI_FDMASK(d) (1UL << ((d) % VKI_NFDBITS))
205
206typedef struct {
207 unsigned long vki_fds_bits [VKI_FDSET_LONGS];
208} vki_fd_set;
209
210
211/* Gawd ...
212 Copied from /usr/src/linux-2.4.9-31/./include/asm-i386/posix_types.h
213*/
214#undef VKI_FD_SET
215#define VKI_FD_SET(fd,fdsetp) \
216 __asm__ __volatile__("btsl %1,%0": \
217 "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd)))
218
219#undef VKI_FD_CLR
220#define VKI_FD_CLR(fd,fdsetp) \
221 __asm__ __volatile__("btrl %1,%0": \
222 "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd)))
223
224#undef VKI_FD_ISSET
225#define VKI_FD_ISSET(fd,fdsetp) (__extension__ ({ \
226 unsigned char __result; \
227 __asm__ __volatile__("btl %1,%2 ; setb %0" \
228 :"=q" (__result) :"r" ((int) (fd)), \
229 "m" (*(vki_fd_set *) (fdsetp))); \
230 __result; }))
231
232#undef VKI_FD_ZERO
233#define VKI_FD_ZERO(fdsetp) \
234do { \
235 int __d0, __d1; \
236 __asm__ __volatile__("cld ; rep ; stosl" \
237 :"=m" (*(vki_fd_set *) (fdsetp)), \
238 "=&c" (__d0), "=&D" (__d1) \
239 :"a" (0), "1" (VKI_FDSET_LONGS), \
240 "2" ((vki_fd_set *) (fdsetp)) : "memory"); \
241} while (0)
242
243
244
245/*
246./include/asm-i386/posix_types.h:typedef long __kernel_suseconds_t;
247./include/linux/types.h:typedef __kernel_suseconds_t suseconds_t;
248
249./include/asm-i386/posix_types.h:typedef long __kernel_time_t;
250./include/linux/types.h:typedef __kernel_time_t time_t;
251*/
252
253struct vki_timeval {
254 /* time_t */ long tv_sec; /* seconds */
255 /* suseconds_t */ long tv_usec; /* microseconds */
256};
257
258
259
260/* For fcntl on fds ..
261 from ./include/asm-i386/fcntl.h */
262#define VKI_F_GETFL 3 /* get file->f_flags */
263#define VKI_F_SETFL 4 /* set file->f_flags */
264
265#define VKI_O_NONBLOCK 04000
266
267/* For nanosleep ...
268 from ./include/linux/time.h */
269struct vki_timespec {
270 /* time_t */ long tv_sec; /* seconds */
271 long tv_nsec; /* nanoseconds */
272};
273
274
sewardjde4a1d02002-03-22 01:27:54 +0000275#endif /* ndef __VG_KERNELIFACE_H */
276
277/*--------------------------------------------------------------------*/
278/*--- end vg_kerneliface.h ---*/
279/*--------------------------------------------------------------------*/