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