blob: 778457171ab64069579049a48521178205471007 [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/*
njnc9539842002-10-02 13:26:35 +00009 This file is part of Valgrind, an extensible x86 protected-mode
10 emulator for monitoring program execution on x86-Unixes.
sewardjde4a1d02002-03-22 01:27:54 +000011
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
njn25e49d8e72002-09-23 09:36:25 +000030 The GNU General Public License is contained in the file COPYING.
sewardjde4a1d02002-03-22 01:27:54 +000031*/
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
sewardjb48e5002002-05-13 00:16:03 +000074
sewardjde4a1d02002-03-22 01:27:54 +000075typedef
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
sewardj2342c972002-05-22 23:34:20 +000093/* sigaltstack controls */
94#define VKI_SS_ONSTACK 1
95#define VKI_SS_DISABLE 2
96
97#define VKI_MINSIGSTKSZ 2048
98#define VKI_SIGSTKSZ 8192
99
sewardjb48e5002002-05-13 00:16:03 +0000100
101
sewardjde4a1d02002-03-22 01:27:54 +0000102#define VKI_SIG_BLOCK 0 /* for blocking signals */
103#define VKI_SIG_UNBLOCK 1 /* for unblocking signals */
104#define VKI_SIG_SETMASK 2 /* for setting the signal mask */
105
106#define VKI_SIG_DFL ((void*)0) /* default signal handling */
107#define VKI_SIG_IGN ((void*)1) /* ignore signal */
108#define VKI_SIG_ERR ((void*)-1) /* error return from signal */
109
110#define VKI_SA_ONSTACK 0x08000000
111#define VKI_SA_RESTART 0x10000000
sewardjde4a1d02002-03-22 01:27:54 +0000112#define VKI_SA_NOCLDSTOP 0x00000001
sewardj018f7622002-05-15 21:13:39 +0000113#define VKI_SA_RESETHAND 0x80000000
114#define VKI_SA_ONESHOT VKI_SA_RESETHAND
115#define VKI_SA_NODEFER 0x40000000
116#define VKI_SA_NOMASK VKI_SA_NODEFER
117#if 0
sewardjde4a1d02002-03-22 01:27:54 +0000118#define VKI_SA_NOCLDWAIT 0x00000002 /* not supported yet */
119#define VKI_SA_SIGINFO 0x00000004
sewardjde4a1d02002-03-22 01:27:54 +0000120#define VKI_SA_INTERRUPT 0x20000000 /* dummy -- ignored */
121#define VKI_SA_RESTORER 0x04000000
122#endif
123
sewardjde4a1d02002-03-22 01:27:54 +0000124#define VKI_SIGSEGV 11
125#define VKI_SIGBUS 7
126#define VKI_SIGILL 4
127#define VKI_SIGFPE 8
128#define VKI_SIGKILL 9
sewardjde4a1d02002-03-22 01:27:54 +0000129#define VKI_SIGSTOP 19
130#define VKI_SIGTERM 15
sewardj033e81f2002-04-25 01:29:35 +0000131#define VKI_SIGUSR1 10
sewardjde4a1d02002-03-22 01:27:54 +0000132
sewardj64039bb2002-06-03 00:58:18 +0000133/* The following are copied from include/asm-i386/mman.h .*/
sewardjde4a1d02002-03-22 01:27:54 +0000134
135#define VKI_PROT_READ 0x1 /* Page can be read. */
136#define VKI_PROT_WRITE 0x2 /* Page can be written. */
137#define VKI_PROT_EXEC 0x4 /* Page can be executed. */
138#define VKI_MAP_ANONYMOUS 0x20 /* Don't use a file. */
139#define VKI_MAP_PRIVATE 0x02 /* Changes are private. */
sewardj64039bb2002-06-03 00:58:18 +0000140#define VKI_MAP_FIXED 0x10 /* Interpret addr exactly */
sewardjde4a1d02002-03-22 01:27:54 +0000141
njn25e49d8e72002-09-23 09:36:25 +0000142/* Copied from linux-2.4.19/include/asm-i386/fcntl.h */
143
sewardjf912dfc2002-11-13 21:51:10 +0000144#define VKI_O_ACCMODE 0003
njn25e49d8e72002-09-23 09:36:25 +0000145#define VKI_O_RDONLY 00
146#define VKI_O_WRONLY 01
147#define VKI_O_RDWR 02
148#define VKI_O_CREAT 0100 /* not fcntl */
149#define VKI_O_EXCL 0200 /* not fcntl */
150#define VKI_O_TRUNC 01000 /* not fcntl */
151#define VKI_O_APPEND 02000
152#define VKI_O_NONBLOCK 04000
153#define VKI_O_SYNC 010000
154#define VKI_FASYNC 020000 /* fcntl, for BSD compatibility */
155#define VKI_O_DIRECT 040000 /* direct disk access hint */
156#define VKI_O_LARGEFILE 0100000
157#define VKI_O_DIRECTORY 0200000 /* must be a directory */
158#define VKI_O_NOFOLLOW 0400000 /* don't follow links */
159
160/* Copied from linux-2.4.19/include/linux/stat.h */
161
162#define VKI_S_IRWXU 00700
163#define VKI_S_IRUSR 00400
164#define VKI_S_IWUSR 00200
165#define VKI_S_IXUSR 00100
166
167#define VKI_S_IRWXG 00070
168#define VKI_S_IRGRP 00040
169#define VKI_S_IWGRP 00020
170#define VKI_S_IXGRP 00010
171
172#define VKI_S_IRWXO 00007
173#define VKI_S_IROTH 00004
174#define VKI_S_IWOTH 00002
175#define VKI_S_IXOTH 00001
176
sewardjde4a1d02002-03-22 01:27:54 +0000177
sewardj0ca2a6b2002-03-29 14:02:34 +0000178/* Copied from /usr/src/linux-2.4.9-13/include/asm/errno.h */
179
sewardj2342c972002-05-22 23:34:20 +0000180#define VKI_EPERM 1 /* Operation not permitted */
sewardj77e466c2002-04-14 02:29:29 +0000181#define VKI_EINTR 4 /* Interrupted system call */
sewardj0ca2a6b2002-03-29 14:02:34 +0000182#define VKI_EINVAL 22 /* Invalid argument */
sewardj2e93c502002-04-12 11:12:52 +0000183#define VKI_ENOMEM 12 /* Out of memory */
sewardj018f7622002-05-15 21:13:39 +0000184#define VKI_EFAULT 14 /* Bad address */
185#define VKI_ESRCH 3 /* No such process */
sewardj92a59562002-09-30 00:53:10 +0000186#define VKI_ENOSYS 38 /* Function not implemented */
sewardj2e93c502002-04-12 11:12:52 +0000187
188#define VKI_EWOULDBLOCK VKI_EAGAIN /* Operation would block */
189#define VKI_EAGAIN 11 /* Try again */
sewardj0ca2a6b2002-03-29 14:02:34 +0000190
191
sewardjde4a1d02002-03-22 01:27:54 +0000192/* Gawd ... hack ... */
193
194typedef struct vki__user_cap_header_struct {
195 UInt version;
196 int pid;
197} vki_cap_user_header_t;
198
199typedef struct vki__user_cap_data_struct {
200 UInt effective;
201 UInt permitted;
202 UInt inheritable;
203} vki_cap_user_data_t;
204
205
206/* "Byrial Jensen" <byrial@image.dk> says:
207 [various] ioctls take a pointer to a "struct
208 termios" but this is another and shorter "struct
209 termios" than the one defined in <termios.h> and used
210 by tcgetattr(3) and tcsetattr(3) and other library
211 functions. GNU libc translate between its library
212 termios and the kernel termios.
213*/
214
215#define VKI_SIZEOF_STRUCT_TERMIOS 36
216
sewardj2f0de322002-03-24 10:17:25 +0000217/* Adam Gundy <arg@cyberscience.com>, 20 Mar 2002, says: */
218#define VKI_SIZEOF_STRUCT_TERMIO 17
219
sewardjde4a1d02002-03-22 01:27:54 +0000220
sewardj2e93c502002-04-12 11:12:52 +0000221/* File descriptor sets, for doing select(). Copied from
222 /usr/src/linux-2.4.9-31/include/linux/posix_types.h
223*/
224/*
225 * This allows for 1024 file descriptors: if NR_OPEN is ever grown
226 * beyond that you'll have to change this too. But 1024 fd's seem to be
227 * enough even for such "real" unices like OSF/1, so hopefully this is
228 * one limit that doesn't have to be changed [again].
229 *
230 * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in
231 * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical
232 * place for them. Solved by having dummy defines in <sys/time.h>.
233 */
234
235/*
236 * Those macros may have been defined in <gnu/types.h>. But we always
237 * use the ones here.
238 */
239#undef VKI_NFDBITS
240#define VKI_NFDBITS (8 * sizeof(unsigned long))
241
242#undef VKI_FD_SETSIZE
243#define VKI_FD_SETSIZE 1024
244
245#undef VKI_FDSET_LONGS
246#define VKI_FDSET_LONGS (VKI_FD_SETSIZE/VKI_NFDBITS)
247
248#undef VKI_FDELT
249#define VKI_FDELT(d) ((d) / VKI_NFDBITS)
250
251#undef VKI_FDMASK
252#define VKI_FDMASK(d) (1UL << ((d) % VKI_NFDBITS))
253
254typedef struct {
255 unsigned long vki_fds_bits [VKI_FDSET_LONGS];
256} vki_fd_set;
257
258
259/* Gawd ...
260 Copied from /usr/src/linux-2.4.9-31/./include/asm-i386/posix_types.h
261*/
262#undef VKI_FD_SET
263#define VKI_FD_SET(fd,fdsetp) \
264 __asm__ __volatile__("btsl %1,%0": \
265 "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd)))
266
267#undef VKI_FD_CLR
268#define VKI_FD_CLR(fd,fdsetp) \
269 __asm__ __volatile__("btrl %1,%0": \
270 "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd)))
271
272#undef VKI_FD_ISSET
273#define VKI_FD_ISSET(fd,fdsetp) (__extension__ ({ \
274 unsigned char __result; \
275 __asm__ __volatile__("btl %1,%2 ; setb %0" \
276 :"=q" (__result) :"r" ((int) (fd)), \
277 "m" (*(vki_fd_set *) (fdsetp))); \
278 __result; }))
279
280#undef VKI_FD_ZERO
281#define VKI_FD_ZERO(fdsetp) \
282do { \
283 int __d0, __d1; \
284 __asm__ __volatile__("cld ; rep ; stosl" \
285 :"=m" (*(vki_fd_set *) (fdsetp)), \
286 "=&c" (__d0), "=&D" (__d1) \
287 :"a" (0), "1" (VKI_FDSET_LONGS), \
288 "2" ((vki_fd_set *) (fdsetp)) : "memory"); \
289} while (0)
290
291
292
293/*
294./include/asm-i386/posix_types.h:typedef long __kernel_suseconds_t;
295./include/linux/types.h:typedef __kernel_suseconds_t suseconds_t;
296
297./include/asm-i386/posix_types.h:typedef long __kernel_time_t;
298./include/linux/types.h:typedef __kernel_time_t time_t;
299*/
300
301struct vki_timeval {
302 /* time_t */ long tv_sec; /* seconds */
303 /* suseconds_t */ long tv_usec; /* microseconds */
304};
305
306
307
308/* For fcntl on fds ..
309 from ./include/asm-i386/fcntl.h */
310#define VKI_F_GETFL 3 /* get file->f_flags */
311#define VKI_F_SETFL 4 /* set file->f_flags */
312
313#define VKI_O_NONBLOCK 04000
314
315/* For nanosleep ...
316 from ./include/linux/time.h */
317struct vki_timespec {
318 /* time_t */ long tv_sec; /* seconds */
319 long tv_nsec; /* nanoseconds */
320};
321
322
sewardjb3586202002-05-09 17:38:13 +0000323/* STAT stuff
324 from /usr/src/linux-2.4.9-31/include/asm-i386/stat.h */
325struct vki_stat {
326 unsigned short st_dev;
327 unsigned short __pad1;
328 unsigned long st_ino;
329 unsigned short st_mode;
330 unsigned short st_nlink;
331 unsigned short st_uid;
332 unsigned short st_gid;
333 unsigned short st_rdev;
334 unsigned short __pad2;
335 unsigned long st_size;
336 unsigned long st_blksize;
337 unsigned long st_blocks;
338 unsigned long st_atime;
339 unsigned long __unused1;
340 unsigned long st_mtime;
341 unsigned long __unused2;
342 unsigned long st_ctime;
343 unsigned long __unused3;
344 unsigned long __unused4;
345 unsigned long __unused5;
346};
347
348
sewardjb48e5002002-05-13 00:16:03 +0000349/* To do with the ELF frame constructed by the kernel on a process'
350 stack just before it transfers control to the program's interpreter
351 (to use the ELF parlance).
sewardja1679dd2002-05-10 22:31:40 +0000352 Constants from /usr/src/linux-2.4.9-31/include/linux/elf.h
353 Logic from /usr/src/linux-2.4.9-31/fs/binfmt_elf.c
354 and its counterpart in the 2.2.14 kernel sources
sewardjb48e5002002-05-13 00:16:03 +0000355 in Red Hat 6.2. */
sewardja1679dd2002-05-10 22:31:40 +0000356#define VKI_AT_CLKTCK 17 /* frequency at which times() increments */
357#define VKI_AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
358#define VKI_AT_BASE 7 /* base address of interpreter */
359#define VKI_AT_PAGESZ 6 /* system page size */
360#define VKI_AT_PHNUM 5 /* number of program headers */
361#define VKI_AT_PHENT 4 /* size of program header entry */
362#define VKI_AT_PHDR 3 /* program headers for program */
sewardjce61d052002-07-25 00:49:51 +0000363#define VKI_AT_USER_AUX_SEGMENT 23 /* tell glibc what address segment
364 0x3B points to. (Needed for
365 Red Hat Limbo, 7.3.92) */
sewardja1679dd2002-05-10 22:31:40 +0000366
sewardja83005f2002-06-13 16:07:51 +0000367/* Including <linux/module.h> leads to loads of hassle because then we
368 need <asm/atomic.h> sometimes (RedHat 7.3) and that is a
369 kernel-only header which deliberately #errors on gcc-3.1. Mucho
370 hassle considering that we only want to know sizeof(struct module).
371 Hence ...
372
373 #include <stdio.h>
374 #include <asm/atomic.h>
375 #include <linux/module.h>
376
377 int main ( void )
378 {
379 printf ("sizeof(struct module) = %d\n", sizeof(struct module) );
380 return 0;
381 }
382*/
383
384#define VKI_SIZEOF_STRUCT_MODULE 96
sewardja1679dd2002-05-10 22:31:40 +0000385
sewardj92a59562002-09-30 00:53:10 +0000386
387/* This is the structure passed to the modify_ldt syscall. Just so as
388 to confuse and annoy everyone, this is _not_ the same as an
389 VgLdtEntry and has to be translated into such. The logic for doing
390 so, in vg_ldt.c, is copied from the kernel sources. */
391/*
392 * ldt.h
393 *
394 * Definitions of structures used with the modify_ldt system call.
395 */
396typedef struct vki_modify_ldt_ldt_s {
397 unsigned int entry_number;
398 unsigned long base_addr;
399 unsigned int limit;
400 unsigned int seg_32bit:1;
401 unsigned int contents:2;
402 unsigned int read_exec_only:1;
403 unsigned int limit_in_pages:1;
404 unsigned int seg_not_present:1;
405 unsigned int useable:1;
406} vki_modify_ldt_t;
407
408#define VKI_MODIFY_LDT_CONTENTS_DATA 0
409#define VKI_MODIFY_LDT_CONTENTS_STACK 1
410#define VKI_MODIFY_LDT_CONTENTS_CODE 2
411
412
413
sewardjde4a1d02002-03-22 01:27:54 +0000414#endif /* ndef __VG_KERNELIFACE_H */
415
416/*--------------------------------------------------------------------*/
417/*--- end vg_kerneliface.h ---*/
418/*--------------------------------------------------------------------*/