sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 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 | |
| 69 | typedef |
| 70 | struct { |
| 71 | UInt ws[VKI_KNSIG_WORDS]; |
| 72 | } |
| 73 | vki_ksigset_t; |
| 74 | |
| 75 | typedef |
| 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 | |
| 84 | typedef |
| 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 | |
sewardj | 0ca2a6b | 2002-03-29 14:02:34 +0000 | [diff] [blame] | 135 | /* Copied from /usr/src/linux-2.4.9-13/include/asm/errno.h */ |
| 136 | |
sewardj | 77e466c | 2002-04-14 02:29:29 +0000 | [diff] [blame] | 137 | #define VKI_EINTR 4 /* Interrupted system call */ |
sewardj | 0ca2a6b | 2002-03-29 14:02:34 +0000 | [diff] [blame] | 138 | #define VKI_EINVAL 22 /* Invalid argument */ |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 139 | #define VKI_ENOMEM 12 /* Out of memory */ |
| 140 | |
| 141 | #define VKI_EWOULDBLOCK VKI_EAGAIN /* Operation would block */ |
| 142 | #define VKI_EAGAIN 11 /* Try again */ |
sewardj | 0ca2a6b | 2002-03-29 14:02:34 +0000 | [diff] [blame] | 143 | |
| 144 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 145 | /* Gawd ... hack ... */ |
| 146 | |
| 147 | typedef struct vki__user_cap_header_struct { |
| 148 | UInt version; |
| 149 | int pid; |
| 150 | } vki_cap_user_header_t; |
| 151 | |
| 152 | typedef struct vki__user_cap_data_struct { |
| 153 | UInt effective; |
| 154 | UInt permitted; |
| 155 | UInt inheritable; |
| 156 | } vki_cap_user_data_t; |
| 157 | |
| 158 | |
| 159 | /* "Byrial Jensen" <byrial@image.dk> says: |
| 160 | [various] ioctls take a pointer to a "struct |
| 161 | termios" but this is another and shorter "struct |
| 162 | termios" than the one defined in <termios.h> and used |
| 163 | by tcgetattr(3) and tcsetattr(3) and other library |
| 164 | functions. GNU libc translate between its library |
| 165 | termios and the kernel termios. |
| 166 | */ |
| 167 | |
| 168 | #define VKI_SIZEOF_STRUCT_TERMIOS 36 |
| 169 | |
sewardj | 2f0de32 | 2002-03-24 10:17:25 +0000 | [diff] [blame] | 170 | /* Adam Gundy <arg@cyberscience.com>, 20 Mar 2002, says: */ |
| 171 | #define VKI_SIZEOF_STRUCT_TERMIO 17 |
| 172 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 173 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 174 | /* File descriptor sets, for doing select(). Copied from |
| 175 | /usr/src/linux-2.4.9-31/include/linux/posix_types.h |
| 176 | */ |
| 177 | /* |
| 178 | * This allows for 1024 file descriptors: if NR_OPEN is ever grown |
| 179 | * beyond that you'll have to change this too. But 1024 fd's seem to be |
| 180 | * enough even for such "real" unices like OSF/1, so hopefully this is |
| 181 | * one limit that doesn't have to be changed [again]. |
| 182 | * |
| 183 | * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in |
| 184 | * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical |
| 185 | * place for them. Solved by having dummy defines in <sys/time.h>. |
| 186 | */ |
| 187 | |
| 188 | /* |
| 189 | * Those macros may have been defined in <gnu/types.h>. But we always |
| 190 | * use the ones here. |
| 191 | */ |
| 192 | #undef VKI_NFDBITS |
| 193 | #define VKI_NFDBITS (8 * sizeof(unsigned long)) |
| 194 | |
| 195 | #undef VKI_FD_SETSIZE |
| 196 | #define VKI_FD_SETSIZE 1024 |
| 197 | |
| 198 | #undef VKI_FDSET_LONGS |
| 199 | #define VKI_FDSET_LONGS (VKI_FD_SETSIZE/VKI_NFDBITS) |
| 200 | |
| 201 | #undef VKI_FDELT |
| 202 | #define VKI_FDELT(d) ((d) / VKI_NFDBITS) |
| 203 | |
| 204 | #undef VKI_FDMASK |
| 205 | #define VKI_FDMASK(d) (1UL << ((d) % VKI_NFDBITS)) |
| 206 | |
| 207 | typedef struct { |
| 208 | unsigned long vki_fds_bits [VKI_FDSET_LONGS]; |
| 209 | } vki_fd_set; |
| 210 | |
| 211 | |
| 212 | /* Gawd ... |
| 213 | Copied from /usr/src/linux-2.4.9-31/./include/asm-i386/posix_types.h |
| 214 | */ |
| 215 | #undef VKI_FD_SET |
| 216 | #define VKI_FD_SET(fd,fdsetp) \ |
| 217 | __asm__ __volatile__("btsl %1,%0": \ |
| 218 | "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd))) |
| 219 | |
| 220 | #undef VKI_FD_CLR |
| 221 | #define VKI_FD_CLR(fd,fdsetp) \ |
| 222 | __asm__ __volatile__("btrl %1,%0": \ |
| 223 | "=m" (*(vki_fd_set *) (fdsetp)):"r" ((int) (fd))) |
| 224 | |
| 225 | #undef VKI_FD_ISSET |
| 226 | #define VKI_FD_ISSET(fd,fdsetp) (__extension__ ({ \ |
| 227 | unsigned char __result; \ |
| 228 | __asm__ __volatile__("btl %1,%2 ; setb %0" \ |
| 229 | :"=q" (__result) :"r" ((int) (fd)), \ |
| 230 | "m" (*(vki_fd_set *) (fdsetp))); \ |
| 231 | __result; })) |
| 232 | |
| 233 | #undef VKI_FD_ZERO |
| 234 | #define VKI_FD_ZERO(fdsetp) \ |
| 235 | do { \ |
| 236 | int __d0, __d1; \ |
| 237 | __asm__ __volatile__("cld ; rep ; stosl" \ |
| 238 | :"=m" (*(vki_fd_set *) (fdsetp)), \ |
| 239 | "=&c" (__d0), "=&D" (__d1) \ |
| 240 | :"a" (0), "1" (VKI_FDSET_LONGS), \ |
| 241 | "2" ((vki_fd_set *) (fdsetp)) : "memory"); \ |
| 242 | } while (0) |
| 243 | |
| 244 | |
| 245 | |
| 246 | /* |
| 247 | ./include/asm-i386/posix_types.h:typedef long __kernel_suseconds_t; |
| 248 | ./include/linux/types.h:typedef __kernel_suseconds_t suseconds_t; |
| 249 | |
| 250 | ./include/asm-i386/posix_types.h:typedef long __kernel_time_t; |
| 251 | ./include/linux/types.h:typedef __kernel_time_t time_t; |
| 252 | */ |
| 253 | |
| 254 | struct vki_timeval { |
| 255 | /* time_t */ long tv_sec; /* seconds */ |
| 256 | /* suseconds_t */ long tv_usec; /* microseconds */ |
| 257 | }; |
| 258 | |
| 259 | |
| 260 | |
| 261 | /* For fcntl on fds .. |
| 262 | from ./include/asm-i386/fcntl.h */ |
| 263 | #define VKI_F_GETFL 3 /* get file->f_flags */ |
| 264 | #define VKI_F_SETFL 4 /* set file->f_flags */ |
| 265 | |
| 266 | #define VKI_O_NONBLOCK 04000 |
| 267 | |
| 268 | /* For nanosleep ... |
| 269 | from ./include/linux/time.h */ |
| 270 | struct vki_timespec { |
| 271 | /* time_t */ long tv_sec; /* seconds */ |
| 272 | long tv_nsec; /* nanoseconds */ |
| 273 | }; |
| 274 | |
| 275 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 276 | #endif /* ndef __VG_KERNELIFACE_H */ |
| 277 | |
| 278 | /*--------------------------------------------------------------------*/ |
| 279 | /*--- end vg_kerneliface.h ---*/ |
| 280 | /*--------------------------------------------------------------------*/ |