sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 3 | /*--- Wrappers for generic Unix system calls syswrap-generic.c ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 11 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_core_basics.h" |
| 32 | #include "pub_core_threadstate.h" |
njn | 899ce73 | 2005-06-21 00:28:11 +0000 | [diff] [blame] | 33 | #include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :( |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 34 | #include "pub_core_aspacemgr.h" |
njn | 899ce73 | 2005-06-21 00:28:11 +0000 | [diff] [blame] | 35 | #include "pub_core_debuglog.h" |
njn | 0087c50 | 2005-07-01 04:15:36 +0000 | [diff] [blame] | 36 | #include "pub_core_errormgr.h" |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 37 | #include "pub_core_libcbase.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 38 | #include "pub_core_libcassert.h" |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 39 | #include "pub_core_libcfile.h" |
njn | f4c5016 | 2005-06-20 14:18:12 +0000 | [diff] [blame] | 40 | #include "pub_core_libcmman.h" // For VG_(mmap), VG_(munmap)() |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 41 | #include "pub_core_libcprint.h" |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 42 | #include "pub_core_libcproc.h" |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 43 | #include "pub_core_libcsignal.h" |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 44 | #include "pub_core_main.h" |
njn | af1d7df | 2005-06-11 01:31:52 +0000 | [diff] [blame] | 45 | #include "pub_core_mallocfree.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 46 | #include "pub_core_options.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 47 | #include "pub_core_scheduler.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 48 | #include "pub_core_signals.h" |
njn | 419bbcb | 2005-06-21 03:52:49 +0000 | [diff] [blame] | 49 | #include "pub_core_stacktrace.h" // For VG_(get_and_pp_StackTrace)() |
njn | 9abd608 | 2005-06-17 21:31:45 +0000 | [diff] [blame] | 50 | #include "pub_core_syscall.h" |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 51 | #include "pub_core_syswrap.h" |
njn | 419bbcb | 2005-06-21 03:52:49 +0000 | [diff] [blame] | 52 | #include "pub_core_tooliface.h" |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 53 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 54 | #include "priv_types_n_macros.h" |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 55 | #include "priv_syswrap-generic.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 56 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 57 | #include "vki_unistd.h" /* for the __NR_* constants */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 58 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 59 | |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 60 | /* return true if address range entirely contained within client |
| 61 | address space */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 62 | Bool ML_(valid_client_addr)(Addr start, SizeT size, ThreadId tid, |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 63 | const Char *syscallname) |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 64 | { |
| 65 | Addr end = start+size; |
| 66 | Addr cl_base = VG_(client_base); |
| 67 | Bool ret; |
| 68 | |
| 69 | if (size == 0) |
| 70 | return True; |
| 71 | |
sewardj | 16063e6 | 2005-03-15 23:29:13 +0000 | [diff] [blame] | 72 | if (0 && cl_base < 0x10000) |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 73 | cl_base = 0x10000; |
| 74 | |
| 75 | ret = |
| 76 | (end >= start) && |
| 77 | start >= cl_base && start < VG_(client_end) && |
| 78 | (end <= VG_(client_end)); |
| 79 | |
| 80 | if (0) |
| 81 | VG_(printf)("%s: test=%p-%p client=%p-%p ret=%d\n", |
nethercote | 1543adf | 2004-10-25 15:43:21 +0000 | [diff] [blame] | 82 | syscallname, start, end, cl_base, VG_(client_end), ret); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 83 | |
nethercote | 1543adf | 2004-10-25 15:43:21 +0000 | [diff] [blame] | 84 | if (!ret && syscallname != NULL) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 85 | VG_(message)(Vg_UserMsg, "Warning: client syscall %s tried " |
| 86 | "to modify addresses %p-%p", |
| 87 | syscallname, start, end); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 88 | |
| 89 | if (VG_(clo_verbosity) > 1) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 90 | VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size)); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 97 | Bool ML_(client_signal_OK)(Int sigNo) |
njn | 419bbcb | 2005-06-21 03:52:49 +0000 | [diff] [blame] | 98 | { |
| 99 | /* signal 0 is OK for kill */ |
njn | 351d006 | 2005-06-21 22:23:59 +0000 | [diff] [blame] | 100 | Bool ret = sigNo >= 0 && sigNo <= VG_SIGVGRTUSERMAX; |
njn | 419bbcb | 2005-06-21 03:52:49 +0000 | [diff] [blame] | 101 | |
| 102 | //VG_(printf)("client_signal_OK(%d) -> %d\n", sigNo, ret); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 107 | /* --------------------------------------------------------------------- |
nethercote | 27ea8bc | 2004-07-10 17:21:14 +0000 | [diff] [blame] | 108 | Doing mmap, mremap |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 109 | ------------------------------------------------------------------ */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 110 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 111 | // Nb: this isn't done as precisely as possible, but it seems that programs |
| 112 | // are usually sufficiently well-behaved that the more obscure corner cases |
| 113 | // aren't important. Various comments in the few functions below give more |
| 114 | // details... njn 2002-Sep-17 |
| 115 | |
| 116 | /* AFAICT from kernel sources (mm/mprotect.c) and general experimentation, |
| 117 | munmap, mprotect (and mremap??) work at the page level. So addresses |
| 118 | and lengths must be adjusted for this. */ |
| 119 | |
| 120 | /* Mash around start and length so that the area exactly covers |
| 121 | an integral number of pages. If we don't do that, memcheck's |
| 122 | idea of addressible memory diverges from that of the |
| 123 | kernel's, which causes the leak detector to crash. */ |
| 124 | static |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 125 | void mash_addr_and_len( Addr* a, SizeT* len) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 126 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 127 | Addr ra; |
| 128 | |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 129 | ra = VG_PGROUNDDN(*a); |
| 130 | *len = VG_PGROUNDUP(*a + *len) - ra; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 131 | *a = ra; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 132 | } |
| 133 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 134 | void ML_(mmap_segment) ( Addr a, SizeT len, UInt prot, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 135 | UInt mm_flags, Int fd, ULong offset ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 136 | { |
sewardj | 40f8ebe | 2002-10-23 21:46:13 +0000 | [diff] [blame] | 137 | Bool rr, ww, xx; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 138 | UInt flags; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 139 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 140 | flags = SF_MMAP; |
| 141 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 142 | if (!(mm_flags & VKI_MAP_PRIVATE)) |
| 143 | flags |= SF_SHARED; |
| 144 | |
| 145 | if (fd != -1) |
| 146 | flags |= SF_FILE; |
| 147 | |
| 148 | VG_(map_fd_segment)(a, len, prot, flags, fd, offset, NULL); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 149 | |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 150 | rr = prot & VKI_PROT_READ; |
| 151 | ww = prot & VKI_PROT_WRITE; |
| 152 | xx = prot & VKI_PROT_EXEC; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 153 | |
sewardj | 40f8ebe | 2002-10-23 21:46:13 +0000 | [diff] [blame] | 154 | VG_TRACK( new_mem_mmap, a, len, rr, ww, xx ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 155 | } |
| 156 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 157 | static |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 158 | SysRes mremap_segment ( Addr old_addr, SizeT old_size, |
| 159 | Addr new_addr, SizeT new_size, |
| 160 | UInt flags, ThreadId tid) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 161 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 162 | SysRes ret; |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 163 | Segment *seg, *next; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 164 | |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 165 | old_size = VG_PGROUNDUP(old_size); |
| 166 | new_size = VG_PGROUNDUP(new_size); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 167 | |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 168 | if (VG_PGROUNDDN(old_addr) != old_addr) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 169 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 170 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 171 | if (!ML_(valid_client_addr)(old_addr, old_size, tid, "mremap(old_addr)")) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 172 | return VG_(mk_SysRes_Error)( VKI_EFAULT ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 173 | |
| 174 | /* fixed at the current address means we don't move it */ |
| 175 | if ((flags & VKI_MREMAP_FIXED) && (old_addr == new_addr)) |
| 176 | flags &= ~(VKI_MREMAP_FIXED|VKI_MREMAP_MAYMOVE); |
| 177 | |
| 178 | if (flags & VKI_MREMAP_FIXED) { |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 179 | if (VG_PGROUNDDN(new_addr) != new_addr) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 180 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 181 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 182 | if (!ML_(valid_client_addr)(new_addr, new_size, tid, "mremap(new_addr)")) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 183 | return VG_(mk_SysRes_Error)( VKI_ENOMEM ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 184 | |
| 185 | /* check for overlaps */ |
| 186 | if ((old_addr < (new_addr+new_size) && |
| 187 | (old_addr+old_size) > new_addr) || |
| 188 | (new_addr < (old_addr+new_size) && |
| 189 | (new_addr+new_size) > old_addr)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 190 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 191 | } |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 192 | |
| 193 | /* Do nothing */ |
| 194 | if (!(flags & VKI_MREMAP_FIXED) && new_size == old_size) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 195 | return VG_(mk_SysRes_Success)( old_addr ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 196 | |
| 197 | seg = VG_(find_segment)(old_addr); |
| 198 | |
| 199 | /* range must be contained within segment */ |
| 200 | if (seg == NULL || !VG_(seg_contains)(seg, old_addr, old_size)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 201 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 202 | |
sewardj | 1024cf7 | 2005-02-28 14:39:21 +0000 | [diff] [blame] | 203 | next = VG_(find_segment_above_mapped)(old_addr); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 204 | |
| 205 | if (0) |
| 206 | VG_(printf)("mremap: old_addr+new_size=%p next->addr=%p flags=%d\n", |
| 207 | old_addr+new_size, next->addr, flags); |
| 208 | |
| 209 | if ((flags & VKI_MREMAP_FIXED) || |
| 210 | (next != NULL && (old_addr+new_size) > next->addr)) { |
| 211 | /* we're moving the block */ |
| 212 | Addr a; |
| 213 | |
| 214 | if ((flags & (VKI_MREMAP_FIXED|VKI_MREMAP_MAYMOVE)) == 0) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 215 | /* not allowed to move */ |
| 216 | return VG_(mk_SysRes_Error)( VKI_ENOMEM ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 217 | |
| 218 | if ((flags & VKI_MREMAP_FIXED) == 0) |
| 219 | new_addr = 0; |
| 220 | |
| 221 | a = VG_(find_map_space)(new_addr, new_size, True); |
| 222 | |
| 223 | if ((flags & VKI_MREMAP_FIXED) && a != new_addr) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 224 | /* didn't find the place we wanted */ |
| 225 | return VG_(mk_SysRes_Error)( VKI_ENOMEM ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 226 | |
| 227 | new_addr = a; |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 228 | |
| 229 | /* we've nailed down the location */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 230 | flags |= VKI_MREMAP_FIXED|VKI_MREMAP_MAYMOVE; |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 231 | |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 232 | ret = VG_(do_syscall5)(__NR_mremap, old_addr, old_size, new_size, |
| 233 | flags, new_addr); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 234 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 235 | if (ret.isError) { |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | VG_TRACK(copy_mem_remap, old_addr, new_addr, |
| 240 | (old_size < new_size) ? old_size : new_size); |
| 241 | |
| 242 | if (new_size > old_size) |
| 243 | VG_TRACK(new_mem_mmap, new_addr+old_size, new_size-old_size, |
| 244 | seg->prot & VKI_PROT_READ, |
| 245 | seg->prot & VKI_PROT_WRITE, |
| 246 | seg->prot & VKI_PROT_EXEC); |
| 247 | VG_TRACK(die_mem_munmap, old_addr, old_size); |
| 248 | |
| 249 | VG_(map_file_segment)(new_addr, new_size, |
| 250 | seg->prot, |
| 251 | seg->flags, |
| 252 | seg->dev, seg->ino, |
| 253 | seg->offset, seg->filename); |
| 254 | |
| 255 | VG_(munmap)((void *)old_addr, old_size); |
| 256 | } else { |
| 257 | /* staying in place */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 258 | ret = VG_(mk_SysRes_Success)( old_addr ); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 259 | |
| 260 | if (new_size < old_size) { |
| 261 | VG_TRACK(die_mem_munmap, old_addr+new_size, old_size-new_size); |
| 262 | VG_(munmap)((void *)(old_addr+new_size), old_size-new_size); |
| 263 | } else { |
| 264 | /* we've nailed down the location */ |
| 265 | flags &= ~VKI_MREMAP_MAYMOVE; |
| 266 | |
| 267 | if (0) |
| 268 | VG_(printf)("mremap: old_addr=%p old_size=%d new_size=%d flags=%d\n", |
| 269 | old_addr, old_size, new_size, flags); |
| 270 | |
njn | ca6fef0 | 2004-11-29 16:49:18 +0000 | [diff] [blame] | 271 | ret = VG_(do_syscall5)(__NR_mremap, old_addr, old_size, new_size, |
| 272 | flags, 0); |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 273 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 274 | if (ret.isError || (!ret.isError && ret.val != old_addr)) |
fitzhardinge | 1a30304 | 2003-12-22 08:48:50 +0000 | [diff] [blame] | 275 | return ret; |
| 276 | |
| 277 | VG_TRACK(new_mem_mmap, old_addr+old_size, new_size-old_size, |
| 278 | seg->prot & VKI_PROT_READ, |
| 279 | seg->prot & VKI_PROT_WRITE, |
| 280 | seg->prot & VKI_PROT_EXEC); |
| 281 | |
| 282 | VG_(map_file_segment)(old_addr+old_size, new_size-old_size, |
| 283 | seg->prot, |
| 284 | seg->flags, |
| 285 | seg->dev, seg->ino, |
| 286 | seg->offset, seg->filename); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return ret; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 294 | /* --------------------------------------------------------------------- |
| 295 | File-descriptor tracking |
| 296 | ------------------------------------------------------------------ */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 297 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 298 | /* One of these is allocated for each open file descriptor. */ |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 299 | typedef struct OpenFd |
| 300 | { |
| 301 | Int fd; /* The file descriptor */ |
| 302 | Char *pathname; /* NULL if not a regular file or unknown */ |
| 303 | ExeContext *where; /* NULL if inherited from parent */ |
| 304 | struct OpenFd *next, *prev; |
| 305 | } OpenFd; |
| 306 | |
| 307 | /* List of allocated file descriptors. */ |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 308 | static OpenFd *allocated_fds; |
| 309 | |
| 310 | /* Count of open file descriptors. */ |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 311 | static int fd_count = 0; |
| 312 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 313 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 314 | /* Note the fact that a file descriptor was just closed. */ |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 315 | static |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 316 | void record_fd_close(ThreadId tid, Int fd) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 317 | { |
| 318 | OpenFd *i = allocated_fds; |
| 319 | |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 320 | if (fd >= VG_(fd_hard_limit)) |
rjwalsh | 02665ba | 2003-12-18 01:48:06 +0000 | [diff] [blame] | 321 | return; /* Valgrind internal */ |
| 322 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 323 | while(i) { |
| 324 | if(i->fd == fd) { |
| 325 | if(i->prev) |
| 326 | i->prev->next = i->next; |
| 327 | else |
| 328 | allocated_fds = i->next; |
| 329 | if(i->next) |
| 330 | i->next->prev = i->prev; |
| 331 | if(i->pathname) |
fitzhardinge | a772847 | 2003-12-16 01:48:38 +0000 | [diff] [blame] | 332 | VG_(arena_free) (VG_AR_CORE, i->pathname); |
| 333 | VG_(arena_free) (VG_AR_CORE, i); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 334 | fd_count--; |
| 335 | break; |
| 336 | } |
| 337 | i = i->next; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* Note the fact that a file descriptor was just opened. If the |
| 342 | tid is -1, this indicates an inherited fd. If the pathname is NULL, |
| 343 | this either indicates a non-standard file (i.e. a pipe or socket or |
| 344 | some such thing) or that we don't know the filename. If the fd is |
| 345 | already open, then we're probably doing a dup2() to an existing fd, |
| 346 | so just overwrite the existing one. */ |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 347 | static void record_fd_open_with_given_name(ThreadId tid, Int fd, char *pathname) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 348 | { |
| 349 | OpenFd *i; |
| 350 | |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 351 | if (fd >= VG_(fd_hard_limit)) |
fitzhardinge | 0e8bfcf | 2003-12-12 07:46:54 +0000 | [diff] [blame] | 352 | return; /* Valgrind internal */ |
| 353 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 354 | /* Check to see if this fd is already open. */ |
| 355 | i = allocated_fds; |
| 356 | while (i) { |
| 357 | if (i->fd == fd) { |
fitzhardinge | a772847 | 2003-12-16 01:48:38 +0000 | [diff] [blame] | 358 | if (i->pathname) VG_(arena_free)(VG_AR_CORE, i->pathname); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | i = i->next; |
| 362 | } |
| 363 | |
| 364 | /* Not already one: allocate an OpenFd */ |
| 365 | if (i == NULL) { |
fitzhardinge | a772847 | 2003-12-16 01:48:38 +0000 | [diff] [blame] | 366 | i = VG_(arena_malloc)(VG_AR_CORE, sizeof(OpenFd)); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 367 | |
| 368 | i->prev = NULL; |
| 369 | i->next = allocated_fds; |
| 370 | if(allocated_fds) allocated_fds->prev = i; |
| 371 | allocated_fds = i; |
| 372 | fd_count++; |
| 373 | } |
| 374 | |
| 375 | i->fd = fd; |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 376 | i->pathname = VG_(arena_strdup)(VG_AR_CORE, pathname); |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 377 | i->where = (tid == -1) ? NULL : VG_(record_ExeContext)(tid); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 378 | } |
| 379 | |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 380 | // Record opening of an fd, and find its name. |
| 381 | static void record_fd_open_named(ThreadId tid, Int fd) |
| 382 | { |
| 383 | static HChar buf[VKI_PATH_MAX]; |
| 384 | Char* name; |
| 385 | if (VG_(resolve_filename)(fd, buf, VKI_PATH_MAX)) |
| 386 | name = buf; |
| 387 | else |
| 388 | name = NULL; |
| 389 | |
| 390 | record_fd_open_with_given_name(tid, fd, name); |
| 391 | } |
| 392 | |
| 393 | // Record opening of a nameless fd. |
| 394 | void ML_(record_fd_open_nameless)(ThreadId tid, Int fd) |
| 395 | { |
| 396 | record_fd_open_with_given_name(tid, fd, NULL); |
| 397 | } |
| 398 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 399 | static |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 400 | Char *unix2name(struct vki_sockaddr_un *sa, UInt len, Char *name) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 401 | { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 402 | if (sa == NULL || len == 0 || sa->sun_path[0] == '\0') { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 403 | VG_(sprintf)(name, "<unknown>"); |
| 404 | } else { |
| 405 | VG_(sprintf)(name, "%s", sa->sun_path); |
| 406 | } |
| 407 | |
| 408 | return name; |
| 409 | } |
| 410 | |
| 411 | static |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 412 | Char *inet2name(struct vki_sockaddr_in *sa, UInt len, Char *name) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 413 | { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 414 | if (sa == NULL || len == 0) { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 415 | VG_(sprintf)(name, "<unknown>"); |
| 416 | } else { |
| 417 | UInt addr = sa->sin_addr.s_addr; |
| 418 | |
| 419 | if (addr == 0) { |
| 420 | VG_(sprintf)(name, "<unbound>"); |
| 421 | } else { |
| 422 | VG_(sprintf)(name, "%u.%u.%u.%u:%u", |
| 423 | addr & 0xFF, (addr>>8) & 0xFF, |
| 424 | (addr>>16) & 0xFF, (addr>>24) & 0xFF, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 425 | vki_ntohs(sa->sin_port)); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | return name; |
| 430 | } |
| 431 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 432 | /* |
| 433 | * Try get some details about a socket. |
| 434 | */ |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 435 | static void |
| 436 | getsockdetails(int fd) |
| 437 | { |
| 438 | union u { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 439 | struct vki_sockaddr a; |
| 440 | struct vki_sockaddr_in in; |
| 441 | struct vki_sockaddr_un un; |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 442 | } laddr; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 443 | UInt llen; |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 444 | |
| 445 | llen = sizeof(laddr); |
| 446 | VG_(memset)(&laddr, 0, llen); |
| 447 | |
| 448 | if(VG_(getsockname)(fd, (struct vki_sockaddr *)&(laddr.a), &llen) != -1) { |
| 449 | switch(laddr.a.sa_family) { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 450 | case VKI_AF_INET: { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 451 | static char lname[32]; |
| 452 | static char pname[32]; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 453 | struct vki_sockaddr_in paddr; |
| 454 | UInt plen = sizeof(struct vki_sockaddr_in); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 455 | |
| 456 | if(VG_(getpeername)(fd, (struct vki_sockaddr *)&paddr, &plen) != -1) { |
| 457 | VG_(message)(Vg_UserMsg, "Open AF_INET socket %d: %s <-> %s", fd, |
| 458 | inet2name(&(laddr.in), llen, lname), |
| 459 | inet2name(&paddr, plen, pname)); |
| 460 | } else { |
| 461 | VG_(message)(Vg_UserMsg, "Open AF_INET socket %d: %s <-> unbound", |
| 462 | fd, inet2name(&(laddr.in), llen, lname)); |
| 463 | } |
| 464 | return; |
| 465 | } |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 466 | case VKI_AF_UNIX: { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 467 | static char lname[256]; |
| 468 | VG_(message)(Vg_UserMsg, "Open AF_UNIX socket %d: %s", fd, |
| 469 | unix2name(&(laddr.un), llen, lname)); |
| 470 | return; |
| 471 | } |
| 472 | default: |
| 473 | VG_(message)(Vg_UserMsg, "Open pf-%d socket %d:", |
| 474 | laddr.a.sa_family, fd); |
| 475 | return; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | VG_(message)(Vg_UserMsg, "Open socket %d:", fd); |
| 480 | } |
| 481 | |
| 482 | |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 483 | /* Dump out a summary, and a more detailed list, of open file descriptors. */ |
| 484 | void VG_(show_open_fds) () |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 485 | { |
| 486 | OpenFd *i = allocated_fds; |
| 487 | |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 488 | VG_(message)(Vg_UserMsg, "FILE DESCRIPTORS: %d open at exit.", fd_count); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 489 | |
| 490 | while(i) { |
| 491 | if(i->pathname) { |
| 492 | VG_(message)(Vg_UserMsg, "Open file descriptor %d: %s", i->fd, |
| 493 | i->pathname); |
| 494 | } else { |
| 495 | int val; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 496 | UInt len = sizeof(val); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 497 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 498 | if (VG_(getsockopt)(i->fd, VKI_SOL_SOCKET, VKI_SO_TYPE, &val, &len) == -1) { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 499 | VG_(message)(Vg_UserMsg, "Open file descriptor %d:", i->fd); |
| 500 | } else { |
| 501 | getsockdetails(i->fd); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if(i->where) { |
| 506 | VG_(pp_ExeContext)(i->where); |
| 507 | VG_(message)(Vg_UserMsg, ""); |
| 508 | } else { |
| 509 | VG_(message)(Vg_UserMsg, " <inherited from parent>"); |
| 510 | VG_(message)(Vg_UserMsg, ""); |
| 511 | } |
| 512 | |
| 513 | i = i->next; |
| 514 | } |
| 515 | |
| 516 | VG_(message)(Vg_UserMsg, ""); |
| 517 | } |
| 518 | |
| 519 | /* If /proc/self/fd doesn't exist for some weird reason (like you've |
| 520 | got a kernel that doesn't have /proc support compiled in), then we |
| 521 | need to find out what file descriptors we inherited from our parent |
| 522 | process the hard way - by checking each fd in turn. */ |
| 523 | |
| 524 | static |
| 525 | void do_hacky_preopened() |
| 526 | { |
| 527 | struct vki_rlimit lim; |
| 528 | unsigned int count; |
| 529 | int i; |
| 530 | |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 531 | if (VG_(getrlimit) (VKI_RLIMIT_NOFILE, &lim) == -1) { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 532 | /* Hmm. getrlimit() failed. Now we're screwed, so just choose |
| 533 | an arbitrarily high number. 1024 happens to be the limit in |
| 534 | the 2.4 kernels. */ |
| 535 | count = 1024; |
| 536 | } else { |
| 537 | count = lim.rlim_cur; |
| 538 | } |
| 539 | |
| 540 | for (i = 0; i < count; i++) |
| 541 | if(VG_(fcntl)(i, VKI_F_GETFL, 0) != -1) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 542 | ML_(record_fd_open_nameless)(-1, i); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* Initialize the list of open file descriptors with the file descriptors |
| 546 | we inherited from out parent process. */ |
| 547 | |
| 548 | void VG_(init_preopened_fds)() |
| 549 | { |
| 550 | int f, ret; |
| 551 | struct vki_dirent d; |
| 552 | |
| 553 | f = VG_(open)("/proc/self/fd", VKI_O_RDONLY, 0); |
| 554 | if(f == -1) { |
| 555 | do_hacky_preopened(); |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | while((ret = VG_(getdents)(f, &d, sizeof(d))) != 0) { |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 560 | if (ret == -1) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 561 | goto out; |
| 562 | |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 563 | if (VG_(strcmp)(d.d_name, ".") && VG_(strcmp)(d.d_name, "..")) { |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 564 | int fno = VG_(atoll)(d.d_name); |
| 565 | |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 566 | if (fno != f) |
| 567 | if (VG_(clo_track_fds)) |
| 568 | record_fd_open_named(-1, fno); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | VG_(lseek)(f, d.d_off, VKI_SEEK_SET); |
| 572 | } |
| 573 | |
| 574 | out: |
| 575 | VG_(close)(f); |
| 576 | } |
| 577 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 578 | static |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 579 | Char *strdupcat ( const Char *s1, const Char *s2, ArenaId aid ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 580 | { |
| 581 | UInt len = VG_(strlen) ( s1 ) + VG_(strlen) ( s2 ) + 1; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 582 | Char *result = VG_(arena_malloc) ( aid, len ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 583 | VG_(strcpy) ( result, s1 ); |
| 584 | VG_(strcat) ( result, s2 ); |
| 585 | return result; |
| 586 | } |
| 587 | |
| 588 | static |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 589 | void pre_mem_read_sendmsg ( ThreadId tid, |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 590 | Char *msg, Addr base, SizeT size ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 591 | { |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 592 | Char *outmsg = strdupcat ( "socketcall.sendmsg", msg, VG_AR_CORE ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 593 | PRE_MEM_READ( outmsg, base, size ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 594 | |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 595 | VG_(arena_free) ( VG_AR_CORE, outmsg ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 599 | void pre_mem_write_recvmsg ( ThreadId tid, |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 600 | Char *msg, Addr base, SizeT size ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 601 | { |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 602 | Char *outmsg = strdupcat ( "socketcall.recvmsg", msg, VG_AR_CORE ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 603 | PRE_MEM_WRITE( outmsg, base, size ); |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 604 | VG_(arena_free) ( VG_AR_CORE, outmsg ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 608 | void post_mem_write_recvmsg ( ThreadId tid, |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 609 | Char *fieldName, Addr base, SizeT size ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 610 | { |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 611 | POST_MEM_WRITE( base, size ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 615 | void msghdr_foreachfield ( |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 616 | ThreadId tid, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 617 | struct vki_msghdr *msg, |
nethercote | 928a5f7 | 2004-11-03 18:10:37 +0000 | [diff] [blame] | 618 | void (*foreach_func)( ThreadId, Char *, Addr, SizeT ) |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 619 | ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 620 | { |
| 621 | if ( !msg ) |
| 622 | return; |
| 623 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 624 | foreach_func ( tid, "(msg)", (Addr)msg, sizeof( struct vki_msghdr ) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 625 | |
| 626 | if ( msg->msg_name ) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 627 | foreach_func ( tid, |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 628 | "(msg.msg_name)", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 629 | (Addr)msg->msg_name, msg->msg_namelen ); |
| 630 | |
| 631 | if ( msg->msg_iov ) { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 632 | struct vki_iovec *iov = msg->msg_iov; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 633 | UInt i; |
| 634 | |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 635 | foreach_func ( tid, |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 636 | "(msg.msg_iov)", |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 637 | (Addr)iov, msg->msg_iovlen * sizeof( struct vki_iovec ) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 638 | |
| 639 | for ( i = 0; i < msg->msg_iovlen; ++i, ++iov ) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 640 | foreach_func ( tid, |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 641 | "(msg.msg_iov[i]", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 642 | (Addr)iov->iov_base, iov->iov_len ); |
| 643 | } |
| 644 | |
| 645 | if ( msg->msg_control ) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 646 | foreach_func ( tid, |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 647 | "(msg.msg_control)", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 648 | (Addr)msg->msg_control, msg->msg_controllen ); |
| 649 | } |
| 650 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 651 | static void check_cmsg_for_fds(ThreadId tid, struct vki_msghdr *msg) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 652 | { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 653 | struct vki_cmsghdr *cm = VKI_CMSG_FIRSTHDR(msg); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 654 | |
| 655 | while (cm) { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 656 | if (cm->cmsg_level == VKI_SOL_SOCKET && |
| 657 | cm->cmsg_type == VKI_SCM_RIGHTS ) { |
| 658 | int *fds = (int *) VKI_CMSG_DATA(cm); |
| 659 | int fdc = (cm->cmsg_len - VKI_CMSG_ALIGN(sizeof(struct vki_cmsghdr))) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 660 | / sizeof(int); |
| 661 | int i; |
| 662 | |
| 663 | for (i = 0; i < fdc; i++) |
| 664 | if(VG_(clo_track_fds)) |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 665 | // XXX: must we check the range on these fds with |
cerion | 7b2c38c | 2005-06-23 07:52:54 +0000 | [diff] [blame] | 666 | // ML_(fd_allowed)()? |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 667 | record_fd_open_named(tid, fds[i]); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 668 | } |
| 669 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 670 | cm = VKI_CMSG_NXTHDR(msg, cm); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 674 | static |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 675 | void pre_mem_read_sockaddr ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 676 | Char *description, |
| 677 | struct vki_sockaddr *sa, UInt salen ) |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 678 | { |
sewardj | ff7c1ab | 2003-02-24 21:55:34 +0000 | [diff] [blame] | 679 | Char *outmsg; |
| 680 | |
| 681 | /* NULL/zero-length sockaddrs are legal */ |
| 682 | if ( sa == NULL || salen == 0 ) return; |
| 683 | |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 684 | outmsg = VG_(arena_malloc) ( VG_AR_CORE, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 685 | VG_(strlen)( description ) + 30 ); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 686 | |
| 687 | VG_(sprintf) ( outmsg, description, ".sa_family" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 688 | PRE_MEM_READ( outmsg, (Addr) &sa->sa_family, sizeof(vki_sa_family_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 689 | |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 690 | switch (sa->sa_family) { |
| 691 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 692 | case VKI_AF_UNIX: |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 693 | VG_(sprintf) ( outmsg, description, ".sun_path" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 694 | PRE_MEM_RASCIIZ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 695 | (Addr) ((struct vki_sockaddr_un *) sa)->sun_path); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 696 | break; |
| 697 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 698 | case VKI_AF_INET: |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 699 | VG_(sprintf) ( outmsg, description, ".sin_port" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 700 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 701 | (Addr) &((struct vki_sockaddr_in *) sa)->sin_port, |
| 702 | sizeof (((struct vki_sockaddr_in *) sa)->sin_port)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 703 | VG_(sprintf) ( outmsg, description, ".sin_addr" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 704 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 705 | (Addr) &((struct vki_sockaddr_in *) sa)->sin_addr, |
| 706 | sizeof (struct vki_in_addr)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 707 | break; |
| 708 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 709 | case VKI_AF_INET6: |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 710 | VG_(sprintf) ( outmsg, description, ".sin6_port" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 711 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 712 | (Addr) &((struct vki_sockaddr_in6 *) sa)->sin6_port, |
| 713 | sizeof (((struct vki_sockaddr_in6 *) sa)->sin6_port)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 714 | VG_(sprintf) ( outmsg, description, ".sin6_flowinfo" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 715 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 716 | (Addr) &((struct vki_sockaddr_in6 *) sa)->sin6_flowinfo, |
| 717 | sizeof (__vki_u32)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 718 | VG_(sprintf) ( outmsg, description, ".sin6_addr" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 719 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 720 | (Addr) &((struct vki_sockaddr_in6 *) sa)->sin6_addr, |
| 721 | sizeof (struct vki_in6_addr)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 722 | VG_(sprintf) ( outmsg, description, ".sin6_scope_id" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 723 | PRE_MEM_READ( outmsg, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 724 | (Addr) &((struct vki_sockaddr_in6 *) sa)->sin6_scope_id, |
| 725 | sizeof (__vki_u32)); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | default: |
| 729 | VG_(sprintf) ( outmsg, description, "" ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 730 | PRE_MEM_READ( outmsg, (Addr) sa, salen ); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 731 | break; |
| 732 | } |
| 733 | |
njn | 9f46df6 | 2005-03-13 18:11:44 +0000 | [diff] [blame] | 734 | VG_(arena_free) ( VG_AR_CORE, outmsg ); |
sewardj | c483e8f | 2002-05-03 21:01:35 +0000 | [diff] [blame] | 735 | } |
| 736 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 737 | /* Dereference a pointer to a UInt. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 738 | static UInt deref_UInt ( ThreadId tid, Addr a, Char* s ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 739 | { |
| 740 | UInt* a_p = (UInt*)a; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 741 | PRE_MEM_READ( s, (Addr)a_p, sizeof(UInt) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 742 | if (a_p == NULL) |
| 743 | return 0; |
| 744 | else |
| 745 | return *a_p; |
| 746 | } |
| 747 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 748 | static |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 749 | void buf_and_len_pre_check( ThreadId tid, Addr buf_p, Addr buflen_p, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 750 | Char* buf_s, Char* buflen_s ) |
| 751 | { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 752 | if (VG_(tdict).track_pre_mem_write) { |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 753 | UInt buflen_in = deref_UInt( tid, buflen_p, buflen_s); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 754 | if (buflen_in > 0) { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 755 | VG_(tdict).track_pre_mem_write( Vg_CoreSysCall, tid, buf_s, buf_p, buflen_in ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | static |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 761 | void buf_and_len_post_check( ThreadId tid, SysRes res, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 762 | Addr buf_p, Addr buflen_p, Char* s ) |
| 763 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 764 | if (!res.isError && VG_(tdict).track_post_mem_write) { |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 765 | UInt buflen_out = deref_UInt( tid, buflen_p, s); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 766 | if (buflen_out > 0 && buf_p != (Addr)NULL) { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 767 | VG_(tdict).track_post_mem_write( Vg_CoreSysCall, tid, buf_p, buflen_out ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /* --------------------------------------------------------------------- |
| 773 | Data seg end, for brk() |
| 774 | ------------------------------------------------------------------ */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 775 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 776 | static Addr do_brk(Addr newbrk) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 777 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 778 | Addr ret = VG_(brk_limit); |
sewardj | e517b80 | 2005-02-16 01:58:51 +0000 | [diff] [blame] | 779 | static const Bool debug = False; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 780 | Segment *seg; |
nethercote | ce47126 | 2004-08-25 13:43:44 +0000 | [diff] [blame] | 781 | Addr current, newaddr; |
| 782 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 783 | |
| 784 | if (debug) |
sewardj | 548be6d | 2005-02-16 01:31:37 +0000 | [diff] [blame] | 785 | VG_(printf)("\ndo_brk: brk_base=%p brk_limit=%p newbrk=%p\n", |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 786 | VG_(brk_base), VG_(brk_limit), newbrk); |
| 787 | |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 788 | # if 0 |
sewardj | e517b80 | 2005-02-16 01:58:51 +0000 | [diff] [blame] | 789 | if (0) show_segments("in_brk"); |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 790 | # endif |
sewardj | 548be6d | 2005-02-16 01:31:37 +0000 | [diff] [blame] | 791 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 792 | if (newbrk < VG_(brk_base) || newbrk >= VG_(client_end)) |
| 793 | return VG_(brk_limit); |
| 794 | |
| 795 | /* brk isn't allowed to grow over anything else */ |
sewardj | 548be6d | 2005-02-16 01:31:37 +0000 | [diff] [blame] | 796 | seg = VG_(find_segment)(VG_(brk_limit) -1); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 797 | |
| 798 | vg_assert(seg != NULL); |
| 799 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 800 | if (0) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 801 | VG_(printf)("brk_limit=%p seg->addr=%p seg->end=%p\n", |
| 802 | VG_(brk_limit), seg->addr, seg->addr+seg->len); |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 803 | vg_assert(VG_(brk_limit) >= seg->addr && VG_(brk_limit) |
| 804 | <= (seg->addr + seg->len)); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 805 | |
sewardj | 79048ce | 2005-02-18 08:28:32 +0000 | [diff] [blame] | 806 | seg = VG_(find_segment_above_mapped)(VG_(brk_limit)-1); |
| 807 | if (0 && seg) |
| 808 | VG_(printf)("NEXT addr = %p\n", seg->addr); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 809 | if (seg != NULL && newbrk > seg->addr) |
| 810 | return VG_(brk_limit); |
| 811 | |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 812 | current = VG_PGROUNDUP(VG_(brk_limit)); |
| 813 | newaddr = VG_PGROUNDUP(newbrk); |
nethercote | ce47126 | 2004-08-25 13:43:44 +0000 | [diff] [blame] | 814 | if (newaddr != current) { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 815 | |
| 816 | /* new brk in a new page - fix the mappings */ |
| 817 | if (newbrk > VG_(brk_limit)) { |
| 818 | |
| 819 | if (debug) |
| 820 | VG_(printf)(" extending brk: current=%p newaddr=%p delta=%d\n", |
| 821 | current, newaddr, newaddr-current); |
| 822 | |
| 823 | if (newaddr == current) { |
| 824 | ret = newbrk; |
nethercote | b4250ae | 2004-07-10 16:50:09 +0000 | [diff] [blame] | 825 | } else if ((void*)-1 != VG_(mmap)((void*)current, newaddr-current, |
| 826 | VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC, |
| 827 | VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS|VKI_MAP_FIXED|VKI_MAP_CLIENT, |
njn | 0ae787c | 2005-06-28 22:14:53 +0000 | [diff] [blame] | 828 | 0, -1, 0)) |
nethercote | b4250ae | 2004-07-10 16:50:09 +0000 | [diff] [blame] | 829 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 830 | ret = newbrk; |
| 831 | } |
| 832 | } else { |
| 833 | vg_assert(newbrk < VG_(brk_limit)); |
| 834 | |
| 835 | if (debug) |
| 836 | VG_(printf)(" shrinking brk: current=%p newaddr=%p delta=%d\n", |
| 837 | current, newaddr, current-newaddr); |
| 838 | |
| 839 | if (newaddr != current) { |
nethercote | e567e70 | 2004-07-10 17:49:17 +0000 | [diff] [blame] | 840 | int res = VG_(munmap)((void *)newaddr, current - newaddr); |
| 841 | vg_assert(0 == res); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 842 | } |
| 843 | ret = newbrk; |
| 844 | } |
| 845 | } else |
| 846 | ret = newbrk; |
| 847 | |
| 848 | VG_(brk_limit) = ret; |
| 849 | |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 854 | /* --------------------------------------------------------------------- |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 855 | Vet file descriptors for sanity |
| 856 | ------------------------------------------------------------------ */ |
| 857 | |
| 858 | /* Return true if we're allowed to use or create this fd */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 859 | Bool ML_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool soft) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 860 | { |
njn | 0087c50 | 2005-07-01 04:15:36 +0000 | [diff] [blame] | 861 | if ((fd < 0 || fd >= VG_(fd_hard_limit) || fd == VG_(clo_log_fd)) && |
| 862 | VG_(showing_core_errors)()) |
| 863 | { |
jseward | d9320a4 | 2003-12-12 06:40:05 +0000 | [diff] [blame] | 864 | VG_(message)(Vg_UserMsg, |
| 865 | "Warning: invalid file descriptor %d in syscall %s()", |
nethercote | 1543adf | 2004-10-25 15:43:21 +0000 | [diff] [blame] | 866 | fd, syscallname); |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 867 | if (fd == VG_(clo_log_fd)) |
jseward | d9320a4 | 2003-12-12 06:40:05 +0000 | [diff] [blame] | 868 | VG_(message)(Vg_UserMsg, |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 869 | " Use --log-fd=<number> to select an alternative log fd."); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 870 | if (VG_(clo_verbosity) > 1) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 871 | VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 872 | } |
| 873 | return False; |
| 874 | } |
sewardj | 1075931 | 2005-05-30 23:52:47 +0000 | [diff] [blame] | 875 | else |
| 876 | if (soft && fd >= VG_(fd_soft_limit)) { |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 877 | return False; |
| 878 | } |
sewardj | 1075931 | 2005-05-30 23:52:47 +0000 | [diff] [blame] | 879 | else |
| 880 | if (fd == 2 && VG_(debugLog_getLevel)() > 0) { |
| 881 | return False; |
| 882 | } |
| 883 | else { |
| 884 | return True; |
| 885 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
| 889 | /* --------------------------------------------------------------------- |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 890 | Deal with a bunch of socket-related syscalls |
| 891 | ------------------------------------------------------------------ */ |
| 892 | |
| 893 | /* ------ */ |
| 894 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 895 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 896 | ML_(generic_PRE_sys_socketpair) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 897 | UWord arg0, UWord arg1, |
| 898 | UWord arg2, UWord arg3 ) |
| 899 | { |
| 900 | /* int socketpair(int d, int type, int protocol, int sv[2]); */ |
| 901 | PRE_MEM_WRITE( "socketcall.socketpair(sv)", |
| 902 | arg3, 2*sizeof(int) ); |
| 903 | } |
| 904 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 905 | SysRes |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 906 | ML_(generic_POST_sys_socketpair) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 907 | SysRes res, |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 908 | UWord arg0, UWord arg1, |
| 909 | UWord arg2, UWord arg3 ) |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 910 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 911 | SysRes r = res; |
| 912 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 913 | Int fd1 = ((Int*)arg3)[0]; |
| 914 | Int fd2 = ((Int*)arg3)[1]; |
| 915 | POST_MEM_WRITE( arg3, 2*sizeof(int) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 916 | if (!ML_(fd_allowed)(fd1, "socketcall.socketpair", tid, True) || |
| 917 | !ML_(fd_allowed)(fd2, "socketcall.socketpair", tid, True)) { |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 918 | VG_(close)(fd1); |
| 919 | VG_(close)(fd2); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 920 | r = VG_(mk_SysRes_Error)( VKI_EMFILE ); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 921 | } else { |
| 922 | POST_MEM_WRITE( arg3, 2*sizeof(int) ); |
| 923 | if (VG_(clo_track_fds)) { |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 924 | ML_(record_fd_open_nameless)(tid, fd1); |
| 925 | ML_(record_fd_open_nameless)(tid, fd2); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | return r; |
| 929 | } |
| 930 | |
| 931 | /* ------ */ |
| 932 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 933 | SysRes |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 934 | ML_(generic_POST_sys_socket) ( ThreadId tid, SysRes res ) |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 935 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 936 | SysRes r = res; |
| 937 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 938 | if (!ML_(fd_allowed)(res.val, "socket", tid, True)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 939 | VG_(close)(res.val); |
| 940 | r = VG_(mk_SysRes_Error)( VKI_EMFILE ); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 941 | } else { |
| 942 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 943 | ML_(record_fd_open_nameless)(tid, res.val); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 944 | } |
| 945 | return r; |
| 946 | } |
| 947 | |
| 948 | /* ------ */ |
| 949 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 950 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 951 | ML_(generic_PRE_sys_bind) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 952 | UWord arg0, UWord arg1, UWord arg2 ) |
| 953 | { |
| 954 | /* int bind(int sockfd, struct sockaddr *my_addr, |
| 955 | int addrlen); */ |
| 956 | pre_mem_read_sockaddr( |
| 957 | tid, "socketcall.bind(my_addr.%s)", |
| 958 | (struct vki_sockaddr *) arg1, arg2 |
| 959 | ); |
| 960 | } |
| 961 | |
| 962 | /* ------ */ |
| 963 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 964 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 965 | ML_(generic_PRE_sys_accept) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 966 | UWord arg0, UWord arg1, UWord arg2 ) |
| 967 | { |
| 968 | /* int accept(int s, struct sockaddr *addr, int *addrlen); */ |
| 969 | Addr addr_p = arg1; |
| 970 | Addr addrlen_p = arg2; |
| 971 | if (addr_p != (Addr)NULL) |
| 972 | buf_and_len_pre_check ( tid, addr_p, addrlen_p, |
| 973 | "socketcall.accept(addr)", |
| 974 | "socketcall.accept(addrlen_in)" ); |
| 975 | } |
| 976 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 977 | SysRes |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 978 | ML_(generic_POST_sys_accept) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 979 | SysRes res, |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 980 | UWord arg0, UWord arg1, UWord arg2 ) |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 981 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 982 | SysRes r = res; |
| 983 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 984 | if (!ML_(fd_allowed)(res.val, "accept", tid, True)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 985 | VG_(close)(res.val); |
| 986 | r = VG_(mk_SysRes_Error)( VKI_EMFILE ); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 987 | } else { |
| 988 | Addr addr_p = arg1; |
| 989 | Addr addrlen_p = arg2; |
| 990 | if (addr_p != (Addr)NULL) |
| 991 | buf_and_len_post_check ( tid, res, addr_p, addrlen_p, |
| 992 | "socketcall.accept(addrlen_out)" ); |
| 993 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 994 | ML_(record_fd_open_nameless)(tid, res.val); |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 995 | } |
| 996 | return r; |
| 997 | } |
| 998 | |
| 999 | /* ------ */ |
| 1000 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1001 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1002 | ML_(generic_PRE_sys_sendto) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1003 | UWord arg0, UWord arg1, UWord arg2, |
| 1004 | UWord arg3, UWord arg4, UWord arg5 ) |
| 1005 | { |
| 1006 | /* int sendto(int s, const void *msg, int len, |
| 1007 | unsigned int flags, |
| 1008 | const struct sockaddr *to, int tolen); */ |
| 1009 | PRE_MEM_READ( "socketcall.sendto(msg)", |
| 1010 | arg1, /* msg */ |
| 1011 | arg2 /* len */ ); |
| 1012 | pre_mem_read_sockaddr( |
| 1013 | tid, "socketcall.sendto(to.%s)", |
| 1014 | (struct vki_sockaddr *) arg4, arg5 |
| 1015 | ); |
| 1016 | } |
| 1017 | |
| 1018 | /* ------ */ |
| 1019 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1020 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1021 | ML_(generic_PRE_sys_send) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1022 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1023 | { |
| 1024 | /* int send(int s, const void *msg, size_t len, int flags); */ |
| 1025 | PRE_MEM_READ( "socketcall.send(msg)", |
| 1026 | arg1, /* msg */ |
| 1027 | arg2 /* len */ ); |
| 1028 | |
| 1029 | } |
| 1030 | |
| 1031 | /* ------ */ |
| 1032 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1033 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1034 | ML_(generic_PRE_sys_recvfrom) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1035 | UWord arg0, UWord arg1, UWord arg2, |
| 1036 | UWord arg3, UWord arg4, UWord arg5 ) |
| 1037 | { |
| 1038 | /* int recvfrom(int s, void *buf, int len, unsigned int flags, |
| 1039 | struct sockaddr *from, int *fromlen); */ |
| 1040 | Addr buf_p = arg1; |
| 1041 | Int len = arg2; |
| 1042 | Addr from_p = arg4; |
| 1043 | Addr fromlen_p = arg5; |
| 1044 | PRE_MEM_WRITE( "socketcall.recvfrom(buf)", buf_p, len ); |
| 1045 | if (from_p != (Addr)NULL) |
| 1046 | buf_and_len_pre_check ( tid, from_p, fromlen_p, |
| 1047 | "socketcall.recvfrom(from)", |
| 1048 | "socketcall.recvfrom(fromlen_in)" ); |
| 1049 | } |
| 1050 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1051 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1052 | ML_(generic_POST_sys_recvfrom) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1053 | SysRes res, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1054 | UWord arg0, UWord arg1, UWord arg2, |
| 1055 | UWord arg3, UWord arg4, UWord arg5 ) |
| 1056 | { |
| 1057 | Addr buf_p = arg1; |
| 1058 | Int len = arg2; |
| 1059 | Addr from_p = arg4; |
| 1060 | Addr fromlen_p = arg5; |
| 1061 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1062 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1063 | if (from_p != (Addr)NULL) |
| 1064 | buf_and_len_post_check ( tid, res, from_p, fromlen_p, |
| 1065 | "socketcall.recvfrom(fromlen_out)" ); |
| 1066 | POST_MEM_WRITE( buf_p, len ); |
| 1067 | } |
| 1068 | |
| 1069 | /* ------ */ |
| 1070 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1071 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1072 | ML_(generic_PRE_sys_recv) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1073 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1074 | { |
| 1075 | /* int recv(int s, void *buf, int len, unsigned int flags); */ |
| 1076 | /* man 2 recv says: |
| 1077 | The recv call is normally used only on a connected socket |
| 1078 | (see connect(2)) and is identical to recvfrom with a NULL |
| 1079 | from parameter. |
| 1080 | */ |
| 1081 | PRE_MEM_WRITE( "socketcall.recv(buf)", |
| 1082 | arg1, /* buf */ |
| 1083 | arg2 /* len */ ); |
| 1084 | } |
| 1085 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1086 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1087 | ML_(generic_POST_sys_recv) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1088 | UWord res, |
| 1089 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1090 | { |
| 1091 | if (res >= 0 && arg1 != 0) { |
| 1092 | POST_MEM_WRITE( arg1, /* buf */ |
| 1093 | arg2 /* len */ ); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | /* ------ */ |
| 1098 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1099 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1100 | ML_(generic_PRE_sys_connect) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1101 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1102 | { |
| 1103 | /* int connect(int sockfd, |
| 1104 | struct sockaddr *serv_addr, int addrlen ); */ |
| 1105 | PRE_MEM_READ( "socketcall.connect(serv_addr.sa_family)", |
| 1106 | arg1, /* serv_addr */ |
| 1107 | sizeof(vki_sa_family_t)); |
| 1108 | pre_mem_read_sockaddr( tid, |
| 1109 | "socketcall.connect(serv_addr.%s)", |
| 1110 | (struct vki_sockaddr *) arg1, arg2); |
| 1111 | } |
| 1112 | |
| 1113 | /* ------ */ |
| 1114 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1115 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1116 | ML_(generic_PRE_sys_setsockopt) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1117 | UWord arg0, UWord arg1, UWord arg2, |
| 1118 | UWord arg3, UWord arg4 ) |
| 1119 | { |
| 1120 | /* int setsockopt(int s, int level, int optname, |
| 1121 | const void *optval, int optlen); */ |
| 1122 | PRE_MEM_READ( "socketcall.setsockopt(optval)", |
| 1123 | arg3, /* optval */ |
| 1124 | arg4 /* optlen */ ); |
| 1125 | } |
| 1126 | |
| 1127 | /* ------ */ |
| 1128 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1129 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1130 | ML_(generic_PRE_sys_getsockopt) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1131 | UWord arg0, UWord arg1, UWord arg2, |
| 1132 | UWord arg3, UWord arg4 ) |
| 1133 | { |
| 1134 | /* int getsockopt(int s, int level, int optname, |
| 1135 | void *optval, socklen_t *optlen); */ |
| 1136 | Addr optval_p = arg3; |
| 1137 | Addr optlen_p = arg4; |
| 1138 | /* vg_assert(sizeof(socklen_t) == sizeof(UInt)); */ |
| 1139 | if (optval_p != (Addr)NULL) |
| 1140 | buf_and_len_pre_check ( tid, optval_p, optlen_p, |
| 1141 | "socketcall.getsockopt(optval)", |
| 1142 | "socketcall.getsockopt(optlen)" ); |
| 1143 | } |
| 1144 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1145 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1146 | ML_(generic_POST_sys_getsockopt) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1147 | SysRes res, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1148 | UWord arg0, UWord arg1, UWord arg2, |
| 1149 | UWord arg3, UWord arg4 ) |
| 1150 | { |
| 1151 | Addr optval_p = arg3; |
| 1152 | Addr optlen_p = arg4; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1153 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1154 | if (optval_p != (Addr)NULL) |
| 1155 | buf_and_len_post_check ( tid, res, optval_p, optlen_p, |
| 1156 | "socketcall.getsockopt(optlen_out)" ); |
| 1157 | } |
| 1158 | |
| 1159 | /* ------ */ |
| 1160 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1161 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1162 | ML_(generic_PRE_sys_getsockname) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1163 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1164 | { |
| 1165 | /* int getsockname(int s, struct sockaddr* name, int* namelen) */ |
| 1166 | Addr name_p = arg1; |
| 1167 | Addr namelen_p = arg2; |
| 1168 | /* Nb: name_p cannot be NULL */ |
| 1169 | buf_and_len_pre_check ( tid, name_p, namelen_p, |
| 1170 | "socketcall.getsockname(name)", |
| 1171 | "socketcall.getsockname(namelen_in)" ); |
| 1172 | } |
| 1173 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1174 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1175 | ML_(generic_POST_sys_getsockname) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1176 | SysRes res, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1177 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1178 | { |
| 1179 | Addr name_p = arg1; |
| 1180 | Addr namelen_p = arg2; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1181 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1182 | buf_and_len_post_check ( tid, res, name_p, namelen_p, |
| 1183 | "socketcall.getsockname(namelen_out)" ); |
| 1184 | } |
| 1185 | |
| 1186 | /* ------ */ |
| 1187 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1188 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1189 | ML_(generic_PRE_sys_getpeername) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1190 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1191 | { |
| 1192 | /* int getpeername(int s, struct sockaddr* name, int* namelen) */ |
| 1193 | Addr name_p = arg1; |
| 1194 | Addr namelen_p = arg2; |
| 1195 | /* Nb: name_p cannot be NULL */ |
| 1196 | buf_and_len_pre_check ( tid, name_p, namelen_p, |
| 1197 | "socketcall.getpeername(name)", |
| 1198 | "socketcall.getpeername(namelen_in)" ); |
| 1199 | } |
| 1200 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1201 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1202 | ML_(generic_POST_sys_getpeername) ( ThreadId tid, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1203 | SysRes res, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1204 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1205 | { |
| 1206 | Addr name_p = arg1; |
| 1207 | Addr namelen_p = arg2; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1208 | vg_assert(!res.isError); /* guaranteed by caller */ |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1209 | buf_and_len_post_check ( tid, res, name_p, namelen_p, |
| 1210 | "socketcall.getpeername(namelen_out)" ); |
| 1211 | } |
| 1212 | |
| 1213 | /* ------ */ |
| 1214 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1215 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1216 | ML_(generic_PRE_sys_sendmsg) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1217 | UWord arg0, UWord arg1 ) |
| 1218 | { |
| 1219 | /* int sendmsg(int s, const struct msghdr *msg, int flags); */ |
| 1220 | struct vki_msghdr *msg = (struct vki_msghdr *)arg1; |
| 1221 | msghdr_foreachfield ( tid, msg, pre_mem_read_sendmsg ); |
| 1222 | } |
| 1223 | |
| 1224 | /* ------ */ |
| 1225 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1226 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1227 | ML_(generic_PRE_sys_recvmsg) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1228 | UWord arg0, UWord arg1 ) |
| 1229 | { |
| 1230 | /* int recvmsg(int s, struct msghdr *msg, int flags); */ |
| 1231 | struct vki_msghdr *msg = (struct vki_msghdr *)arg1; |
| 1232 | msghdr_foreachfield ( tid, msg, pre_mem_write_recvmsg ); |
| 1233 | } |
| 1234 | |
sewardj | 987a8eb | 2005-03-01 19:00:30 +0000 | [diff] [blame] | 1235 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1236 | ML_(generic_POST_sys_recvmsg) ( ThreadId tid, |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 1237 | UWord arg0, UWord arg1 ) |
| 1238 | { |
| 1239 | struct vki_msghdr *msg = (struct vki_msghdr *)arg1; |
| 1240 | msghdr_foreachfield( tid, msg, post_mem_write_recvmsg ); |
| 1241 | check_cmsg_for_fds( tid, msg ); |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | /* --------------------------------------------------------------------- |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1246 | Deal with a bunch of IPC related syscalls |
| 1247 | ------------------------------------------------------------------ */ |
| 1248 | |
| 1249 | /* ------ */ |
| 1250 | |
| 1251 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1252 | ML_(generic_PRE_sys_semop) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1253 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1254 | { |
| 1255 | /* int semop(int semid, struct sembuf *sops, unsigned nsops); */ |
| 1256 | PRE_MEM_READ( "semop(sops)", arg1, arg2 * sizeof(struct vki_sembuf) ); |
| 1257 | } |
| 1258 | |
| 1259 | /* ------ */ |
| 1260 | |
| 1261 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1262 | ML_(generic_PRE_sys_semtimedop) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1263 | UWord arg0, UWord arg1, |
| 1264 | UWord arg2, UWord arg3 ) |
| 1265 | { |
| 1266 | /* int semtimedop(int semid, struct sembuf *sops, unsigned nsops, |
| 1267 | struct timespec *timeout); */ |
| 1268 | PRE_MEM_READ( "semtimedop(sops)", arg1, arg2 * sizeof(struct vki_sembuf) ); |
| 1269 | if (arg3 != 0) |
| 1270 | PRE_MEM_READ( "semtimedop(timeout)", arg3, sizeof(struct vki_timespec) ); |
| 1271 | } |
| 1272 | |
| 1273 | /* ------ */ |
| 1274 | |
| 1275 | static |
| 1276 | UInt get_sem_count( Int semid ) |
| 1277 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1278 | struct vki_semid_ds buf; |
| 1279 | union vki_semun arg; |
| 1280 | SysRes res; |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1281 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1282 | arg.buf = &buf; |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1283 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1284 | # ifdef __NR_semctl |
| 1285 | res = VG_(do_syscall4)(__NR_semctl, semid, 0, VKI_IPC_STAT, *(UWord *)&arg); |
| 1286 | # else |
| 1287 | res = VG_(do_syscall5)(__NR_ipc, 3 /* IPCOP_semctl */, semid, 0, |
| 1288 | VKI_IPC_STAT, (UWord)&arg); |
| 1289 | # endif |
| 1290 | if (res.isError) |
| 1291 | return 0; |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1292 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1293 | return buf.sem_nsems; |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1297 | ML_(generic_PRE_sys_semctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1298 | UWord arg0, UWord arg1, |
| 1299 | UWord arg2, UWord arg3 ) |
| 1300 | { |
| 1301 | /* int semctl(int semid, int semnum, int cmd, ...); */ |
| 1302 | union vki_semun arg = *(union vki_semun *)&arg3; |
| 1303 | UInt nsems; |
| 1304 | switch (arg2 /* cmd */) { |
| 1305 | case VKI_IPC_INFO: |
| 1306 | case VKI_SEM_INFO: |
| 1307 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1308 | case VKI_SEM_INFO|VKI_IPC_64: |
| 1309 | PRE_MEM_WRITE( "semctl(IPC_INFO, arg.buf)", |
| 1310 | (Addr)arg.buf, sizeof(struct vki_seminfo) ); |
| 1311 | break; |
| 1312 | case VKI_IPC_STAT: |
| 1313 | case VKI_SEM_STAT: |
| 1314 | PRE_MEM_WRITE( "semctl(IPC_STAT, arg.buf)", |
| 1315 | (Addr)arg.buf, sizeof(struct vki_semid_ds) ); |
| 1316 | break; |
| 1317 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1318 | case VKI_SEM_STAT|VKI_IPC_64: |
| 1319 | PRE_MEM_WRITE( "semctl(IPC_STAT, arg.buf)", |
| 1320 | (Addr)arg.buf, sizeof(struct vki_semid64_ds) ); |
| 1321 | break; |
| 1322 | case VKI_IPC_SET: |
| 1323 | PRE_MEM_READ( "semctl(IPC_SET, arg.buf)", |
| 1324 | (Addr)arg.buf, sizeof(struct vki_semid_ds) ); |
| 1325 | break; |
| 1326 | case VKI_IPC_SET|VKI_IPC_64: |
| 1327 | PRE_MEM_READ( "semctl(IPC_SET, arg.buf)", |
| 1328 | (Addr)arg.buf, sizeof(struct vki_semid64_ds) ); |
| 1329 | break; |
| 1330 | case VKI_GETALL: |
| 1331 | case VKI_GETALL|VKI_IPC_64: |
| 1332 | nsems = get_sem_count( arg0 ); |
| 1333 | PRE_MEM_WRITE( "semctl(IPC_GETALL, arg.array)", |
| 1334 | (Addr)arg.array, sizeof(unsigned short) * nsems ); |
| 1335 | break; |
| 1336 | case VKI_SETALL: |
| 1337 | case VKI_SETALL|VKI_IPC_64: |
| 1338 | nsems = get_sem_count( arg0 ); |
| 1339 | PRE_MEM_READ( "semctl(IPC_SETALL, arg.array)", |
| 1340 | (Addr)arg.array, sizeof(unsigned short) * nsems ); |
| 1341 | break; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1346 | ML_(generic_POST_sys_semctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1347 | UWord res, |
| 1348 | UWord arg0, UWord arg1, |
| 1349 | UWord arg2, UWord arg3 ) |
| 1350 | { |
| 1351 | union vki_semun arg = *(union vki_semun *)&arg3; |
| 1352 | UInt nsems; |
| 1353 | switch (arg2 /* cmd */) { |
| 1354 | case VKI_IPC_INFO: |
| 1355 | case VKI_SEM_INFO: |
| 1356 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1357 | case VKI_SEM_INFO|VKI_IPC_64: |
| 1358 | POST_MEM_WRITE( (Addr)arg.buf, sizeof(struct vki_seminfo) ); |
| 1359 | break; |
| 1360 | case VKI_IPC_STAT: |
| 1361 | case VKI_SEM_STAT: |
| 1362 | POST_MEM_WRITE( (Addr)arg.buf, sizeof(struct vki_semid_ds) ); |
| 1363 | break; |
| 1364 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1365 | case VKI_SEM_STAT|VKI_IPC_64: |
| 1366 | POST_MEM_WRITE( (Addr)arg.buf, sizeof(struct vki_semid64_ds) ); |
| 1367 | break; |
| 1368 | case VKI_GETALL: |
| 1369 | case VKI_GETALL|VKI_IPC_64: |
| 1370 | nsems = get_sem_count( arg0 ); |
| 1371 | POST_MEM_WRITE( (Addr)arg.array, sizeof(unsigned short) * nsems ); |
| 1372 | break; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /* ------ */ |
| 1377 | |
| 1378 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1379 | ML_(generic_PRE_sys_msgsnd) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1380 | UWord arg0, UWord arg1, |
| 1381 | UWord arg2, UWord arg3 ) |
| 1382 | { |
| 1383 | /* int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); */ |
| 1384 | struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; |
| 1385 | PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) ); |
| 1386 | PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, arg2 ); |
| 1387 | } |
| 1388 | |
| 1389 | /* ------ */ |
| 1390 | |
| 1391 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1392 | ML_(generic_PRE_sys_msgrcv) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1393 | UWord arg0, UWord arg1, UWord arg2, |
| 1394 | UWord arg3, UWord arg4 ) |
| 1395 | { |
| 1396 | /* ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, |
| 1397 | long msgtyp, int msgflg); */ |
| 1398 | struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; |
| 1399 | PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) ); |
| 1400 | PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, arg2 ); |
| 1401 | } |
| 1402 | |
| 1403 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1404 | ML_(generic_POST_sys_msgrcv) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1405 | UWord res, |
| 1406 | UWord arg0, UWord arg1, UWord arg2, |
| 1407 | UWord arg3, UWord arg4 ) |
| 1408 | { |
| 1409 | struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; |
| 1410 | POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) ); |
| 1411 | POST_MEM_WRITE( (Addr)&msgp->mtext, res ); |
| 1412 | } |
| 1413 | |
| 1414 | /* ------ */ |
| 1415 | |
| 1416 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1417 | ML_(generic_PRE_sys_msgctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1418 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1419 | { |
| 1420 | /* int msgctl(int msqid, int cmd, struct msqid_ds *buf); */ |
| 1421 | switch (arg1 /* cmd */) { |
| 1422 | case VKI_IPC_INFO: |
| 1423 | case VKI_MSG_INFO: |
| 1424 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1425 | case VKI_MSG_INFO|VKI_IPC_64: |
| 1426 | PRE_MEM_WRITE( "msgctl(IPC_INFO, buf)", |
| 1427 | arg2, sizeof(struct vki_msginfo) ); |
| 1428 | break; |
| 1429 | case VKI_IPC_STAT: |
| 1430 | case VKI_MSG_STAT: |
| 1431 | PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)", |
| 1432 | arg2, sizeof(struct vki_msqid_ds) ); |
| 1433 | break; |
| 1434 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1435 | case VKI_MSG_STAT|VKI_IPC_64: |
| 1436 | PRE_MEM_WRITE( "msgctl(IPC_STAT, arg.buf)", |
| 1437 | arg2, sizeof(struct vki_msqid64_ds) ); |
| 1438 | break; |
| 1439 | case VKI_IPC_SET: |
| 1440 | PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)", |
| 1441 | arg2, sizeof(struct vki_msqid_ds) ); |
| 1442 | break; |
| 1443 | case VKI_IPC_SET|VKI_IPC_64: |
| 1444 | PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)", |
| 1445 | arg2, sizeof(struct vki_msqid64_ds) ); |
| 1446 | break; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1451 | ML_(generic_POST_sys_msgctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1452 | UWord res, |
| 1453 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1454 | { |
| 1455 | switch (arg1 /* cmd */) { |
| 1456 | case VKI_IPC_INFO: |
| 1457 | case VKI_MSG_INFO: |
| 1458 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1459 | case VKI_MSG_INFO|VKI_IPC_64: |
| 1460 | POST_MEM_WRITE( arg2, sizeof(struct vki_msginfo) ); |
| 1461 | break; |
| 1462 | case VKI_IPC_STAT: |
| 1463 | case VKI_MSG_STAT: |
| 1464 | POST_MEM_WRITE( arg2, sizeof(struct vki_msqid_ds) ); |
| 1465 | break; |
| 1466 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1467 | case VKI_MSG_STAT|VKI_IPC_64: |
| 1468 | POST_MEM_WRITE( arg2, sizeof(struct vki_msqid64_ds) ); |
| 1469 | break; |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | /* ------ */ |
| 1474 | |
| 1475 | static |
| 1476 | UInt get_shm_size ( Int shmid ) |
| 1477 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1478 | # ifdef __NR_shmctl |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1479 | struct vki_shmid64_ds buf; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1480 | SysRes __res = VG_(do_syscall3)(__NR_shmctl, shmid, VKI_IPC_STAT, (UWord)&buf); |
| 1481 | # else |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1482 | struct vki_shmid_ds buf; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1483 | SysRes __res = VG_(do_syscall5)(__NR_ipc, 24 /* IPCOP_shmctl */, shmid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1484 | VKI_IPC_STAT, 0, (UWord)&buf); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1485 | # endif |
| 1486 | if (__res.isError) |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1487 | return 0; |
| 1488 | |
| 1489 | return buf.shm_segsz; |
| 1490 | } |
| 1491 | |
| 1492 | UWord |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1493 | ML_(generic_PRE_sys_shmat) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1494 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1495 | { |
| 1496 | /* void *shmat(int shmid, const void *shmaddr, int shmflg); */ |
| 1497 | UInt segmentSize = get_shm_size ( arg0 ); |
| 1498 | if (arg1 == 0) |
| 1499 | arg1 = VG_(find_map_space)(0, segmentSize, True); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1500 | else if (!ML_(valid_client_addr)(arg1, segmentSize, tid, "shmat")) |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1501 | arg1 = 0; |
| 1502 | return arg1; |
| 1503 | } |
| 1504 | |
| 1505 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1506 | ML_(generic_POST_sys_shmat) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1507 | UWord res, |
| 1508 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1509 | { |
| 1510 | UInt segmentSize = get_shm_size ( arg0 ); |
| 1511 | if ( segmentSize > 0 ) { |
| 1512 | UInt prot = VKI_PROT_READ|VKI_PROT_WRITE; |
| 1513 | /* we don't distinguish whether it's read-only or |
| 1514 | * read-write -- it doesn't matter really. */ |
| 1515 | VG_TRACK( new_mem_mmap, res, segmentSize, True, True, False ); |
| 1516 | |
| 1517 | if (!(arg2 & 010000)) /* = SHM_RDONLY */ |
| 1518 | prot &= ~VKI_PROT_WRITE; |
| 1519 | VG_(map_segment)(res, segmentSize, prot, SF_SHARED|SF_SHM); |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | /* ------ */ |
| 1524 | |
| 1525 | Bool |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1526 | ML_(generic_PRE_sys_shmdt) ( ThreadId tid, UWord arg0 ) |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1527 | { |
| 1528 | /* int shmdt(const void *shmaddr); */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1529 | return ML_(valid_client_addr)(arg0, 1, tid, "shmdt"); |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1533 | ML_(generic_POST_sys_shmdt) ( ThreadId tid, UWord res, UWord arg0 ) |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1534 | { |
| 1535 | Segment *s = VG_(find_segment)(arg0); |
| 1536 | |
| 1537 | if (s != NULL && (s->flags & SF_SHM) && VG_(seg_contains)(s, arg0, 1)) { |
| 1538 | VG_TRACK( die_mem_munmap, s->addr, s->len ); |
| 1539 | VG_(unmap_range)(s->addr, s->len); |
| 1540 | } |
| 1541 | } |
| 1542 | /* ------ */ |
| 1543 | |
| 1544 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1545 | ML_(generic_PRE_sys_shmctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1546 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1547 | { |
| 1548 | /* int shmctl(int shmid, int cmd, struct shmid_ds *buf); */ |
| 1549 | switch (arg1 /* cmd */) { |
| 1550 | case VKI_IPC_INFO: |
| 1551 | PRE_MEM_WRITE( "shmctl(IPC_INFO, buf)", |
| 1552 | arg2, sizeof(struct vki_shminfo) ); |
| 1553 | break; |
| 1554 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1555 | PRE_MEM_WRITE( "shmctl(IPC_INFO, buf)", |
| 1556 | arg2, sizeof(struct vki_shminfo64) ); |
| 1557 | break; |
| 1558 | case VKI_SHM_INFO: |
| 1559 | case VKI_SHM_INFO|VKI_IPC_64: |
| 1560 | PRE_MEM_WRITE( "shmctl(SHM_INFO, buf)", |
| 1561 | arg2, sizeof(struct vki_shm_info) ); |
| 1562 | break; |
| 1563 | case VKI_IPC_STAT: |
| 1564 | case VKI_SHM_STAT: |
| 1565 | PRE_MEM_WRITE( "shmctl(IPC_STAT, buf)", |
| 1566 | arg2, sizeof(struct vki_shmid_ds) ); |
| 1567 | break; |
| 1568 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1569 | case VKI_SHM_STAT|VKI_IPC_64: |
| 1570 | PRE_MEM_WRITE( "shmctl(IPC_STAT, arg.buf)", |
| 1571 | arg2, sizeof(struct vki_shmid64_ds) ); |
| 1572 | break; |
| 1573 | case VKI_IPC_SET: |
| 1574 | PRE_MEM_READ( "shmctl(IPC_SET, arg.buf)", |
| 1575 | arg2, sizeof(struct vki_shmid_ds) ); |
| 1576 | break; |
| 1577 | case VKI_IPC_SET|VKI_IPC_64: |
| 1578 | PRE_MEM_READ( "shmctl(IPC_SET, arg.buf)", |
| 1579 | arg2, sizeof(struct vki_shmid64_ds) ); |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | void |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1585 | ML_(generic_POST_sys_shmctl) ( ThreadId tid, |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1586 | UWord res, |
| 1587 | UWord arg0, UWord arg1, UWord arg2 ) |
| 1588 | { |
| 1589 | switch (arg1 /* cmd */) { |
| 1590 | case VKI_IPC_INFO: |
| 1591 | POST_MEM_WRITE( arg2, sizeof(struct vki_shminfo) ); |
| 1592 | break; |
| 1593 | case VKI_IPC_INFO|VKI_IPC_64: |
| 1594 | POST_MEM_WRITE( arg2, sizeof(struct vki_shminfo64) ); |
| 1595 | break; |
| 1596 | case VKI_SHM_INFO: |
| 1597 | case VKI_SHM_INFO|VKI_IPC_64: |
| 1598 | POST_MEM_WRITE( arg2, sizeof(struct vki_shm_info) ); |
| 1599 | break; |
| 1600 | case VKI_IPC_STAT: |
| 1601 | case VKI_SHM_STAT: |
| 1602 | POST_MEM_WRITE( arg2, sizeof(struct vki_shmid_ds) ); |
| 1603 | break; |
| 1604 | case VKI_IPC_STAT|VKI_IPC_64: |
| 1605 | case VKI_SHM_STAT|VKI_IPC_64: |
| 1606 | POST_MEM_WRITE( arg2, sizeof(struct vki_shmid64_ds) ); |
| 1607 | break; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | /* --------------------------------------------------------------------- |
nethercote | 4fa681f | 2004-11-08 17:51:39 +0000 | [diff] [blame] | 1613 | The Main Entertainment ... syscall wrappers |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1614 | ------------------------------------------------------------------ */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1615 | |
nethercote | 4fa681f | 2004-11-08 17:51:39 +0000 | [diff] [blame] | 1616 | /* Note: the PRE() and POST() wrappers are for the actual functions |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1617 | implementing the system calls in the OS kernel. These mostly have |
nethercote | 4fa681f | 2004-11-08 17:51:39 +0000 | [diff] [blame] | 1618 | names like sys_write(); a few have names like old_mmap(). See the |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 1619 | comment for ML_(syscall_table)[] for important info about the __NR_foo |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1620 | constants and their relationship to the sys_foo() functions. |
nethercote | 4fa681f | 2004-11-08 17:51:39 +0000 | [diff] [blame] | 1621 | |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 1622 | Some notes about names used for syscalls and args: |
| 1623 | - For the --trace-syscalls=yes output, we use the sys_foo() name to avoid |
| 1624 | ambiguity. |
| 1625 | |
| 1626 | - For error messages, we generally use a somewhat generic name |
| 1627 | for the syscall (eg. "write" rather than "sys_write"). This should be |
| 1628 | good enough for the average user to understand what is happening, |
| 1629 | without confusing them with names like "sys_write". |
| 1630 | |
| 1631 | - Also, for error messages the arg names are mostly taken from the man |
| 1632 | pages (even though many of those man pages are really for glibc |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1633 | functions of the same name), rather than from the OS kernel source, |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 1634 | for the same reason -- a user presented with a "bogus foo(bar)" arg |
| 1635 | will most likely look at the "foo" man page to see which is the "bar" |
| 1636 | arg. |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 1637 | |
nethercote | 9c311eb | 2004-11-12 18:20:12 +0000 | [diff] [blame] | 1638 | Note that we use our own vki_* types. The one exception is in |
| 1639 | PRE_REG_READn calls, where pointer types haven't been changed, because |
| 1640 | they don't need to be -- eg. for "foo*" to be used, the type foo need not |
| 1641 | be visible. |
| 1642 | |
nethercote | 4fa681f | 2004-11-08 17:51:39 +0000 | [diff] [blame] | 1643 | XXX: some of these are arch-specific, and should be factored out. |
| 1644 | */ |
| 1645 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1646 | #define PRE(name) DEFN_PRE_TEMPLATE(generic, name) |
| 1647 | #define POST(name) DEFN_POST_TEMPLATE(generic, name) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1648 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 1649 | // Combine two 32-bit values into a 64-bit value |
| 1650 | #define LOHI64(lo,hi) ( (lo) | ((ULong)(hi) << 32) ) |
| 1651 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1652 | //zz //PRE(sys_exit_group, Special) |
| 1653 | //zz //{ |
| 1654 | //zz // VG_(core_panic)("syscall exit_group() not caught by the scheduler?!"); |
| 1655 | //zz //} |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 1656 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1657 | PRE(sys_exit) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1658 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1659 | ThreadState* tst; |
sewardj | a922b61 | 2005-03-11 02:47:32 +0000 | [diff] [blame] | 1660 | /* simple; just make this thread exit */ |
| 1661 | PRINT("exit( %d )", ARG1); |
| 1662 | PRE_REG_READ1(void, "exit", int, exitcode); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1663 | tst = VG_(get_ThreadState)(tid); |
| 1664 | /* Set the thread's status to be exiting, then claim that the |
| 1665 | syscall succeeded. */ |
sewardj | a922b61 | 2005-03-11 02:47:32 +0000 | [diff] [blame] | 1666 | tst->exitreason = VgSrc_ExitSyscall; |
| 1667 | tst->os_state.exitcode = ARG1; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1668 | SET_STATUS_Success(0); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 1671 | PRE(sys_sched_yield) |
| 1672 | { |
| 1673 | *flags |= SfMayBlock; |
| 1674 | PRINT("sched_yield()"); |
| 1675 | PRE_REG_READ0(long, "sys_sched_yield"); |
| 1676 | } |
nethercote | 5b653bc | 2004-11-15 14:32:12 +0000 | [diff] [blame] | 1677 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1678 | PRE(sys_ni_syscall) |
nethercote | eb1c7b7 | 2004-11-11 19:43:50 +0000 | [diff] [blame] | 1679 | { |
| 1680 | PRINT("non-existent syscall! (ni_syscall)"); |
| 1681 | PRE_REG_READ0(long, "ni_syscall"); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1682 | SET_STATUS_Failure( VKI_ENOSYS ); |
nethercote | eb1c7b7 | 2004-11-11 19:43:50 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1685 | PRE(sys_iopl) |
| 1686 | { |
| 1687 | PRINT("sys_iopl ( %d )", ARG1); |
| 1688 | PRE_REG_READ1(long, "iopl", unsigned long, level); |
| 1689 | } |
| 1690 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1691 | PRE(sys_setxattr) |
| 1692 | { |
| 1693 | *flags |= SfMayBlock; |
| 1694 | PRINT("sys_setxattr ( %p, %p, %p, %llu, %d )", |
| 1695 | ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); |
| 1696 | PRE_REG_READ5(long, "setxattr", |
| 1697 | char *, path, char *, name, |
| 1698 | void *, value, vki_size_t, size, int, flags); |
| 1699 | PRE_MEM_RASCIIZ( "setxattr(path)", ARG1 ); |
| 1700 | PRE_MEM_RASCIIZ( "setxattr(name)", ARG2 ); |
| 1701 | PRE_MEM_READ( "setxattr(value)", ARG3, ARG4 ); |
| 1702 | } |
| 1703 | |
| 1704 | PRE(sys_lsetxattr) |
| 1705 | { |
| 1706 | *flags |= SfMayBlock; |
| 1707 | PRINT("sys_lsetxattr ( %p, %p, %p, %llu, %d )", |
| 1708 | ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); |
| 1709 | PRE_REG_READ5(long, "lsetxattr", |
| 1710 | char *, path, char *, name, |
| 1711 | void *, value, vki_size_t, size, int, flags); |
| 1712 | PRE_MEM_RASCIIZ( "lsetxattr(path)", ARG1 ); |
| 1713 | PRE_MEM_RASCIIZ( "lsetxattr(name)", ARG2 ); |
| 1714 | PRE_MEM_READ( "lsetxattr(value)", ARG3, ARG4 ); |
| 1715 | } |
| 1716 | |
| 1717 | PRE(sys_fsetxattr) |
| 1718 | { |
| 1719 | *flags |= SfMayBlock; |
| 1720 | PRINT("sys_fsetxattr ( %d, %p, %p, %llu, %d )", |
| 1721 | ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); |
| 1722 | PRE_REG_READ5(long, "fsetxattr", |
| 1723 | int, fd, char *, name, void *, value, |
| 1724 | vki_size_t, size, int, flags); |
| 1725 | PRE_MEM_RASCIIZ( "fsetxattr(name)", ARG2 ); |
| 1726 | PRE_MEM_READ( "fsetxattr(value)", ARG3, ARG4 ); |
| 1727 | } |
rjwalsh | cdf1cb5 | 2004-04-29 08:40:50 +0000 | [diff] [blame] | 1728 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1729 | PRE(sys_getxattr) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1730 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1731 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1732 | PRINT("sys_getxattr ( %p, %p, %p, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4); |
nethercote | 2e1c37d | 2004-11-13 13:57:12 +0000 | [diff] [blame] | 1733 | PRE_REG_READ4(ssize_t, "getxattr", |
| 1734 | char *, path, char *, name, void *, value, vki_size_t, size); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1735 | PRE_MEM_RASCIIZ( "getxattr(path)", ARG1 ); |
| 1736 | PRE_MEM_RASCIIZ( "getxattr(name)", ARG2 ); |
| 1737 | PRE_MEM_WRITE( "getxattr(value)", ARG3, ARG4 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1738 | } |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 1739 | POST(sys_getxattr) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1740 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1741 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1742 | if (RES > 0 && ARG3 != (Addr)NULL) { |
| 1743 | POST_MEM_WRITE( ARG3, RES ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1747 | PRE(sys_lgetxattr) |
| 1748 | { |
| 1749 | *flags |= SfMayBlock; |
| 1750 | PRINT("sys_lgetxattr ( %p, %p, %p, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4); |
| 1751 | PRE_REG_READ4(ssize_t, "lgetxattr", |
| 1752 | char *, path, char *, name, void *, value, vki_size_t, size); |
| 1753 | PRE_MEM_RASCIIZ( "lgetxattr(path)", ARG1 ); |
| 1754 | PRE_MEM_RASCIIZ( "lgetxattr(name)", ARG2 ); |
| 1755 | PRE_MEM_WRITE( "lgetxattr(value)", ARG3, ARG4 ); |
| 1756 | } |
| 1757 | POST(sys_lgetxattr) |
| 1758 | { |
| 1759 | vg_assert(SUCCESS); |
| 1760 | if (RES > 0 && ARG3 != (Addr)NULL) { |
| 1761 | POST_MEM_WRITE( ARG3, RES ); |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | PRE(sys_fgetxattr) |
| 1766 | { |
| 1767 | *flags |= SfMayBlock; |
| 1768 | PRINT("sys_fgetxattr ( %d, %p, %p, %llu )", ARG1, ARG2, ARG3, (ULong)ARG4); |
| 1769 | PRE_REG_READ4(ssize_t, "fgetxattr", |
| 1770 | int, fd, char *, name, void *, value, vki_size_t, size); |
| 1771 | PRE_MEM_RASCIIZ( "fgetxattr(name)", ARG2 ); |
| 1772 | PRE_MEM_WRITE( "fgetxattr(value)", ARG3, ARG4 ); |
| 1773 | } |
| 1774 | POST(sys_fgetxattr) |
| 1775 | { |
| 1776 | if (RES > 0 && ARG3 != (Addr)NULL) |
| 1777 | POST_MEM_WRITE( ARG3, RES ); |
| 1778 | } |
| 1779 | |
| 1780 | PRE(sys_listxattr) |
| 1781 | { |
| 1782 | *flags |= SfMayBlock; |
| 1783 | PRINT("sys_listxattr ( %p, %p, %llu )", ARG1, ARG2, (ULong)ARG3); |
| 1784 | PRE_REG_READ3(ssize_t, "listxattr", |
| 1785 | char *, path, char *, list, vki_size_t, size); |
| 1786 | PRE_MEM_RASCIIZ( "listxattr(path)", ARG1 ); |
| 1787 | PRE_MEM_WRITE( "listxattr(list)", ARG2, ARG3 ); |
| 1788 | } |
| 1789 | POST(sys_listxattr) |
| 1790 | { |
| 1791 | if (RES > 0 && ARG2 != (Addr)NULL) |
| 1792 | POST_MEM_WRITE( ARG2, RES ); |
| 1793 | } |
| 1794 | |
| 1795 | PRE(sys_llistxattr) |
| 1796 | { |
| 1797 | *flags |= SfMayBlock; |
| 1798 | PRINT("sys_llistxattr ( %p, %p, %llu )", ARG1, ARG2, (ULong)ARG3); |
| 1799 | PRE_REG_READ3(ssize_t, "llistxattr", |
| 1800 | char *, path, char *, list, vki_size_t, size); |
| 1801 | PRE_MEM_RASCIIZ( "llistxattr(path)", ARG1 ); |
| 1802 | PRE_MEM_WRITE( "llistxattr(list)", ARG2, ARG3 ); |
| 1803 | } |
| 1804 | POST(sys_llistxattr) |
| 1805 | { |
| 1806 | if (RES > 0 && ARG2 != (Addr)NULL) |
| 1807 | POST_MEM_WRITE( ARG2, RES ); |
| 1808 | } |
| 1809 | |
| 1810 | PRE(sys_flistxattr) |
| 1811 | { |
| 1812 | *flags |= SfMayBlock; |
| 1813 | PRINT("sys_flistxattr ( %d, %p, %llu )", ARG1, ARG2, (ULong)ARG3); |
| 1814 | PRE_REG_READ3(ssize_t, "flistxattr", |
| 1815 | int, fd, char *, list, vki_size_t, size); |
| 1816 | PRE_MEM_WRITE( "flistxattr(list)", ARG2, ARG3 ); |
| 1817 | } |
| 1818 | POST(sys_flistxattr) |
| 1819 | { |
| 1820 | if (RES > 0 && ARG2 != (Addr)NULL) |
| 1821 | POST_MEM_WRITE( ARG2, RES ); |
| 1822 | } |
| 1823 | |
| 1824 | PRE(sys_removexattr) |
| 1825 | { |
| 1826 | *flags |= SfMayBlock; |
| 1827 | PRINT("sys_removexattr ( %p, %p )", ARG1, ARG2); |
| 1828 | PRE_REG_READ2(long, "removexattr", char *, path, char *, name); |
| 1829 | PRE_MEM_RASCIIZ( "removexattr(path)", ARG1 ); |
| 1830 | PRE_MEM_RASCIIZ( "removexattr(name)", ARG2 ); |
| 1831 | } |
| 1832 | |
| 1833 | PRE(sys_lremovexattr) |
| 1834 | { |
| 1835 | *flags |= SfMayBlock; |
| 1836 | PRINT("sys_lremovexattr ( %p, %p )", ARG1, ARG2); |
| 1837 | PRE_REG_READ2(long, "lremovexattr", char *, path, char *, name); |
| 1838 | PRE_MEM_RASCIIZ( "lremovexattr(path)", ARG1 ); |
| 1839 | PRE_MEM_RASCIIZ( "lremovexattr(name)", ARG2 ); |
| 1840 | } |
| 1841 | |
| 1842 | PRE(sys_fremovexattr) |
| 1843 | { |
| 1844 | *flags |= SfMayBlock; |
| 1845 | PRINT("sys_fremovexattr ( %d, %p )", ARG1, ARG2); |
| 1846 | PRE_REG_READ2(long, "fremovexattr", int, fd, char *, name); |
| 1847 | PRE_MEM_RASCIIZ( "fremovexattr(name)", ARG2 ); |
| 1848 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1849 | |
| 1850 | PRE(sys_quotactl) |
| 1851 | { |
| 1852 | PRINT("sys_quotactl (0x%x, %p, 0x%x, 0x%x )", ARG1,ARG2,ARG3, ARG4); |
| 1853 | PRE_REG_READ4(long, "quotactl", |
| 1854 | unsigned int, cmd, const char *, special, vki_qid_t, id, |
| 1855 | void *, addr); |
| 1856 | PRE_MEM_RASCIIZ( "quotactl(special)", ARG2 ); |
| 1857 | } |
| 1858 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1859 | // XXX: this wrapper is only suitable for 32-bit platforms |
| 1860 | #if defined(VGP_x86_linux) |
| 1861 | PRE(sys_lookup_dcookie) |
| 1862 | { |
| 1863 | PRINT("sys_lookup_dcookie (0x%llx, %p, %d)", LOHI64(ARG1,ARG2), ARG3, ARG4); |
| 1864 | PRE_REG_READ4(long, "lookup_dcookie", |
| 1865 | vki_u32, cookie_low32, vki_u32, cookie_high32, |
| 1866 | char *, buf, vki_size_t, len); |
| 1867 | PRE_MEM_WRITE( "lookup_dcookie(buf)", ARG3, ARG4); |
| 1868 | } |
| 1869 | POST(sys_lookup_dcookie) |
| 1870 | { |
| 1871 | vg_assert(SUCCESS); |
| 1872 | if (ARG3 != (Addr)NULL) |
| 1873 | POST_MEM_WRITE( ARG3, RES); |
| 1874 | } |
| 1875 | #endif |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 1876 | |
| 1877 | PRE(sys_fsync) |
| 1878 | { |
| 1879 | *flags |= SfMayBlock; |
| 1880 | PRINT("sys_fsync ( %d )", ARG1); |
| 1881 | PRE_REG_READ1(long, "fsync", unsigned int, fd); |
| 1882 | } |
| 1883 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1884 | PRE(sys_fdatasync) |
| 1885 | { |
| 1886 | *flags |= SfMayBlock; |
| 1887 | PRINT("sys_fdatasync ( %d )", ARG1); |
| 1888 | PRE_REG_READ1(long, "fdatasync", unsigned int, fd); |
| 1889 | } |
| 1890 | |
| 1891 | PRE(sys_msync) |
| 1892 | { |
| 1893 | *flags |= SfMayBlock; |
| 1894 | PRINT("sys_msync ( %p, %llu, %d )", ARG1,(ULong)ARG2,ARG3); |
| 1895 | PRE_REG_READ3(long, "msync", |
| 1896 | unsigned long, start, vki_size_t, length, int, flags); |
| 1897 | PRE_MEM_READ( "msync(start)", ARG1, ARG2 ); |
| 1898 | } |
| 1899 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1900 | // Nb: getpmsg() and putpmsg() are special additional syscalls used in early |
| 1901 | // versions of LiS (Linux Streams). They are not part of the kernel. |
| 1902 | // Therefore, we have to provide this type ourself, rather than getting it |
| 1903 | // from the kernel sources. |
| 1904 | struct vki_pmsg_strbuf { |
| 1905 | int maxlen; /* no. of bytes in buffer */ |
| 1906 | int len; /* no. of bytes returned */ |
| 1907 | vki_caddr_t buf; /* pointer to data */ |
| 1908 | }; |
| 1909 | PRE(sys_getpmsg) |
| 1910 | { |
| 1911 | /* LiS getpmsg from http://www.gcom.com/home/linux/lis/ */ |
| 1912 | struct vki_pmsg_strbuf *ctrl; |
| 1913 | struct vki_pmsg_strbuf *data; |
| 1914 | *flags |= SfMayBlock; |
| 1915 | PRINT("sys_getpmsg ( %d, %p, %p, %p, %p )", ARG1,ARG2,ARG3,ARG4,ARG5); |
| 1916 | PRE_REG_READ5(int, "getpmsg", |
| 1917 | int, fd, struct strbuf *, ctrl, struct strbuf *, data, |
| 1918 | int *, bandp, int *, flagsp); |
| 1919 | ctrl = (struct vki_pmsg_strbuf *)ARG2; |
| 1920 | data = (struct vki_pmsg_strbuf *)ARG3; |
| 1921 | if (ctrl && ctrl->maxlen > 0) |
| 1922 | PRE_MEM_WRITE( "getpmsg(ctrl)", (Addr)ctrl->buf, ctrl->maxlen); |
| 1923 | if (data && data->maxlen > 0) |
| 1924 | PRE_MEM_WRITE( "getpmsg(data)", (Addr)data->buf, data->maxlen); |
| 1925 | if (ARG4) |
| 1926 | PRE_MEM_WRITE( "getpmsg(bandp)", (Addr)ARG4, sizeof(int)); |
| 1927 | if (ARG5) |
| 1928 | PRE_MEM_WRITE( "getpmsg(flagsp)", (Addr)ARG5, sizeof(int)); |
| 1929 | } |
| 1930 | POST(sys_getpmsg) |
| 1931 | { |
| 1932 | struct vki_pmsg_strbuf *ctrl; |
| 1933 | struct vki_pmsg_strbuf *data; |
| 1934 | vg_assert(SUCCESS); |
| 1935 | ctrl = (struct vki_pmsg_strbuf *)ARG2; |
| 1936 | data = (struct vki_pmsg_strbuf *)ARG3; |
| 1937 | if (RES == 0 && ctrl && ctrl->len > 0) { |
| 1938 | POST_MEM_WRITE( (Addr)ctrl->buf, ctrl->len); |
| 1939 | } |
| 1940 | if (RES == 0 && data && data->len > 0) { |
| 1941 | POST_MEM_WRITE( (Addr)data->buf, data->len); |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | PRE(sys_putpmsg) |
| 1946 | { |
| 1947 | /* LiS putpmsg from http://www.gcom.com/home/linux/lis/ */ |
| 1948 | struct vki_pmsg_strbuf *ctrl; |
| 1949 | struct vki_pmsg_strbuf *data; |
| 1950 | *flags |= SfMayBlock; |
| 1951 | PRINT("sys_putpmsg ( %d, %p, %p, %d, %d )", ARG1,ARG2,ARG3,ARG4,ARG5); |
| 1952 | PRE_REG_READ5(int, "putpmsg", |
| 1953 | int, fd, struct strbuf *, ctrl, struct strbuf *, data, |
| 1954 | int, band, int, flags); |
| 1955 | ctrl = (struct vki_pmsg_strbuf *)ARG2; |
| 1956 | data = (struct vki_pmsg_strbuf *)ARG3; |
| 1957 | if (ctrl && ctrl->len > 0) |
| 1958 | PRE_MEM_READ( "putpmsg(ctrl)", (Addr)ctrl->buf, ctrl->len); |
| 1959 | if (data && data->len > 0) |
| 1960 | PRE_MEM_READ( "putpmsg(data)", (Addr)data->buf, data->len); |
| 1961 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1962 | |
| 1963 | PRE(sys_getitimer) |
| 1964 | { |
| 1965 | PRINT("sys_getitimer ( %d, %p )", ARG1, ARG2); |
| 1966 | PRE_REG_READ2(long, "getitimer", int, which, struct itimerval *, value); |
| 1967 | PRE_MEM_WRITE( "getitimer(value)", ARG2, sizeof(struct vki_itimerval) ); |
| 1968 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1969 | POST(sys_getitimer) |
| 1970 | { |
| 1971 | if (ARG2 != (Addr)NULL) { |
| 1972 | POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerval)); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | PRE(sys_setitimer) |
| 1977 | { |
| 1978 | PRINT("sys_setitimer ( %d, %p, %p )", ARG1,ARG2,ARG3); |
| 1979 | PRE_REG_READ3(long, "setitimer", |
| 1980 | int, which, |
| 1981 | struct itimerval *, value, struct itimerval *, ovalue); |
| 1982 | if (ARG2 != (Addr)NULL) |
| 1983 | PRE_MEM_READ( "setitimer(value)", ARG2, sizeof(struct vki_itimerval) ); |
| 1984 | if (ARG3 != (Addr)NULL) |
| 1985 | PRE_MEM_WRITE( "setitimer(ovalue)", ARG3, sizeof(struct vki_itimerval)); |
| 1986 | } |
| 1987 | |
| 1988 | POST(sys_setitimer) |
| 1989 | { |
| 1990 | if (ARG3 != (Addr)NULL) { |
| 1991 | POST_MEM_WRITE(ARG3, sizeof(struct vki_itimerval)); |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | PRE(sys_chroot) |
| 1996 | { |
| 1997 | PRINT("sys_chroot ( %p )", ARG1); |
| 1998 | PRE_REG_READ1(long, "chroot", const char *, path); |
| 1999 | PRE_MEM_RASCIIZ( "chroot(path)", ARG1 ); |
| 2000 | } |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2001 | |
| 2002 | PRE(sys_madvise) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2003 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2004 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2005 | PRINT("sys_madvise ( %p, %llu, %d )", ARG1,(ULong)ARG2,ARG3); |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 2006 | PRE_REG_READ3(long, "madvise", |
| 2007 | unsigned long, start, vki_size_t, length, int, advice); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2010 | PRE(sys_mremap) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2011 | { |
nethercote | 27ea8bc | 2004-07-10 17:21:14 +0000 | [diff] [blame] | 2012 | // Nb: this is different to the glibc version described in the man pages, |
| 2013 | // which lacks the fifth 'new_address' argument. |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 2014 | PRINT("sys_mremap ( %p, %llu, %d, 0x%x, %p )", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2015 | ARG1, (ULong)ARG2, ARG3, ARG4, ARG5); |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 2016 | PRE_REG_READ5(unsigned long, "mremap", |
| 2017 | unsigned long, old_addr, unsigned long, old_size, |
| 2018 | unsigned long, new_size, unsigned long, flags, |
| 2019 | unsigned long, new_addr); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2020 | SET_STATUS_from_SysRes( |
| 2021 | mremap_segment((Addr)ARG1, ARG2, (Addr)ARG5, ARG3, ARG4, tid) |
| 2022 | ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 2025 | PRE(sys_nice) |
| 2026 | { |
| 2027 | PRINT("sys_nice ( %d )", ARG1); |
| 2028 | PRE_REG_READ1(long, "nice", int, inc); |
| 2029 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2030 | |
| 2031 | PRE(sys_sched_getscheduler) |
| 2032 | { |
| 2033 | PRINT("sys_sched_getscheduler ( %d )", ARG1); |
| 2034 | PRE_REG_READ1(long, "sched_getscheduler", vki_pid_t, pid); |
| 2035 | } |
| 2036 | |
| 2037 | PRE(sys_sched_setscheduler) |
| 2038 | { |
| 2039 | PRINT("sys_sched_setscheduler ( %d, %d, %p )", ARG1,ARG2,ARG3); |
| 2040 | PRE_REG_READ3(long, "sched_setscheduler", |
| 2041 | vki_pid_t, pid, int, policy, struct sched_param *, p); |
| 2042 | if (ARG3 != 0) |
| 2043 | PRE_MEM_READ( "sched_setscheduler(p)", |
| 2044 | ARG3, sizeof(struct vki_sched_param)); |
| 2045 | } |
| 2046 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2047 | PRE(sys_mlock) |
| 2048 | { |
| 2049 | *flags |= SfMayBlock; |
| 2050 | PRINT("sys_mlock ( %p, %llu )", ARG1, (ULong)ARG2); |
| 2051 | PRE_REG_READ2(long, "mlock", unsigned long, addr, vki_size_t, len); |
| 2052 | } |
| 2053 | |
| 2054 | PRE(sys_munlock) |
| 2055 | { |
| 2056 | *flags |= SfMayBlock; |
| 2057 | PRINT("sys_munlock ( %p, %llu )", ARG1, (ULong)ARG2); |
| 2058 | PRE_REG_READ2(long, "munlock", unsigned long, addr, vki_size_t, len); |
| 2059 | } |
| 2060 | |
| 2061 | PRE(sys_mlockall) |
| 2062 | { |
| 2063 | *flags |= SfMayBlock; |
| 2064 | PRINT("sys_mlockall ( %x )", ARG1); |
| 2065 | PRE_REG_READ1(long, "mlockall", int, flags); |
| 2066 | } |
| 2067 | |
| 2068 | PRE(sys_munlockall) |
| 2069 | { |
| 2070 | *flags |= SfMayBlock; |
| 2071 | PRINT("sys_munlockall ( )"); |
| 2072 | PRE_REG_READ0(long, "munlockall"); |
| 2073 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2074 | |
| 2075 | PRE(sys_sched_get_priority_max) |
| 2076 | { |
| 2077 | PRINT("sched_get_priority_max ( %d )", ARG1); |
| 2078 | PRE_REG_READ1(long, "sched_get_priority_max", int, policy); |
| 2079 | } |
| 2080 | |
| 2081 | PRE(sys_sched_get_priority_min) |
| 2082 | { |
| 2083 | PRINT("sched_get_priority_min ( %d )", ARG1); |
| 2084 | PRE_REG_READ1(long, "sched_get_priority_min", int, policy); |
| 2085 | } |
| 2086 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2087 | PRE(sys_setpriority) |
| 2088 | { |
| 2089 | PRINT("sys_setpriority ( %d, %d, %d )", ARG1, ARG2, ARG3); |
| 2090 | PRE_REG_READ3(long, "setpriority", int, which, int, who, int, prio); |
| 2091 | } |
| 2092 | |
| 2093 | PRE(sys_getpriority) |
| 2094 | { |
| 2095 | PRINT("sys_getpriority ( %d, %d )", ARG1, ARG2); |
| 2096 | PRE_REG_READ2(long, "getpriority", int, which, int, who); |
| 2097 | } |
| 2098 | |
| 2099 | PRE(sys_setregid16) |
| 2100 | { |
| 2101 | PRINT("sys_setregid16 ( %d, %d )", ARG1, ARG2); |
| 2102 | PRE_REG_READ2(long, "setregid16", vki_old_gid_t, rgid, vki_old_gid_t, egid); |
| 2103 | } |
| 2104 | |
tom | 4f08a65 | 2005-07-05 23:25:17 +0000 | [diff] [blame] | 2105 | // The actual kernel definition of this routine takes a |
| 2106 | // single 64 bit offset argument. This version is for 32 bit |
| 2107 | // platforms only and treats the offset as two values - the |
| 2108 | // kernel relies on stack based argument passing conventions |
| 2109 | // to merge the two together. |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2110 | PRE(sys_pwrite64) |
| 2111 | { |
| 2112 | *flags |= SfMayBlock; |
| 2113 | PRINT("sys_pwrite64 ( %d, %p, %llu, %lld )", |
| 2114 | ARG1, ARG2, (ULong)ARG3, LOHI64(ARG4,ARG5)); |
| 2115 | PRE_REG_READ5(ssize_t, "pwrite64", |
| 2116 | unsigned int, fd, const char *, buf, vki_size_t, count, |
| 2117 | vki_u32, offset_low32, vki_u32, offset_high32); |
| 2118 | PRE_MEM_READ( "pwrite64(buf)", ARG2, ARG3 ); |
| 2119 | } |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 2120 | |
| 2121 | PRE(sys_sync) |
| 2122 | { |
| 2123 | *flags |= SfMayBlock; |
| 2124 | PRINT("sys_sync ( )"); |
| 2125 | PRE_REG_READ0(long, "sync"); |
| 2126 | } |
| 2127 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2128 | PRE(sys_fstatfs) |
| 2129 | { |
| 2130 | PRINT("sys_fstatfs ( %d, %p )",ARG1,ARG2); |
| 2131 | PRE_REG_READ2(long, "fstatfs", |
| 2132 | unsigned int, fd, struct statfs *, buf); |
| 2133 | PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_statfs) ); |
| 2134 | } |
| 2135 | |
| 2136 | POST(sys_fstatfs) |
| 2137 | { |
| 2138 | POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) ); |
| 2139 | } |
| 2140 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2141 | PRE(sys_fstatfs64) |
| 2142 | { |
| 2143 | PRINT("sys_fstatfs64 ( %d, %llu, %p )",ARG1,(ULong)ARG2,ARG3); |
| 2144 | PRE_REG_READ3(long, "fstatfs64", |
| 2145 | unsigned int, fd, vki_size_t, size, struct statfs64 *, buf); |
| 2146 | PRE_MEM_WRITE( "fstatfs64(buf)", ARG3, ARG2 ); |
| 2147 | } |
| 2148 | POST(sys_fstatfs64) |
| 2149 | { |
| 2150 | POST_MEM_WRITE( ARG3, ARG2 ); |
| 2151 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2152 | |
| 2153 | PRE(sys_getsid) |
| 2154 | { |
| 2155 | PRINT("sys_getsid ( %d )", ARG1); |
| 2156 | PRE_REG_READ1(long, "getsid", vki_pid_t, pid); |
| 2157 | } |
| 2158 | |
tom | 4f08a65 | 2005-07-05 23:25:17 +0000 | [diff] [blame] | 2159 | // The actual kernel definition of this routine takes a |
| 2160 | // single 64 bit offset argument. This version is for 32 bit |
| 2161 | // platforms only and treats the offset as two values - the |
| 2162 | // kernel relies on stack based argument passing conventions |
| 2163 | // to merge the two together. |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 2164 | PRE(sys_pread64) |
| 2165 | { |
| 2166 | *flags |= SfMayBlock; |
| 2167 | PRINT("sys_pread64 ( %d, %p, %llu, %lld )", |
| 2168 | ARG1, ARG2, (ULong)ARG3, LOHI64(ARG4,ARG5)); |
| 2169 | PRE_REG_READ5(ssize_t, "pread64", |
| 2170 | unsigned int, fd, char *, buf, vki_size_t, count, |
| 2171 | vki_u32, offset_low32, vki_u32, offset_high32); |
| 2172 | PRE_MEM_WRITE( "pread64(buf)", ARG2, ARG3 ); |
| 2173 | } |
| 2174 | POST(sys_pread64) |
| 2175 | { |
| 2176 | vg_assert(SUCCESS); |
| 2177 | if (RES > 0) { |
| 2178 | POST_MEM_WRITE( ARG2, RES ); |
| 2179 | } |
| 2180 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2181 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2182 | PRE(sys_mknod) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2183 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2184 | PRINT("sys_mknod ( %p, 0x%x, 0x%x )", ARG1, ARG2, ARG3 ); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 2185 | PRE_REG_READ3(long, "mknod", |
| 2186 | const char *, pathname, int, mode, unsigned, dev); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2187 | PRE_MEM_RASCIIZ( "mknod(pathname)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2190 | PRE(sys_flock) |
| 2191 | { |
| 2192 | *flags |= SfMayBlock; |
| 2193 | PRINT("sys_flock ( %d, %d )", ARG1, ARG2 ); |
| 2194 | PRE_REG_READ2(long, "flock", unsigned int, fd, unsigned int, operation); |
| 2195 | } |
| 2196 | |
| 2197 | /* This surely isn't remotely generic -- move to linux-specifics? */ |
| 2198 | PRE(sys_init_module) |
| 2199 | { |
| 2200 | *flags |= SfMayBlock; |
| 2201 | PRINT("sys_init_module ( %p, %llu, %p )", ARG1, (ULong)ARG2, ARG3 ); |
| 2202 | PRE_REG_READ3(long, "init_module", |
| 2203 | void *, umod, unsigned long, len, const char *, uargs); |
| 2204 | PRE_MEM_READ( "init_module(umod)", ARG1, ARG2 ); |
| 2205 | PRE_MEM_RASCIIZ( "init_module(uargs)", ARG3 ); |
| 2206 | } |
| 2207 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2208 | PRE(sys_capget) |
| 2209 | { |
| 2210 | PRINT("sys_capget ( %p, %p )", ARG1, ARG2 ); |
| 2211 | PRE_REG_READ2(long, "capget", |
| 2212 | vki_cap_user_header_t, header, vki_cap_user_data_t, data); |
| 2213 | PRE_MEM_READ( "capget(header)", ARG1, |
| 2214 | sizeof(struct __vki_user_cap_header_struct) ); |
| 2215 | PRE_MEM_WRITE( "capget(data)", ARG2, |
| 2216 | sizeof(struct __vki_user_cap_data_struct) ); |
| 2217 | } |
| 2218 | POST(sys_capget) |
| 2219 | { |
| 2220 | if (ARG2 != (Addr)NULL) |
| 2221 | POST_MEM_WRITE( ARG2, sizeof(struct __vki_user_cap_data_struct) ); |
| 2222 | } |
| 2223 | |
| 2224 | PRE(sys_capset) |
| 2225 | { |
| 2226 | PRINT("sys_capset ( %p, %p )", ARG1, ARG2 ); |
| 2227 | PRE_REG_READ2(long, "capset", |
| 2228 | vki_cap_user_header_t, header, |
| 2229 | const vki_cap_user_data_t, data); |
| 2230 | PRE_MEM_READ( "capset(header)", |
| 2231 | ARG1, sizeof(struct __vki_user_cap_header_struct) ); |
| 2232 | PRE_MEM_READ( "capset(data)", |
| 2233 | ARG2, sizeof(struct __vki_user_cap_data_struct) ); |
| 2234 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2235 | |
nethercote | a81e916 | 2004-02-12 14:34:14 +0000 | [diff] [blame] | 2236 | // Pre_read a char** argument. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2237 | static void pre_argv_envp(Addr a, ThreadId tid, Char* s1, Char* s2) |
nethercote | a81e916 | 2004-02-12 14:34:14 +0000 | [diff] [blame] | 2238 | { |
| 2239 | while (True) { |
njn | b249fd7 | 2004-11-29 14:24:57 +0000 | [diff] [blame] | 2240 | Addr a_deref; |
| 2241 | Addr* a_p = (Addr*)a; |
| 2242 | PRE_MEM_READ( s1, (Addr)a_p, sizeof(Addr) ); |
| 2243 | a_deref = *a_p; |
nethercote | a81e916 | 2004-02-12 14:34:14 +0000 | [diff] [blame] | 2244 | if (0 == a_deref) |
| 2245 | break; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 2246 | PRE_MEM_RASCIIZ( s2, a_deref ); |
nethercote | a81e916 | 2004-02-12 14:34:14 +0000 | [diff] [blame] | 2247 | a += sizeof(char*); |
| 2248 | } |
| 2249 | } |
| 2250 | |
njn | 7b85dd5 | 2005-06-12 17:26:29 +0000 | [diff] [blame] | 2251 | static Bool i_am_the_only_thread ( void ) |
| 2252 | { |
| 2253 | Int c = VG_(count_living_threads)(); |
| 2254 | vg_assert(c >= 1); /* stay sane */ |
| 2255 | return c == 1; |
| 2256 | } |
| 2257 | |
| 2258 | /* Wait until all other threads disappear. */ |
| 2259 | void VG_(reap_threads)(ThreadId self) |
| 2260 | { |
| 2261 | while (!i_am_the_only_thread()) { |
| 2262 | /* Let other thread(s) run */ |
| 2263 | VG_(vg_yield)(); |
| 2264 | VG_(poll_signals)(self); |
| 2265 | } |
| 2266 | vg_assert(i_am_the_only_thread()); |
| 2267 | } |
| 2268 | |
nethercote | 7310afb | 2004-11-12 15:41:06 +0000 | [diff] [blame] | 2269 | // XXX: prototype here seemingly doesn't match the prototype for i386-linux, |
| 2270 | // but it seems to work nonetheless... |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2271 | PRE(sys_execve) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2272 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2273 | Char* path; /* path to executable */ |
| 2274 | ThreadState* tst; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2275 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2276 | PRINT("sys_execve ( %p(%s), %p, %p )", ARG1, ARG1, ARG2, ARG3); |
nethercote | 7310afb | 2004-11-12 15:41:06 +0000 | [diff] [blame] | 2277 | PRE_REG_READ3(vki_off_t, "execve", |
| 2278 | char *, filename, char **, argv, char **, envp); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2279 | PRE_MEM_RASCIIZ( "execve(filename)", ARG1 ); |
| 2280 | if (ARG2 != 0) |
| 2281 | pre_argv_envp( ARG2, tid, "execve(argv)", "execve(argv[i])" ); |
| 2282 | if (ARG3 != 0) |
| 2283 | pre_argv_envp( ARG3, tid, "execve(envp)", "execve(envp[i])" ); |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2284 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2285 | path = (Char *)ARG1; |
| 2286 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2287 | vg_assert(VG_(is_valid_tid)(tid)); |
| 2288 | tst = VG_(get_ThreadState)(tid); |
| 2289 | |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2290 | /* Erk. If the exec fails, then the following will have made a |
| 2291 | mess of things which makes it hard for us to continue. The |
| 2292 | right thing to do is piece everything together again in |
| 2293 | POST(execve), but that's hard work. Instead, we make an effort |
| 2294 | to check that the execve will work before actually calling |
| 2295 | exec. */ |
| 2296 | { |
| 2297 | struct vki_stat st; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2298 | Int i = VG_(stat)((Char *)ARG1, &st); |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2299 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2300 | if (i == -1) { |
| 2301 | /* stat failed */ |
| 2302 | SET_STATUS_Failure( VKI_EACCES/*really, we should copy stat's result*/ ); |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2303 | return; |
| 2304 | } |
thughes | 90efa30 | 2004-09-25 16:13:55 +0000 | [diff] [blame] | 2305 | /* just look for regular file with any X bit set |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2306 | XXX do proper permissions check? |
| 2307 | */ |
thughes | 90efa30 | 2004-09-25 16:13:55 +0000 | [diff] [blame] | 2308 | if ((st.st_mode & 0100111) == 0100000) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2309 | SET_STATUS_Failure( VKI_EACCES ); |
fitzhardinge | e1c06d8 | 2003-10-30 07:21:44 +0000 | [diff] [blame] | 2310 | return; |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | /* Resistance is futile. Nuke all other threads. POSIX mandates |
| 2315 | this. (Really, nuke them all, since the new process will make |
| 2316 | its own new thread.) */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2317 | VG_(nuke_all_threads_except)( tid, VgSrc_ExitSyscall ); |
njn | 7b85dd5 | 2005-06-12 17:26:29 +0000 | [diff] [blame] | 2318 | VG_(reap_threads)(tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2319 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2320 | { // Remove the valgrind-specific stuff from the environment so the |
njn | 16eeb4e | 2005-06-16 03:56:58 +0000 | [diff] [blame] | 2321 | // child doesn't get vg_preload_core.so, vg_preload_TOOL.so, etc. |
| 2322 | // This is done unconditionally, since if we are tracing the child, |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2323 | // stage1/2 will set up the appropriate client environment. |
| 2324 | Char** envp = (Char**)ARG3; |
| 2325 | if (envp != NULL) { |
| 2326 | VG_(env_remove_valgrind_env_stuff)( envp ); |
| 2327 | } |
fitzhardinge | 5408c06 | 2004-01-04 23:52:59 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | if (VG_(clo_trace_children)) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2331 | Char* optvar = VG_(build_child_VALGRINDCLO)( (Char*)ARG1 ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2332 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2333 | // Set VALGRINDCLO and VALGRINDLIB in ARG3 (the environment) |
| 2334 | VG_(env_setenv)( (Char***)&ARG3, VALGRINDCLO, optvar); |
| 2335 | VG_(env_setenv)( (Char***)&ARG3, VALGRINDLIB, VG_(libdir)); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2336 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2337 | // Create executable name: "/proc/self/fd/<vgexecfd>", update ARG1 |
sewardj | 8e33279 | 2005-03-11 12:56:56 +0000 | [diff] [blame] | 2338 | path = VG_(build_child_exename)(); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 2341 | VG_(debugLog)(1, "syswrap", "Exec of %s\n", (HChar*)ARG1); |
sewardj | 1075931 | 2005-05-30 23:52:47 +0000 | [diff] [blame] | 2342 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2343 | if (0) { |
| 2344 | Char **cpp; |
| 2345 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2346 | VG_(printf)("exec: %s\n", (Char *)ARG1); |
| 2347 | for(cpp = (Char **)ARG2; cpp && *cpp; cpp++) |
nethercote | f6a1d50 | 2004-08-09 12:21:57 +0000 | [diff] [blame] | 2348 | VG_(printf)("argv: %s\n", *cpp); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2349 | for(cpp = (Char **)ARG3; cpp && *cpp; cpp++) |
nethercote | f6a1d50 | 2004-08-09 12:21:57 +0000 | [diff] [blame] | 2350 | VG_(printf)("env: %s\n", *cpp); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2351 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2352 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2353 | /* restore the DATA rlimit for the child */ |
| 2354 | VG_(setrlimit)(VKI_RLIMIT_DATA, &VG_(client_rlimit_data)); |
| 2355 | |
| 2356 | /* |
| 2357 | Set the signal state up for exec. |
| 2358 | |
| 2359 | We need to set the real signal state to make sure the exec'd |
| 2360 | process gets SIG_IGN properly. |
| 2361 | |
| 2362 | Also set our real sigmask to match the client's sigmask so that |
| 2363 | the exec'd child will get the right mask. First we need to |
| 2364 | clear out any pending signals so they they don't get delivered, |
| 2365 | which would confuse things. |
fitzhardinge | f0dd7e1 | 2004-01-16 02:17:30 +0000 | [diff] [blame] | 2366 | |
| 2367 | XXX This is a bug - the signals should remain pending, and be |
| 2368 | delivered to the new process after exec. There's also a |
| 2369 | race-condition, since if someone delivers us a signal between |
| 2370 | the sigprocmask and the execve, we'll still get the signal. Oh |
| 2371 | well. |
| 2372 | */ |
| 2373 | { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2374 | vki_sigset_t allsigs; |
| 2375 | vki_siginfo_t info; |
fitzhardinge | f0dd7e1 | 2004-01-16 02:17:30 +0000 | [diff] [blame] | 2376 | static const struct vki_timespec zero = { 0, 0 }; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2377 | Int i; |
| 2378 | |
| 2379 | for(i = 1; i < VG_(max_signal); i++) { |
| 2380 | struct vki_sigaction sa; |
| 2381 | VG_(do_sys_sigaction)(i, NULL, &sa); |
| 2382 | if (sa.ksa_handler == VKI_SIG_IGN) |
| 2383 | VG_(sigaction)(i, &sa, NULL); |
| 2384 | else { |
| 2385 | sa.ksa_handler = VKI_SIG_DFL; |
| 2386 | VG_(sigaction)(i, &sa, NULL); |
| 2387 | } |
| 2388 | } |
| 2389 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2390 | VG_(sigfillset)(&allsigs); |
| 2391 | while(VG_(sigtimedwait)(&allsigs, &info, &zero) > 0) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2392 | ; |
fitzhardinge | f0dd7e1 | 2004-01-16 02:17:30 +0000 | [diff] [blame] | 2393 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2394 | VG_(sigprocmask)(VKI_SIG_SETMASK, &tst->sig_mask, NULL); |
fitzhardinge | f0dd7e1 | 2004-01-16 02:17:30 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2397 | SET_STATUS_from_SysRes( |
| 2398 | VG_(do_syscall3)(__NR_execve, (UWord)path, ARG2, ARG3) |
| 2399 | ); |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 2400 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2401 | /* If we got here, then the execve failed. We've already made too |
| 2402 | much of a mess of ourselves to continue, so we have to abort. */ |
nethercote | e70bd7d | 2004-08-18 14:37:17 +0000 | [diff] [blame] | 2403 | VG_(message)(Vg_UserMsg, "execve(%p(%s), %p, %p) failed, errno %d", |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2404 | ARG1, ARG1, ARG2, ARG3, -RES); |
| 2405 | VG_(message)(Vg_UserMsg, "EXEC FAILED: I can't recover from " |
| 2406 | "execve() failing, so I'm dying."); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2407 | VG_(message)(Vg_UserMsg, "Add more stringent tests in PRE(sys_execve), " |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2408 | "or work out how to recover."); |
| 2409 | VG_(exit)(101); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2412 | PRE(sys_access) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2413 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2414 | PRINT("sys_access ( %p(%s), %d )", ARG1,ARG1,ARG2); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 2415 | PRE_REG_READ2(long, "access", const char *, pathname, int, mode); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2416 | PRE_MEM_RASCIIZ( "access(pathname)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2419 | PRE(sys_alarm) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2420 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2421 | PRINT("sys_alarm ( %d )", ARG1); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 2422 | PRE_REG_READ1(unsigned long, "alarm", unsigned int, seconds); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2425 | PRE(sys_brk) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2426 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2427 | Addr brk_limit = VG_(brk_limit); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2428 | Addr brk_new; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2429 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2430 | /* libc says: int brk(void *end_data_segment); |
| 2431 | kernel says: void* brk(void* end_data_segment); (more or less) |
| 2432 | |
| 2433 | libc returns 0 on success, and -1 (and sets errno) on failure. |
| 2434 | Nb: if you ask to shrink the dataseg end below what it |
| 2435 | currently is, that always succeeds, even if the dataseg end |
| 2436 | doesn't actually change (eg. brk(0)). Unless it seg faults. |
| 2437 | |
| 2438 | Kernel returns the new dataseg end. If the brk() failed, this |
| 2439 | will be unchanged from the old one. That's why calling (kernel) |
| 2440 | brk(0) gives the current dataseg end (libc brk() just returns |
| 2441 | zero in that case). |
| 2442 | |
| 2443 | Both will seg fault if you shrink it back into a text segment. |
| 2444 | */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2445 | PRINT("sys_brk ( %p )", ARG1); |
nethercote | 9c311eb | 2004-11-12 18:20:12 +0000 | [diff] [blame] | 2446 | PRE_REG_READ1(unsigned long, "brk", unsigned long, end_data_segment); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2447 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2448 | brk_new = do_brk(ARG1); |
| 2449 | SET_STATUS_Success( brk_new ); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2450 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2451 | if (brk_new == ARG1) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2452 | /* brk() succeeded */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2453 | if (brk_new < brk_limit) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2454 | /* successfully shrunk the data segment. */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2455 | VG_TRACK( die_mem_brk, (Addr)ARG1, |
| 2456 | brk_limit-ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2457 | } else |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2458 | if (brk_new > brk_limit) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2459 | /* successfully grew the data segment */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 2460 | VG_TRACK( new_mem_brk, brk_limit, |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2461 | ARG1-brk_limit ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2462 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2463 | } else { |
| 2464 | /* brk() failed */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2465 | vg_assert(brk_limit == brk_new); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2469 | PRE(sys_chdir) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2470 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2471 | PRINT("sys_chdir ( %p )", ARG1); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 2472 | PRE_REG_READ1(long, "chdir", const char *, path); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2473 | PRE_MEM_RASCIIZ( "chdir(path)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2476 | PRE(sys_chmod) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2477 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2478 | PRINT("sys_chmod ( %p, %d )", ARG1,ARG2); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 2479 | PRE_REG_READ2(long, "chmod", const char *, path, vki_mode_t, mode); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2480 | PRE_MEM_RASCIIZ( "chmod(path)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2483 | PRE(sys_chown16) |
| 2484 | { |
| 2485 | PRINT("sys_chown16 ( %p, 0x%x, 0x%x )", ARG1,ARG2,ARG3); |
| 2486 | PRE_REG_READ3(long, "chown16", |
| 2487 | const char *, path, |
| 2488 | vki_old_uid_t, owner, vki_old_gid_t, group); |
| 2489 | PRE_MEM_RASCIIZ( "chown16(path)", ARG1 ); |
| 2490 | } |
| 2491 | |
| 2492 | PRE(sys_chown) |
| 2493 | { |
| 2494 | /* int chown(const char *path, uid_t owner, gid_t group); */ |
| 2495 | PRINT("sys_chown ( %p, 0x%x, 0x%x )", ARG1,ARG2,ARG3); |
| 2496 | PRE_REG_READ3(long, "chown", |
| 2497 | const char *, path, vki_uid_t, owner, vki_gid_t, group); |
| 2498 | PRE_MEM_RASCIIZ( "chown(path)", ARG1 ); |
| 2499 | } |
| 2500 | |
| 2501 | PRE(sys_lchown) |
| 2502 | { |
| 2503 | PRINT("sys_lchown ( %p, 0x%x, 0x%x )", ARG1,ARG2,ARG3); |
| 2504 | PRE_REG_READ3(long, "lchown", |
| 2505 | const char *, path, vki_uid_t, owner, vki_gid_t, group); |
| 2506 | PRE_MEM_RASCIIZ( "lchown(path)", ARG1 ); |
| 2507 | } |
nethercote | 2e1c37d | 2004-11-13 13:57:12 +0000 | [diff] [blame] | 2508 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2509 | PRE(sys_close) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2510 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2511 | PRINT("sys_close ( %d )", ARG1); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 2512 | PRE_REG_READ1(long, "close", unsigned int, fd); |
| 2513 | |
nethercote | f854867 | 2004-06-21 12:42:35 +0000 | [diff] [blame] | 2514 | /* Detect and negate attempts by the client to close Valgrind's log fd */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 2515 | if (!ML_(fd_allowed)(ARG1, "close", tid, False)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2516 | SET_STATUS_Failure( VKI_EBADF ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2519 | POST(sys_close) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 2520 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2521 | if (VG_(clo_track_fds)) record_fd_close(tid, ARG1); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 2522 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2523 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2524 | PRE(sys_dup) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2525 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2526 | PRINT("sys_dup ( %d )", ARG1); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 2527 | PRE_REG_READ1(long, "dup", unsigned int, oldfd); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2530 | POST(sys_dup) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2531 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2532 | vg_assert(SUCCESS); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 2533 | if (!ML_(fd_allowed)(RES, "dup", tid, True)) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2534 | VG_(close)(RES); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2535 | SET_STATUS_Failure( VKI_EMFILE ); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 2536 | } else { |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 2537 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 2538 | record_fd_open_named(tid, RES); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2542 | PRE(sys_dup2) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2543 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2544 | PRINT("sys_dup2 ( %d, %d )", ARG1,ARG2); |
nethercote | 71f05f3 | 2004-11-12 18:49:27 +0000 | [diff] [blame] | 2545 | PRE_REG_READ2(long, "dup2", unsigned int, oldfd, unsigned int, newfd); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 2546 | if (!ML_(fd_allowed)(ARG2, "dup2", tid, True)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2547 | SET_STATUS_Failure( VKI_EBADF ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2550 | POST(sys_dup2) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2551 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2552 | vg_assert(SUCCESS); |
nethercote | 71f05f3 | 2004-11-12 18:49:27 +0000 | [diff] [blame] | 2553 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 2554 | record_fd_open_named(tid, RES); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2557 | PRE(sys_fchdir) |
| 2558 | { |
| 2559 | PRINT("sys_fchdir ( %d )", ARG1); |
| 2560 | PRE_REG_READ1(long, "fchdir", unsigned int, fd); |
| 2561 | } |
| 2562 | |
| 2563 | PRE(sys_fchown16) |
| 2564 | { |
| 2565 | PRINT("sys_fchown16 ( %d, %d, %d )", ARG1,ARG2,ARG3); |
| 2566 | PRE_REG_READ3(long, "fchown16", |
| 2567 | unsigned int, fd, vki_old_uid_t, owner, vki_old_gid_t, group); |
| 2568 | } |
| 2569 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2570 | PRE(sys_fchown) |
| 2571 | { |
| 2572 | PRINT("sys_fchown ( %d, %d, %d )", ARG1,ARG2,ARG3); |
| 2573 | PRE_REG_READ3(long, "fchown", |
| 2574 | unsigned int, fd, vki_uid_t, owner, vki_gid_t, group); |
| 2575 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2576 | |
| 2577 | PRE(sys_fchmod) |
| 2578 | { |
| 2579 | PRINT("sys_fchmod ( %d, %d )", ARG1,ARG2); |
| 2580 | PRE_REG_READ2(long, "fchmod", unsigned int, fildes, vki_mode_t, mode); |
| 2581 | } |
| 2582 | |
| 2583 | PRE(sys_fcntl) |
| 2584 | { |
| 2585 | switch (ARG2) { |
| 2586 | // These ones ignore ARG3. |
| 2587 | case VKI_F_GETFD: |
| 2588 | case VKI_F_GETFL: |
| 2589 | case VKI_F_GETOWN: |
| 2590 | case VKI_F_SETOWN: |
| 2591 | case VKI_F_GETSIG: |
| 2592 | case VKI_F_SETSIG: |
| 2593 | case VKI_F_GETLEASE: |
| 2594 | PRINT("sys_fcntl ( %d, %d )", ARG1,ARG2); |
| 2595 | PRE_REG_READ2(long, "fcntl", unsigned int, fd, unsigned int, cmd); |
| 2596 | break; |
| 2597 | |
| 2598 | // These ones use ARG3 as "arg". |
| 2599 | case VKI_F_DUPFD: |
| 2600 | case VKI_F_SETFD: |
| 2601 | case VKI_F_SETFL: |
| 2602 | case VKI_F_SETLEASE: |
| 2603 | case VKI_F_NOTIFY: |
| 2604 | PRINT("sys_fcntl[ARG3=='arg'] ( %d, %d, %d )", ARG1,ARG2,ARG3); |
| 2605 | PRE_REG_READ3(long, "fcntl", |
| 2606 | unsigned int, fd, unsigned int, cmd, unsigned long, arg); |
| 2607 | break; |
| 2608 | |
| 2609 | // These ones use ARG3 as "lock". |
| 2610 | case VKI_F_GETLK: |
| 2611 | case VKI_F_SETLK: |
| 2612 | case VKI_F_SETLKW: |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 2613 | # if defined(VGP_x86_linux) |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2614 | case VKI_F_GETLK64: |
| 2615 | case VKI_F_SETLK64: |
| 2616 | case VKI_F_SETLKW64: |
| 2617 | # else |
| 2618 | # endif |
| 2619 | PRINT("sys_fcntl[ARG3=='lock'] ( %d, %d, %p )", ARG1,ARG2,ARG3); |
| 2620 | PRE_REG_READ3(long, "fcntl", |
| 2621 | unsigned int, fd, unsigned int, cmd, |
| 2622 | struct flock64 *, lock); |
| 2623 | break; |
| 2624 | } |
| 2625 | |
| 2626 | if (ARG2 == VKI_F_SETLKW) |
| 2627 | *flags |= SfMayBlock; |
| 2628 | } |
| 2629 | |
| 2630 | POST(sys_fcntl) |
| 2631 | { |
| 2632 | vg_assert(SUCCESS); |
| 2633 | if (ARG2 == VKI_F_DUPFD) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 2634 | if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) { |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2635 | VG_(close)(RES); |
| 2636 | SET_STATUS_Failure( VKI_EMFILE ); |
| 2637 | } else { |
| 2638 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 2639 | record_fd_open_named(tid, RES); |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2640 | } |
| 2641 | } |
| 2642 | } |
njn | cfb8ad5 | 2004-11-23 14:57:49 +0000 | [diff] [blame] | 2643 | |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 2644 | // XXX: wrapper only suitable for 32-bit systems |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2645 | PRE(sys_fcntl64) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2646 | { |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 2647 | switch (ARG2) { |
| 2648 | // These ones ignore ARG3. |
| 2649 | case VKI_F_GETFD: |
| 2650 | case VKI_F_GETFL: |
| 2651 | case VKI_F_GETOWN: |
| 2652 | case VKI_F_SETOWN: |
| 2653 | case VKI_F_GETSIG: |
| 2654 | case VKI_F_SETSIG: |
| 2655 | case VKI_F_GETLEASE: |
| 2656 | PRINT("sys_fcntl64 ( %d, %d )", ARG1,ARG2); |
| 2657 | PRE_REG_READ2(long, "fcntl64", unsigned int, fd, unsigned int, cmd); |
| 2658 | break; |
| 2659 | |
| 2660 | // These ones use ARG3 as "arg". |
| 2661 | case VKI_F_DUPFD: |
| 2662 | case VKI_F_SETFD: |
| 2663 | case VKI_F_SETFL: |
| 2664 | case VKI_F_SETLEASE: |
| 2665 | case VKI_F_NOTIFY: |
| 2666 | PRINT("sys_fcntl64[ARG3=='arg'] ( %d, %d, %d )", ARG1,ARG2,ARG3); |
| 2667 | PRE_REG_READ3(long, "fcntl64", |
| 2668 | unsigned int, fd, unsigned int, cmd, unsigned long, arg); |
| 2669 | break; |
| 2670 | |
| 2671 | // These ones use ARG3 as "lock". |
| 2672 | case VKI_F_GETLK: |
| 2673 | case VKI_F_SETLK: |
| 2674 | case VKI_F_SETLKW: |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 2675 | # if defined(VGP_x86_linux) |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 2676 | case VKI_F_GETLK64: |
| 2677 | case VKI_F_SETLK64: |
| 2678 | case VKI_F_SETLKW64: |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2679 | # endif |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 2680 | PRINT("sys_fcntl64[ARG3=='lock'] ( %d, %d, %p )", ARG1,ARG2,ARG3); |
| 2681 | PRE_REG_READ3(long, "fcntl64", |
| 2682 | unsigned int, fd, unsigned int, cmd, |
| 2683 | struct flock64 *, lock); |
| 2684 | break; |
| 2685 | } |
njn | cfb8ad5 | 2004-11-23 14:57:49 +0000 | [diff] [blame] | 2686 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 2687 | # if defined(VGP_x86_linux) |
| 2688 | if (ARG2 == VKI_F_SETLKW || ARG2 == VKI_F_SETLKW64) |
| 2689 | *flags |= SfMayBlock; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2690 | # else |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 2691 | if (ARG2 == VKI_F_SETLKW) |
| 2692 | *flags |= SfMayBlock; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2693 | # endif |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2696 | POST(sys_fcntl64) |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 2697 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2698 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2699 | if (ARG2 == VKI_F_DUPFD) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 2700 | if (!ML_(fd_allowed)(RES, "fcntl64(DUPFD)", tid, True)) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2701 | VG_(close)(RES); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2702 | SET_STATUS_Failure( VKI_EMFILE ); |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 2703 | } else { |
| 2704 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 2705 | record_fd_open_named(tid, RES); |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 2706 | } |
| 2707 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2710 | PRE(sys_newfstat) |
| 2711 | { |
| 2712 | PRINT("sys_newfstat ( %d, %p )", ARG1,ARG2); |
| 2713 | PRE_REG_READ2(long, "fstat", unsigned int, fd, struct stat *, buf); |
| 2714 | PRE_MEM_WRITE( "fstat(buf)", ARG2, sizeof(struct vki_stat) ); |
| 2715 | } |
| 2716 | |
| 2717 | POST(sys_newfstat) |
| 2718 | { |
| 2719 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); |
| 2720 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2721 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2722 | static vki_sigset_t fork_saved_mask; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2723 | |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 2724 | // In Linux, the sys_fork() function varies across architectures, but we |
| 2725 | // ignore the various args it gets, and so it looks arch-neutral. Hmm. |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2726 | PRE(sys_fork) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2727 | { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2728 | vki_sigset_t mask; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2729 | |
nethercote | 75a8c98 | 2004-11-11 19:03:34 +0000 | [diff] [blame] | 2730 | PRINT("sys_fork ( )"); |
| 2731 | PRE_REG_READ0(long, "fork"); |
| 2732 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2733 | /* Block all signals during fork, so that we can fix things up in |
| 2734 | the child without being interrupted. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2735 | VG_(sigfillset)(&mask); |
| 2736 | VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2737 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2738 | SET_STATUS_from_SysRes( VG_(do_syscall0)(__NR_fork) ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2739 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2740 | if (SUCCESS && RES == 0) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2741 | VG_(do_atfork_child)(tid); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2742 | |
| 2743 | /* restore signal mask */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2744 | VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2745 | } |
| 2746 | else |
| 2747 | if (SUCCESS && RES > 0) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2748 | PRINT(" fork: process %d created child %d\n", VG_(getpid)(), RES); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2749 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2750 | /* restore signal mask */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 2751 | VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 2755 | PRE(sys_ftruncate) |
| 2756 | { |
| 2757 | *flags |= SfMayBlock; |
| 2758 | PRINT("sys_ftruncate ( %d, %lld )", ARG1,(ULong)ARG2); |
| 2759 | PRE_REG_READ2(long, "ftruncate", unsigned int, fd, unsigned long, length); |
| 2760 | } |
| 2761 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2762 | PRE(sys_truncate) |
| 2763 | { |
| 2764 | *flags |= SfMayBlock; |
| 2765 | PRINT("sys_truncate ( %p(%s), %d )", ARG1,ARG1,ARG2); |
| 2766 | PRE_REG_READ2(long, "truncate", |
| 2767 | const char *, path, unsigned long, length); |
| 2768 | PRE_MEM_RASCIIZ( "truncate(path)", ARG1 ); |
| 2769 | } |
| 2770 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2771 | // XXX: this wrapper is only suitable for 32-bit platforms |
| 2772 | #if defined(VGP_x86_linux) |
| 2773 | PRE(sys_ftruncate64) |
| 2774 | { |
| 2775 | *flags |= SfMayBlock; |
| 2776 | PRINT("sys_ftruncate64 ( %d, %lld )", ARG1, LOHI64(ARG2,ARG3)); |
| 2777 | PRE_REG_READ3(long, "ftruncate64", |
| 2778 | unsigned int, fd, |
| 2779 | vki_u32, length_low32, vki_u32, length_high32); |
| 2780 | } |
| 2781 | #endif |
| 2782 | |
| 2783 | // XXX: this wrapper is only suitable for 32-bit platforms |
| 2784 | #if defined(VGP_x86_linux) |
| 2785 | PRE(sys_truncate64) |
| 2786 | { |
| 2787 | *flags |= SfMayBlock; |
| 2788 | PRINT("sys_truncate64 ( %p, %lld )", ARG1, LOHI64(ARG2, ARG3)); |
| 2789 | PRE_REG_READ3(long, "truncate64", |
| 2790 | const char *, path, |
| 2791 | vki_u32, length_low32, vki_u32, length_high32); |
| 2792 | PRE_MEM_RASCIIZ( "truncate64(path)", ARG1 ); |
| 2793 | } |
| 2794 | #endif |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2795 | |
| 2796 | PRE(sys_getdents) |
| 2797 | { |
| 2798 | *flags |= SfMayBlock; |
| 2799 | PRINT("sys_getdents ( %d, %p, %d )", ARG1,ARG2,ARG3); |
| 2800 | PRE_REG_READ3(long, "getdents", |
| 2801 | unsigned int, fd, struct linux_dirent *, dirp, |
| 2802 | unsigned int, count); |
| 2803 | PRE_MEM_WRITE( "getdents(dirp)", ARG2, ARG3 ); |
| 2804 | } |
| 2805 | |
| 2806 | POST(sys_getdents) |
| 2807 | { |
| 2808 | vg_assert(SUCCESS); |
| 2809 | if (RES > 0) |
| 2810 | POST_MEM_WRITE( ARG2, RES ); |
| 2811 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2812 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2813 | PRE(sys_getdents64) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2814 | { |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2815 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2816 | PRINT("sys_getdents64 ( %d, %p, %d )",ARG1,ARG2,ARG3); |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 2817 | PRE_REG_READ3(long, "getdents64", |
| 2818 | unsigned int, fd, struct linux_dirent64 *, dirp, |
| 2819 | unsigned int, count); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2820 | PRE_MEM_WRITE( "getdents64(dirp)", ARG2, ARG3 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2823 | POST(sys_getdents64) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2824 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2825 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2826 | if (RES > 0) |
| 2827 | POST_MEM_WRITE( ARG2, RES ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2830 | PRE(sys_getgroups16) |
| 2831 | { |
| 2832 | PRINT("sys_getgroups16 ( %d, %p )", ARG1, ARG2); |
| 2833 | PRE_REG_READ2(long, "getgroups16", int, size, vki_old_gid_t *, list); |
| 2834 | if (ARG1 > 0) |
| 2835 | PRE_MEM_WRITE( "getgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) ); |
| 2836 | } |
| 2837 | |
| 2838 | POST(sys_getgroups16) |
| 2839 | { |
| 2840 | vg_assert(SUCCESS); |
| 2841 | if (ARG1 > 0 && RES > 0) |
| 2842 | POST_MEM_WRITE( ARG2, RES * sizeof(vki_old_gid_t) ); |
| 2843 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2844 | |
| 2845 | PRE(sys_getgroups) |
| 2846 | { |
| 2847 | PRINT("sys_getgroups ( %d, %p )", ARG1, ARG2); |
| 2848 | PRE_REG_READ2(long, "getgroups", int, size, vki_gid_t *, list); |
| 2849 | if (ARG1 > 0) |
| 2850 | PRE_MEM_WRITE( "getgroups(list)", ARG2, ARG1 * sizeof(vki_gid_t) ); |
| 2851 | } |
| 2852 | |
| 2853 | POST(sys_getgroups) |
| 2854 | { |
| 2855 | vg_assert(SUCCESS); |
| 2856 | if (ARG1 > 0 && RES > 0) |
| 2857 | POST_MEM_WRITE( ARG2, RES * sizeof(vki_gid_t) ); |
| 2858 | } |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 2859 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2860 | PRE(sys_getcwd) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2861 | { |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 2862 | // Note that the kernel version of getcwd() behaves quite differently to |
| 2863 | // the glibc one. |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2864 | PRINT("sys_getcwd ( %p, %llu )", ARG1,(ULong)ARG2); |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 2865 | PRE_REG_READ2(long, "getcwd", char *, buf, unsigned long, size); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2866 | PRE_MEM_WRITE( "getcwd(buf)", ARG1, ARG2 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2869 | POST(sys_getcwd) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2870 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2871 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2872 | if (RES != (Addr)NULL) |
| 2873 | POST_MEM_WRITE( ARG1, RES ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2876 | PRE(sys_geteuid16) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2877 | { |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 2878 | PRINT("sys_geteuid16 ( )"); |
| 2879 | PRE_REG_READ0(long, "geteuid16"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2882 | PRE(sys_geteuid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2883 | { |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 2884 | PRINT("sys_geteuid ( )"); |
| 2885 | PRE_REG_READ0(long, "geteuid"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2888 | PRE(sys_getegid16) |
| 2889 | { |
| 2890 | PRINT("sys_getegid16 ( )"); |
| 2891 | PRE_REG_READ0(long, "getegid16"); |
| 2892 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2893 | |
| 2894 | PRE(sys_getegid) |
| 2895 | { |
| 2896 | PRINT("sys_getegid ( )"); |
| 2897 | PRE_REG_READ0(long, "getegid"); |
| 2898 | } |
| 2899 | |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 2900 | PRE(sys_getgid16) |
| 2901 | { |
| 2902 | PRINT("sys_getgid16 ( )"); |
| 2903 | PRE_REG_READ0(long, "getgid16"); |
| 2904 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2905 | |
| 2906 | PRE(sys_getgid) |
| 2907 | { |
| 2908 | PRINT("sys_getgid ( )"); |
| 2909 | PRE_REG_READ0(long, "getgid"); |
| 2910 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2911 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2912 | PRE(sys_getpid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2913 | { |
nethercote | 4e632c2 | 2004-11-09 16:45:33 +0000 | [diff] [blame] | 2914 | PRINT("sys_getpid ()"); |
| 2915 | PRE_REG_READ0(long, "getpid"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2918 | PRE(sys_getpgid) |
| 2919 | { |
| 2920 | PRINT("sys_getpgid ( %d )", ARG1); |
| 2921 | PRE_REG_READ1(long, "getpgid", vki_pid_t, pid); |
| 2922 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2923 | |
| 2924 | PRE(sys_getpgrp) |
| 2925 | { |
| 2926 | PRINT("sys_getpgrp ()"); |
| 2927 | PRE_REG_READ0(long, "getpgrp"); |
| 2928 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2929 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2930 | PRE(sys_getppid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2931 | { |
nethercote | 4e632c2 | 2004-11-09 16:45:33 +0000 | [diff] [blame] | 2932 | PRINT("sys_getppid ()"); |
| 2933 | PRE_REG_READ0(long, "getppid"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 2936 | static void common_post_getrlimit(ThreadId tid, UWord a1, UWord a2) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2937 | { |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2938 | POST_MEM_WRITE( a2, sizeof(struct vki_rlimit) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2939 | |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2940 | switch (a1) { |
| 2941 | case VKI_RLIMIT_NOFILE: |
| 2942 | ((struct vki_rlimit *)a2)->rlim_cur = VG_(fd_soft_limit); |
| 2943 | ((struct vki_rlimit *)a2)->rlim_max = VG_(fd_hard_limit); |
| 2944 | break; |
nethercote | 535f03b | 2004-02-15 15:32:51 +0000 | [diff] [blame] | 2945 | |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2946 | case VKI_RLIMIT_DATA: |
| 2947 | *((struct vki_rlimit *)a2) = VG_(client_rlimit_data); |
| 2948 | break; |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 2949 | |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2950 | case VKI_RLIMIT_STACK: |
| 2951 | *((struct vki_rlimit *)a2) = VG_(client_rlimit_stack); |
| 2952 | break; |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 2953 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2956 | PRE(sys_old_getrlimit) |
| 2957 | { |
| 2958 | PRINT("sys_old_getrlimit ( %d, %p )", ARG1,ARG2); |
| 2959 | PRE_REG_READ2(long, "old_getrlimit", |
| 2960 | unsigned int, resource, struct rlimit *, rlim); |
| 2961 | PRE_MEM_WRITE( "old_getrlimit(rlim)", ARG2, sizeof(struct vki_rlimit) ); |
| 2962 | } |
| 2963 | |
| 2964 | POST(sys_old_getrlimit) |
| 2965 | { |
| 2966 | common_post_getrlimit(tid, ARG1, ARG2); |
| 2967 | } |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2968 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2969 | PRE(sys_getrlimit) |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2970 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2971 | PRINT("sys_getrlimit ( %d, %p )", ARG1,ARG2); |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2972 | PRE_REG_READ2(long, "getrlimit", |
| 2973 | unsigned int, resource, struct rlimit *, rlim); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2974 | PRE_MEM_WRITE( "getrlimit(rlim)", ARG2, sizeof(struct vki_rlimit) ); |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 2977 | POST(sys_getrlimit) |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2978 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2979 | common_post_getrlimit(tid, ARG1, ARG2); |
nethercote | 620154f | 2004-11-12 21:21:07 +0000 | [diff] [blame] | 2980 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2981 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2982 | PRE(sys_getrusage) |
| 2983 | { |
| 2984 | /* int getrusage (int who, struct rusage *usage); */ |
| 2985 | PRINT("sys_getrusage ( %d, %p )", ARG1,ARG2); |
| 2986 | PRE_REG_READ2(long, "getrusage", int, who, struct rusage *, usage); |
| 2987 | PRE_MEM_WRITE( "getrusage(usage)", ARG2, sizeof(struct vki_rusage) ); |
| 2988 | } |
| 2989 | |
| 2990 | POST(sys_getrusage) |
| 2991 | { |
| 2992 | vg_assert(SUCCESS); |
| 2993 | if (RES == 0) |
| 2994 | POST_MEM_WRITE( ARG2, sizeof(struct vki_rusage) ); |
| 2995 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2996 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2997 | PRE(sys_gettimeofday) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 2998 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 2999 | PRINT("sys_gettimeofday ( %p, %p )", ARG1,ARG2); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 3000 | PRE_REG_READ2(long, "gettimeofday", |
| 3001 | struct timeval *, tv, struct timezone *, tz); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3002 | PRE_MEM_WRITE( "gettimeofday(tv)", ARG1, sizeof(struct vki_timeval) ); |
| 3003 | if (ARG2 != 0) |
| 3004 | PRE_MEM_WRITE( "gettimeofday(tz)", ARG2, sizeof(struct vki_timezone) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 3007 | POST(sys_gettimeofday) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3008 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3009 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3010 | if (RES == 0) { |
| 3011 | POST_MEM_WRITE( ARG1, sizeof(struct vki_timeval) ); |
| 3012 | if (ARG2 != 0) |
| 3013 | POST_MEM_WRITE( ARG2, sizeof(struct vki_timezone) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3014 | } |
| 3015 | } |
| 3016 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 3017 | PRE(sys_settimeofday) |
| 3018 | { |
| 3019 | PRINT("sys_settimeofday ( %p, %p )", ARG1,ARG2); |
| 3020 | PRE_REG_READ2(long, "settimeofday", |
| 3021 | struct timeval *, tv, struct timezone *, tz); |
| 3022 | PRE_MEM_READ( "settimeofday(tv)", ARG1, sizeof(struct vki_timeval) ); |
| 3023 | if (ARG2 != 0) { |
| 3024 | PRE_MEM_READ( "settimeofday(tz)", ARG2, sizeof(struct vki_timezone) ); |
| 3025 | /* maybe should warn if tz->tz_dsttime is non-zero? */ |
| 3026 | } |
| 3027 | } |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 3028 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3029 | PRE(sys_getuid16) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3030 | { |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 3031 | PRINT("sys_getuid16 ( )"); |
| 3032 | PRE_REG_READ0(long, "getuid16"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3035 | PRE(sys_getuid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3036 | { |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 3037 | PRINT("sys_getuid ( )"); |
| 3038 | PRE_REG_READ0(long, "getuid"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
nethercote | 2e1c37d | 2004-11-13 13:57:12 +0000 | [diff] [blame] | 3041 | // XXX: I reckon some of these cases must be x86-specific |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3042 | PRE(sys_ioctl) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3043 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3044 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3045 | PRINT("sys_ioctl ( %d, 0x%x, %p )",ARG1,ARG2,ARG3); |
nethercote | 9c311eb | 2004-11-12 18:20:12 +0000 | [diff] [blame] | 3046 | PRE_REG_READ3(long, "ioctl", |
| 3047 | unsigned int, fd, unsigned int, request, unsigned long, arg); |
| 3048 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3049 | switch (ARG2 /* request */) { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3050 | case VKI_TCSETS: |
| 3051 | case VKI_TCSETSW: |
| 3052 | case VKI_TCSETSF: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3053 | PRE_MEM_READ( "ioctl(TCSET{S,SW,SF})", ARG3, sizeof(struct vki_termios) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3054 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3055 | case VKI_TCGETS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3056 | PRE_MEM_WRITE( "ioctl(TCGETS)", ARG3, sizeof(struct vki_termios) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3057 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3058 | case VKI_TCSETA: |
| 3059 | case VKI_TCSETAW: |
| 3060 | case VKI_TCSETAF: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3061 | PRE_MEM_READ( "ioctl(TCSET{A,AW,AF})", ARG3, sizeof(struct vki_termio) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3062 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3063 | case VKI_TCGETA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3064 | PRE_MEM_WRITE( "ioctl(TCGETA)", ARG3, sizeof(struct vki_termio) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3065 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3066 | case VKI_TCSBRK: |
| 3067 | case VKI_TCXONC: |
| 3068 | case VKI_TCSBRKP: |
| 3069 | case VKI_TCFLSH: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3070 | /* These just take an int by value */ |
| 3071 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3072 | case VKI_TIOCGWINSZ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3073 | PRE_MEM_WRITE( "ioctl(TIOCGWINSZ)", ARG3, sizeof(struct vki_winsize) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3074 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3075 | case VKI_TIOCSWINSZ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3076 | PRE_MEM_READ( "ioctl(TIOCSWINSZ)", ARG3, sizeof(struct vki_winsize) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3077 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3078 | case VKI_TIOCMBIS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3079 | PRE_MEM_READ( "ioctl(TIOCMBIS)", ARG3, sizeof(unsigned int) ); |
thughes | fc5cd00 | 2004-09-11 14:37:04 +0000 | [diff] [blame] | 3080 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3081 | case VKI_TIOCMBIC: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3082 | PRE_MEM_READ( "ioctl(TIOCMBIC)", ARG3, sizeof(unsigned int) ); |
thughes | fc5cd00 | 2004-09-11 14:37:04 +0000 | [diff] [blame] | 3083 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3084 | case VKI_TIOCMSET: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3085 | PRE_MEM_READ( "ioctl(TIOCMSET)", ARG3, sizeof(unsigned int) ); |
thughes | fc5cd00 | 2004-09-11 14:37:04 +0000 | [diff] [blame] | 3086 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3087 | case VKI_TIOCLINUX: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3088 | PRE_MEM_READ( "ioctl(TIOCLINUX)", ARG3, sizeof(char *) ); |
| 3089 | if (*(char *)ARG3 == 11) { |
| 3090 | PRE_MEM_READ( "ioctl(TIOCLINUX, 11)", ARG3, 2 * sizeof(char *) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3091 | } |
| 3092 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3093 | case VKI_TIOCGPGRP: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3094 | /* Get process group ID for foreground processing group. */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3095 | PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3096 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3097 | case VKI_TIOCSPGRP: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3098 | /* Set a process group ID? */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3099 | PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3100 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3101 | case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3102 | PRE_MEM_WRITE( "ioctl(TIOCGPTN)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3103 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3104 | case VKI_TIOCSCTTY: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3105 | /* Just takes an int value. */ |
| 3106 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3107 | case VKI_TIOCSPTLCK: /* Lock/unlock Pty */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3108 | PRE_MEM_READ( "ioctl(TIOCSPTLCK)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3109 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3110 | case VKI_FIONBIO: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3111 | PRE_MEM_READ( "ioctl(FIONBIO)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3112 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3113 | case VKI_FIOASYNC: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3114 | PRE_MEM_READ( "ioctl(FIOASYNC)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3115 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3116 | case VKI_FIONREAD: /* identical to SIOCINQ */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3117 | PRE_MEM_WRITE( "ioctl(FIONREAD)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3118 | break; |
| 3119 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3120 | case VKI_SG_SET_COMMAND_Q: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3121 | PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3122 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3123 | case VKI_SG_IO: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3124 | PRE_MEM_WRITE( "ioctl(SG_IO)", ARG3, sizeof(vki_sg_io_hdr_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3125 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3126 | case VKI_SG_GET_SCSI_ID: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3127 | PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3, sizeof(vki_sg_scsi_id_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3128 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3129 | case VKI_SG_SET_RESERVED_SIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3130 | PRE_MEM_READ( "ioctl(SG_SET_RESERVED_SIZE)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3131 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3132 | case VKI_SG_SET_TIMEOUT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3133 | PRE_MEM_READ( "ioctl(SG_SET_TIMEOUT)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3134 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3135 | case VKI_SG_GET_RESERVED_SIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3136 | PRE_MEM_WRITE( "ioctl(SG_GET_RESERVED_SIZE)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3137 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3138 | case VKI_SG_GET_TIMEOUT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3139 | PRE_MEM_WRITE( "ioctl(SG_GET_TIMEOUT)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3140 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3141 | case VKI_SG_GET_VERSION_NUM: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3142 | PRE_MEM_READ( "ioctl(SG_GET_VERSION_NUM)", ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3143 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3144 | case VKI_SG_EMULATED_HOST: /* 0x2203 */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3145 | PRE_MEM_WRITE( "ioctl(SG_EMULATED_HOST)", ARG3, sizeof(int) ); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3146 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3147 | case VKI_SG_GET_SG_TABLESIZE: /* 0x227f */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3148 | PRE_MEM_WRITE( "ioctl(SG_GET_SG_TABLESIZE)", ARG3, sizeof(int) ); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3149 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3150 | |
mueller | a4b153a | 2003-11-19 22:07:14 +0000 | [diff] [blame] | 3151 | case VKI_IIOCGETCPS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3152 | PRE_MEM_WRITE( "ioctl(IIOCGETCPS)", ARG3, |
nethercote | 95a9786 | 2004-11-06 16:31:43 +0000 | [diff] [blame] | 3153 | VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3154 | break; |
mueller | a4b153a | 2003-11-19 22:07:14 +0000 | [diff] [blame] | 3155 | case VKI_IIOCNETGPN: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3156 | PRE_MEM_READ( "ioctl(IIOCNETGPN)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3157 | (Addr)&((vki_isdn_net_ioctl_phone *)ARG3)->name, |
| 3158 | sizeof(((vki_isdn_net_ioctl_phone *)ARG3)->name) ); |
| 3159 | PRE_MEM_WRITE( "ioctl(IIOCNETGPN)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3160 | sizeof(vki_isdn_net_ioctl_phone) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3161 | break; |
| 3162 | |
| 3163 | /* These all use struct ifreq AFAIK */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3164 | case VKI_SIOCGIFINDEX: /* get iface index */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3165 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFINDEX)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3166 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3167 | PRE_MEM_WRITE( "ioctl(SIOCGIFINDEX)", ARG3, sizeof(struct vki_ifreq)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3168 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3169 | case VKI_SIOCGIFFLAGS: /* get flags */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3170 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFFLAGS)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3171 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3172 | PRE_MEM_WRITE( "ioctl(SIOCGIFFLAGS)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3173 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3174 | case VKI_SIOCGIFHWADDR: /* Get hardware address */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3175 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFHWADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3176 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3177 | PRE_MEM_WRITE( "ioctl(SIOCGIFHWADDR)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3178 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3179 | case VKI_SIOCGIFMTU: /* get MTU size */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3180 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMTU)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3181 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3182 | PRE_MEM_WRITE( "ioctl(SIOCGIFMTU)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3183 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3184 | case VKI_SIOCGIFADDR: /* get PA address */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3185 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3186 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3187 | PRE_MEM_WRITE( "ioctl(SIOCGIFADDR)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3188 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3189 | case VKI_SIOCGIFNETMASK: /* get network PA mask */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3190 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFNETMASK)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3191 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3192 | PRE_MEM_WRITE( "ioctl(SIOCGIFNETMASK)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3193 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3194 | case VKI_SIOCGIFMETRIC: /* get metric */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3195 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMETRIC)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3196 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3197 | PRE_MEM_WRITE( "ioctl(SIOCGIFMETRIC)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3198 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3199 | case VKI_SIOCGIFMAP: /* Get device parameters */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3200 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMAP)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3201 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3202 | PRE_MEM_WRITE( "ioctl(SIOCGIFMAP)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3203 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3204 | case VKI_SIOCGIFTXQLEN: /* Get the tx queue length */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3205 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFTXQLEN)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3206 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3207 | PRE_MEM_WRITE( "ioctl(SIOCGIFTXQLEN)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3208 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3209 | case VKI_SIOCGIFDSTADDR: /* get remote PA address */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3210 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFDSTADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3211 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3212 | PRE_MEM_WRITE( "ioctl(SIOCGIFDSTADDR)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3213 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3214 | case VKI_SIOCGIFBRDADDR: /* get broadcast PA address */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3215 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFBRDADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3216 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3217 | PRE_MEM_WRITE( "ioctl(SIOCGIFBRDADDR)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3218 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3219 | case VKI_SIOCGIFNAME: /* get iface name */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3220 | PRE_MEM_READ( "ioctl(SIOCGIFNAME)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3221 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_ifindex, |
| 3222 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) ); |
| 3223 | PRE_MEM_WRITE( "ioctl(SIOCGIFNAME)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3224 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3225 | case VKI_SIOCGMIIPHY: /* get hardware entry */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3226 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIPHY)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3227 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
| 3228 | PRE_MEM_WRITE( "ioctl(SIOCGIFMIIPHY)", ARG3, sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3229 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3230 | case VKI_SIOCGMIIREG: /* get hardware entry registers */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3231 | PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3232 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3233 | PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3234 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, |
| 3235 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3236 | PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3237 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num, |
| 3238 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) ); |
| 3239 | PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3240 | sizeof(struct vki_ifreq)); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3241 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3242 | case VKI_SIOCGIFCONF: /* get iface list */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3243 | /* WAS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3244 | PRE_MEM_WRITE( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf)); |
| 3245 | KERNEL_DO_SYSCALL(tid,RES); |
| 3246 | if (!VG_(is_kerror)(RES) && RES == 0) |
| 3247 | POST_MEM_WRITE(ARG3, sizeof(struct ifconf)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3248 | */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3249 | PRE_MEM_READ( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct vki_ifconf)); |
| 3250 | if ( ARG3 ) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3251 | // TODO len must be readable and writable |
| 3252 | // buf pointer only needs to be readable |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3253 | struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3254 | PRE_MEM_WRITE( "ioctl(SIOCGIFCONF).ifc_buf", |
nethercote | 50397c2 | 2004-11-04 18:03:06 +0000 | [diff] [blame] | 3255 | (Addr)(ifc->vki_ifc_buf), ifc->ifc_len ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3256 | } |
| 3257 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3258 | case VKI_SIOCGSTAMP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3259 | PRE_MEM_WRITE( "ioctl(SIOCGSTAMP)", ARG3, sizeof(struct vki_timeval)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3260 | break; |
| 3261 | /* SIOCOUTQ is an ioctl that, when called on a socket, returns |
| 3262 | the number of bytes currently in that socket's send buffer. |
| 3263 | It writes this value as an int to the memory location |
| 3264 | indicated by the third argument of ioctl(2). */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3265 | case VKI_SIOCOUTQ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3266 | PRE_MEM_WRITE( "ioctl(SIOCOUTQ)", ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3267 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3268 | case VKI_SIOCGRARP: /* get RARP table entry */ |
| 3269 | case VKI_SIOCGARP: /* get ARP table entry */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3270 | PRE_MEM_WRITE( "ioctl(SIOCGARP)", ARG3, sizeof(struct vki_arpreq)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3271 | break; |
| 3272 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3273 | case VKI_SIOCSIFFLAGS: /* set flags */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3274 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFFLAGS)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3275 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3276 | PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3277 | (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, |
| 3278 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3279 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3280 | case VKI_SIOCSIFMAP: /* Set device parameters */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3281 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMAP)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3282 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3283 | PRE_MEM_READ( "ioctl(SIOCSIFMAP)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3284 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_map, |
| 3285 | sizeof(((struct vki_ifreq *)ARG3)->ifr_map) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3286 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3287 | case VKI_SIOCSIFTXQLEN: /* Set the tx queue length */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3288 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFTXQLEN)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3289 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3290 | PRE_MEM_READ( "ioctl(SIOCSIFTXQLEN)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3291 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_qlen, |
| 3292 | sizeof(((struct vki_ifreq *)ARG3)->ifr_qlen) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3293 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3294 | case VKI_SIOCSIFADDR: /* set PA address */ |
| 3295 | case VKI_SIOCSIFDSTADDR: /* set remote PA address */ |
| 3296 | case VKI_SIOCSIFBRDADDR: /* set broadcast PA address */ |
| 3297 | case VKI_SIOCSIFNETMASK: /* set network PA mask */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3298 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIF*ADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3299 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3300 | PRE_MEM_READ( "ioctl(SIOCSIF*ADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3301 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_addr, |
| 3302 | sizeof(((struct vki_ifreq *)ARG3)->ifr_addr) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3303 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3304 | case VKI_SIOCSIFMETRIC: /* set metric */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3305 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMETRIC)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3306 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3307 | PRE_MEM_READ( "ioctl(SIOCSIFMETRIC)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3308 | (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric, |
| 3309 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3310 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3311 | case VKI_SIOCSIFMTU: /* set MTU size */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3312 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMTU)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3313 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3314 | PRE_MEM_READ( "ioctl(SIOCSIFMTU)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3315 | (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu, |
| 3316 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3317 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3318 | case VKI_SIOCSIFHWADDR: /* set hardware address */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3319 | PRE_MEM_RASCIIZ( "ioctl(SIOCSIFHWADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3320 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3321 | PRE_MEM_READ( "ioctl(SIOCSIFHWADDR)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3322 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_hwaddr, |
| 3323 | sizeof(((struct vki_ifreq *)ARG3)->ifr_hwaddr) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3324 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3325 | case VKI_SIOCSMIIREG: /* set hardware entry registers */ |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3326 | PRE_MEM_RASCIIZ( "ioctl(SIOCSMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3327 | (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3328 | PRE_MEM_READ( "ioctl(SIOCSMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3329 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, |
| 3330 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3331 | PRE_MEM_READ( "ioctl(SIOCSMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3332 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num, |
| 3333 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) ); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3334 | PRE_MEM_READ( "ioctl(SIOCSMIIREG)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3335 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in, |
| 3336 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3337 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3338 | /* Routing table calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3339 | case VKI_SIOCADDRT: /* add routing table entry */ |
| 3340 | case VKI_SIOCDELRT: /* delete routing table entry */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3341 | PRE_MEM_READ( "ioctl(SIOCADDRT/DELRT)", ARG3, |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3342 | sizeof(struct vki_rtentry)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3343 | break; |
| 3344 | |
| 3345 | /* RARP cache control calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3346 | case VKI_SIOCDRARP: /* delete RARP table entry */ |
| 3347 | case VKI_SIOCSRARP: /* set RARP table entry */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3348 | /* ARP cache control calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3349 | case VKI_SIOCSARP: /* set ARP table entry */ |
| 3350 | case VKI_SIOCDARP: /* delete ARP table entry */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3351 | PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", ARG3, sizeof(struct vki_ifreq)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3352 | break; |
| 3353 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3354 | case VKI_SIOCGPGRP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3355 | PRE_MEM_WRITE( "ioctl(SIOCGPGRP)", ARG3, sizeof(int) ); |
thughes | 1174fed | 2004-09-11 15:33:17 +0000 | [diff] [blame] | 3356 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3357 | case VKI_SIOCSPGRP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3358 | PRE_MEM_READ( "ioctl(SIOCSPGRP)", ARG3, sizeof(int) ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3359 | //tst->sys_flags &= ~SfMayBlock; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3360 | break; |
| 3361 | |
| 3362 | /* linux/soundcard interface (OSS) */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3363 | case VKI_SNDCTL_SEQ_GETOUTCOUNT: |
| 3364 | case VKI_SNDCTL_SEQ_GETINCOUNT: |
| 3365 | case VKI_SNDCTL_SEQ_PERCMODE: |
| 3366 | case VKI_SNDCTL_SEQ_TESTMIDI: |
| 3367 | case VKI_SNDCTL_SEQ_RESETSAMPLES: |
| 3368 | case VKI_SNDCTL_SEQ_NRSYNTHS: |
| 3369 | case VKI_SNDCTL_SEQ_NRMIDIS: |
| 3370 | case VKI_SNDCTL_SEQ_GETTIME: |
| 3371 | case VKI_SNDCTL_DSP_GETFMTS: |
| 3372 | case VKI_SNDCTL_DSP_GETTRIGGER: |
| 3373 | case VKI_SNDCTL_DSP_GETODELAY: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3374 | case VKI_SNDCTL_DSP_GETSPDIF: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3375 | case VKI_SNDCTL_DSP_GETCAPS: |
| 3376 | case VKI_SOUND_PCM_READ_RATE: |
| 3377 | case VKI_SOUND_PCM_READ_CHANNELS: |
| 3378 | case VKI_SOUND_PCM_READ_BITS: |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 3379 | #if !defined(VGA_ppc32) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3380 | case (VKI_SOUND_PCM_READ_BITS|0x40000000): /* what the fuck ? */ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 3381 | #endif |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3382 | case VKI_SOUND_PCM_READ_FILTER: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3383 | PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, int))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3384 | ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3385 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3386 | case VKI_SNDCTL_SEQ_CTRLRATE: |
| 3387 | case VKI_SNDCTL_DSP_SPEED: |
| 3388 | case VKI_SNDCTL_DSP_STEREO: |
| 3389 | case VKI_SNDCTL_DSP_GETBLKSIZE: |
| 3390 | case VKI_SNDCTL_DSP_CHANNELS: |
| 3391 | case VKI_SOUND_PCM_WRITE_FILTER: |
| 3392 | case VKI_SNDCTL_DSP_SUBDIVIDE: |
| 3393 | case VKI_SNDCTL_DSP_SETFRAGMENT: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3394 | case VKI_SNDCTL_DSP_GETCHANNELMASK: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3395 | case VKI_SNDCTL_DSP_BIND_CHANNEL: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3396 | case VKI_SNDCTL_TMR_TIMEBASE: |
| 3397 | case VKI_SNDCTL_TMR_TEMPO: |
| 3398 | case VKI_SNDCTL_TMR_SOURCE: |
| 3399 | case VKI_SNDCTL_MIDI_PRETIME: |
| 3400 | case VKI_SNDCTL_MIDI_MPUMODE: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3401 | PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3402 | ARG3, sizeof(int)); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3403 | PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3404 | ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3405 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3406 | case VKI_SNDCTL_DSP_GETOSPACE: |
| 3407 | case VKI_SNDCTL_DSP_GETISPACE: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3408 | PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, audio_buf_info))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3409 | ARG3, sizeof(vki_audio_buf_info)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3410 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3411 | case VKI_SNDCTL_DSP_SETTRIGGER: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3412 | PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOW, int))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3413 | ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3414 | break; |
| 3415 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3416 | case VKI_SNDCTL_DSP_POST: |
| 3417 | case VKI_SNDCTL_DSP_RESET: |
| 3418 | case VKI_SNDCTL_DSP_SYNC: |
| 3419 | case VKI_SNDCTL_DSP_SETSYNCRO: |
| 3420 | case VKI_SNDCTL_DSP_SETDUPLEX: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | |
| 3423 | /* Real Time Clock (/dev/rtc) ioctls */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3424 | case VKI_RTC_UIE_ON: |
| 3425 | case VKI_RTC_UIE_OFF: |
| 3426 | case VKI_RTC_AIE_ON: |
| 3427 | case VKI_RTC_AIE_OFF: |
| 3428 | case VKI_RTC_PIE_ON: |
| 3429 | case VKI_RTC_PIE_OFF: |
| 3430 | case VKI_RTC_IRQP_SET: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3431 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3432 | case VKI_RTC_RD_TIME: |
| 3433 | case VKI_RTC_ALM_READ: |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3434 | PRE_MEM_WRITE( "ioctl(RTC_RD_TIME/ALM_READ)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3435 | ARG3, sizeof(struct vki_rtc_time)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3436 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3437 | case VKI_RTC_ALM_SET: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3438 | PRE_MEM_READ( "ioctl(RTC_ALM_SET)", ARG3, sizeof(struct vki_rtc_time)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3439 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3440 | case VKI_RTC_IRQP_READ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3441 | PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3, sizeof(unsigned long)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3442 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3443 | |
nethercote | 95a9786 | 2004-11-06 16:31:43 +0000 | [diff] [blame] | 3444 | case VKI_BLKGETSIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3445 | PRE_MEM_WRITE( "ioctl(BLKGETSIZE)", ARG3, sizeof(unsigned long)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3446 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3447 | |
thughes | acbbc32 | 2004-06-19 12:12:01 +0000 | [diff] [blame] | 3448 | /* Hard disks */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3449 | case VKI_HDIO_GET_IDENTITY: /* 0x030d */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3450 | PRE_MEM_WRITE( "ioctl(HDIO_GET_IDENTITY)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3451 | VKI_SIZEOF_STRUCT_HD_DRIVEID ); |
thughes | acbbc32 | 2004-06-19 12:12:01 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3454 | /* CD ROM stuff (??) */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3455 | case VKI_CDROM_GET_MCN: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3456 | PRE_MEM_READ( "ioctl(CDROM_GET_MCN)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3457 | sizeof(struct vki_cdrom_mcn) ); |
nethercote | 671398c | 2004-02-22 18:08:04 +0000 | [diff] [blame] | 3458 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3459 | case VKI_CDROM_SEND_PACKET: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3460 | PRE_MEM_READ( "ioctl(CDROM_SEND_PACKET)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3461 | sizeof(struct vki_cdrom_generic_command)); |
nethercote | 671398c | 2004-02-22 18:08:04 +0000 | [diff] [blame] | 3462 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3463 | case VKI_CDROMSUBCHNL: |
nethercote | 11e07d3 | 2004-11-06 16:17:52 +0000 | [diff] [blame] | 3464 | PRE_MEM_READ( "ioctl(CDROMSUBCHNL (cdsc_format, char))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3465 | (Addr) &(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format), |
| 3466 | sizeof(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format)); |
| 3467 | PRE_MEM_WRITE( "ioctl(CDROMSUBCHNL)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3468 | sizeof(struct vki_cdrom_subchnl)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3469 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3470 | case VKI_CDROMREADMODE2: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3471 | PRE_MEM_READ( "ioctl(CDROMREADMODE2)", ARG3, VKI_CD_FRAMESIZE_RAW0 ); |
nethercote | 671398c | 2004-02-22 18:08:04 +0000 | [diff] [blame] | 3472 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3473 | case VKI_CDROMREADTOCHDR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3474 | PRE_MEM_WRITE( "ioctl(CDROMREADTOCHDR)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3475 | sizeof(struct vki_cdrom_tochdr)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3476 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3477 | case VKI_CDROMREADTOCENTRY: |
nethercote | 11e07d3 | 2004-11-06 16:17:52 +0000 | [diff] [blame] | 3478 | PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_format, char))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3479 | (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_format), |
| 3480 | sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_format)); |
nethercote | 11e07d3 | 2004-11-06 16:17:52 +0000 | [diff] [blame] | 3481 | PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_track, char))", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3482 | (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_track), |
| 3483 | sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_track)); |
| 3484 | PRE_MEM_WRITE( "ioctl(CDROMREADTOCENTRY)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3485 | sizeof(struct vki_cdrom_tocentry)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3486 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3487 | case VKI_CDROMMULTISESSION: /* 0x5310 */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3488 | PRE_MEM_WRITE( "ioctl(CDROMMULTISESSION)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3489 | sizeof(struct vki_cdrom_multisession)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3490 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3491 | case VKI_CDROMVOLREAD: /* 0x5313 */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3492 | PRE_MEM_WRITE( "ioctl(CDROMVOLREAD)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3493 | sizeof(struct vki_cdrom_volctrl)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3494 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3495 | case VKI_CDROMREADAUDIO: /* 0x530e */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3496 | PRE_MEM_READ( "ioctl(CDROMREADAUDIO)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3497 | sizeof (struct vki_cdrom_read_audio)); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3498 | if ( ARG3 ) { |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3499 | /* ToDo: don't do any of the following if the structure is invalid */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3500 | struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3501 | PRE_MEM_WRITE( "ioctl(CDROMREADAUDIO).buf", |
| 3502 | (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3503 | } |
| 3504 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3505 | case VKI_CDROMPLAYMSF: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3506 | PRE_MEM_READ( "ioctl(CDROMPLAYMSF)", ARG3, sizeof(struct vki_cdrom_msf)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3507 | break; |
| 3508 | /* The following two are probably bogus (should check args |
| 3509 | for readability). JRS 20021117 */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3510 | case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */ |
| 3511 | case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3512 | break; |
thughes | 66d8009 | 2004-06-19 12:41:05 +0000 | [diff] [blame] | 3513 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3514 | case VKI_FIGETBSZ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3515 | PRE_MEM_WRITE( "ioctl(FIGETBSZ)", ARG3, sizeof(unsigned long)); |
thughes | 66d8009 | 2004-06-19 12:41:05 +0000 | [diff] [blame] | 3516 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3517 | case VKI_FIBMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3518 | PRE_MEM_READ( "ioctl(FIBMAP)", ARG3, sizeof(unsigned long)); |
thughes | 66d8009 | 2004-06-19 12:41:05 +0000 | [diff] [blame] | 3519 | break; |
| 3520 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3521 | case VKI_FBIOGET_VSCREENINFO: /* 0x4600 */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3522 | PRE_MEM_WRITE( "ioctl(FBIOGET_VSCREENINFO)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3523 | sizeof(struct vki_fb_var_screeninfo)); |
thughes | 44e3558 | 2004-04-21 15:52:33 +0000 | [diff] [blame] | 3524 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3525 | case VKI_FBIOGET_FSCREENINFO: /* 0x4602 */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3526 | PRE_MEM_WRITE( "ioctl(FBIOGET_FSCREENINFO)", ARG3, |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3527 | sizeof(struct vki_fb_fix_screeninfo)); |
thughes | 44e3558 | 2004-04-21 15:52:33 +0000 | [diff] [blame] | 3528 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3529 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3530 | case VKI_PPCLAIM: |
| 3531 | case VKI_PPEXCL: |
| 3532 | case VKI_PPYIELD: |
| 3533 | case VKI_PPRELEASE: |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3534 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3535 | case VKI_PPSETMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3536 | PRE_MEM_READ( "ioctl(PPSETMODE)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3537 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3538 | case VKI_PPGETMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3539 | PRE_MEM_WRITE( "ioctl(PPGETMODE)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3540 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3541 | case VKI_PPSETPHASE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3542 | PRE_MEM_READ( "ioctl(PPSETPHASE)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3543 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3544 | case VKI_PPGETPHASE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3545 | PRE_MEM_WRITE( "ioctl(PPGETPHASE)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3546 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3547 | case VKI_PPGETMODES: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3548 | PRE_MEM_WRITE( "ioctl(PPGETMODES)", ARG3, sizeof(unsigned int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3549 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3550 | case VKI_PPSETFLAGS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3551 | PRE_MEM_READ( "ioctl(PPSETFLAGS)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3552 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3553 | case VKI_PPGETFLAGS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3554 | PRE_MEM_WRITE( "ioctl(PPGETFLAGS)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3555 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3556 | case VKI_PPRSTATUS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3557 | PRE_MEM_WRITE( "ioctl(PPRSTATUS)", ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3558 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3559 | case VKI_PPRDATA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3560 | PRE_MEM_WRITE( "ioctl(PPRDATA)", ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3561 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3562 | case VKI_PPRCONTROL: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3563 | PRE_MEM_WRITE( "ioctl(PPRCONTROL)", ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3564 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3565 | case VKI_PPWDATA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3566 | PRE_MEM_READ( "ioctl(PPWDATA)", ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3567 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3568 | case VKI_PPWCONTROL: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3569 | PRE_MEM_READ( "ioctl(PPWCONTROL)", ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3570 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3571 | case VKI_PPFCONTROL: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3572 | PRE_MEM_READ( "ioctl(PPFCONTROL)", ARG3, 2 * sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3573 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3574 | case VKI_PPDATADIR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3575 | PRE_MEM_READ( "ioctl(PPDATADIR)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3576 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3577 | case VKI_PPNEGOT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3578 | PRE_MEM_READ( "ioctl(PPNEGOT)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3579 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3580 | case VKI_PPWCTLONIRQ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3581 | PRE_MEM_READ( "ioctl(PPWCTLONIRQ)",ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3582 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3583 | case VKI_PPCLRIRQ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3584 | PRE_MEM_WRITE( "ioctl(PPCLRIRQ)", ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3585 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3586 | case VKI_PPSETTIME: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3587 | PRE_MEM_READ( "ioctl(PPSETTIME)", ARG3, sizeof(struct vki_timeval) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3588 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3589 | case VKI_PPGETTIME: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3590 | PRE_MEM_WRITE( "ioctl(PPGETTIME)", ARG3, sizeof(struct vki_timeval) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 3591 | break; |
| 3592 | |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3593 | case VKI_GIO_FONT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3594 | PRE_MEM_WRITE( "ioctl(GIO_FONT)", ARG3, 32 * 256 ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | case VKI_PIO_FONT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3597 | PRE_MEM_READ( "ioctl(PIO_FONT)", ARG3, 32 * 256 ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3598 | break; |
| 3599 | |
| 3600 | case VKI_GIO_FONTX: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3601 | PRE_MEM_READ( "ioctl(GIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) ); |
| 3602 | if ( ARG3 ) { |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3603 | /* ToDo: don't do any of the following if the structure is invalid */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3604 | struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3; |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3605 | PRE_MEM_WRITE( "ioctl(GIO_FONTX).chardata", (Addr)cfd->chardata, |
| 3606 | 32 * cfd->charcount ); |
| 3607 | } |
| 3608 | break; |
| 3609 | case VKI_PIO_FONTX: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3610 | PRE_MEM_READ( "ioctl(PIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) ); |
| 3611 | if ( ARG3 ) { |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3612 | /* ToDo: don't do any of the following if the structure is invalid */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3613 | struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3; |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3614 | PRE_MEM_READ( "ioctl(PIO_FONTX).chardata", (Addr)cfd->chardata, |
| 3615 | 32 * cfd->charcount ); |
| 3616 | } |
| 3617 | break; |
| 3618 | |
| 3619 | case VKI_PIO_FONTRESET: |
| 3620 | break; |
| 3621 | |
| 3622 | case VKI_GIO_CMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3623 | PRE_MEM_WRITE( "ioctl(GIO_CMAP)", ARG3, 16 * 3 ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3624 | break; |
| 3625 | case VKI_PIO_CMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3626 | PRE_MEM_READ( "ioctl(PIO_CMAP)", ARG3, 16 * 3 ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3627 | break; |
| 3628 | |
| 3629 | case VKI_KIOCSOUND: |
| 3630 | case VKI_KDMKTONE: |
| 3631 | break; |
| 3632 | |
| 3633 | case VKI_KDGETLED: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3634 | PRE_MEM_WRITE( "ioctl(KDGETLED)", ARG3, sizeof(char) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | case VKI_KDSETLED: |
| 3637 | break; |
| 3638 | |
| 3639 | case VKI_KDGKBTYPE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3640 | PRE_MEM_WRITE( "ioctl(KDGKBTYPE)", ARG3, sizeof(char) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3641 | break; |
| 3642 | |
| 3643 | case VKI_KDADDIO: |
| 3644 | case VKI_KDDELIO: |
| 3645 | case VKI_KDENABIO: |
| 3646 | case VKI_KDDISABIO: |
| 3647 | break; |
| 3648 | |
| 3649 | case VKI_KDSETMODE: |
| 3650 | break; |
| 3651 | case VKI_KDGETMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3652 | PRE_MEM_WRITE( "ioctl(KDGETMODE)", ARG3, sizeof(int) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3653 | break; |
| 3654 | |
| 3655 | case VKI_KDMAPDISP: |
| 3656 | case VKI_KDUNMAPDISP: |
| 3657 | break; |
| 3658 | |
| 3659 | case VKI_GIO_SCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3660 | PRE_MEM_WRITE( "ioctl(GIO_SCRNMAP)", ARG3, VKI_E_TABSZ ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3661 | break; |
| 3662 | case VKI_PIO_SCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3663 | PRE_MEM_READ( "ioctl(PIO_SCRNMAP)", ARG3, VKI_E_TABSZ ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | case VKI_GIO_UNISCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3666 | PRE_MEM_WRITE( "ioctl(GIO_UNISCRNMAP)", ARG3, |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3667 | VKI_E_TABSZ * sizeof(unsigned short) ); |
| 3668 | break; |
| 3669 | case VKI_PIO_UNISCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3670 | PRE_MEM_READ( "ioctl(PIO_UNISCRNMAP)", ARG3, |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3671 | VKI_E_TABSZ * sizeof(unsigned short) ); |
| 3672 | break; |
| 3673 | |
| 3674 | case VKI_KDGKBMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3675 | PRE_MEM_WRITE( "ioctl(KDGKBMODE)", ARG3, sizeof(int) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3676 | break; |
| 3677 | case VKI_KDSKBMODE: |
| 3678 | break; |
| 3679 | |
| 3680 | case VKI_KDGKBMETA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3681 | PRE_MEM_WRITE( "ioctl(KDGKBMETA)", ARG3, sizeof(int) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3682 | break; |
| 3683 | case VKI_KDSKBMETA: |
| 3684 | break; |
| 3685 | |
| 3686 | case VKI_KDGKBLED: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3687 | PRE_MEM_WRITE( "ioctl(KDGKBLED)", ARG3, sizeof(char) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | case VKI_KDSKBLED: |
| 3690 | break; |
| 3691 | |
| 3692 | case VKI_KDGKBENT: |
| 3693 | PRE_MEM_READ( "ioctl(KDGKBENT).kb_table", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3694 | (Addr)&((struct vki_kbentry *)ARG3)->kb_table, |
| 3695 | sizeof(((struct vki_kbentry *)ARG3)->kb_table) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3696 | PRE_MEM_READ( "ioctl(KDGKBENT).kb_index", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3697 | (Addr)&((struct vki_kbentry *)ARG3)->kb_index, |
| 3698 | sizeof(((struct vki_kbentry *)ARG3)->kb_index) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3699 | PRE_MEM_WRITE( "ioctl(KDGKBENT).kb_value", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3700 | (Addr)&((struct vki_kbentry *)ARG3)->kb_value, |
| 3701 | sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3702 | break; |
| 3703 | case VKI_KDSKBENT: |
| 3704 | PRE_MEM_READ( "ioctl(KDSKBENT).kb_table", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3705 | (Addr)&((struct vki_kbentry *)ARG3)->kb_table, |
| 3706 | sizeof(((struct vki_kbentry *)ARG3)->kb_table) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3707 | PRE_MEM_READ( "ioctl(KDSKBENT).kb_index", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3708 | (Addr)&((struct vki_kbentry *)ARG3)->kb_index, |
| 3709 | sizeof(((struct vki_kbentry *)ARG3)->kb_index) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3710 | PRE_MEM_READ( "ioctl(KDSKBENT).kb_value", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3711 | (Addr)&((struct vki_kbentry *)ARG3)->kb_value, |
| 3712 | sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3713 | break; |
| 3714 | |
| 3715 | case VKI_KDGKBSENT: |
| 3716 | PRE_MEM_READ( "ioctl(KDGKBSENT).kb_func", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3717 | (Addr)&((struct vki_kbsentry *)ARG3)->kb_func, |
| 3718 | sizeof(((struct vki_kbsentry *)ARG3)->kb_func) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3719 | PRE_MEM_WRITE( "ioctl(KDGKSENT).kb_string", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3720 | (Addr)((struct vki_kbsentry *)ARG3)->kb_string, |
| 3721 | sizeof(((struct vki_kbsentry *)ARG3)->kb_string) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3722 | break; |
| 3723 | case VKI_KDSKBSENT: |
| 3724 | PRE_MEM_READ( "ioctl(KDSKBSENT).kb_func", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3725 | (Addr)&((struct vki_kbsentry *)ARG3)->kb_func, |
| 3726 | sizeof(((struct vki_kbsentry *)ARG3)->kb_func) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3727 | PRE_MEM_RASCIIZ( "ioctl(KDSKBSENT).kb_string", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3728 | (Addr)((struct vki_kbsentry *)ARG3)->kb_string ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3729 | break; |
| 3730 | |
| 3731 | case VKI_KDGKBDIACR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3732 | PRE_MEM_WRITE( "ioctl(KDGKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3733 | break; |
| 3734 | case VKI_KDSKBDIACR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3735 | PRE_MEM_READ( "ioctl(KDSKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | |
| 3738 | case VKI_KDGETKEYCODE: |
| 3739 | PRE_MEM_READ( "ioctl(KDGETKEYCODE).scancode", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3740 | (Addr)&((struct vki_kbkeycode *)ARG3)->scancode, |
| 3741 | sizeof(((struct vki_kbkeycode *)ARG3)->scancode) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3742 | PRE_MEM_WRITE( "ioctl(KDGETKEYCODE).keycode", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3743 | (Addr)((struct vki_kbkeycode *)ARG3)->keycode, |
| 3744 | sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3745 | break; |
| 3746 | case VKI_KDSETKEYCODE: |
| 3747 | PRE_MEM_READ( "ioctl(KDSETKEYCODE).scancode", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3748 | (Addr)&((struct vki_kbkeycode *)ARG3)->scancode, |
| 3749 | sizeof(((struct vki_kbkeycode *)ARG3)->scancode) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3750 | PRE_MEM_READ( "ioctl(KDSETKEYCODE).keycode", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3751 | (Addr)((struct vki_kbkeycode *)ARG3)->keycode, |
| 3752 | sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | |
| 3755 | case VKI_KDSIGACCEPT: |
| 3756 | break; |
| 3757 | |
| 3758 | case VKI_KDKBDREP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3759 | PRE_MEM_READ( "ioctl(KBKBDREP)", ARG3, sizeof(struct vki_kbd_repeat) ); |
thughes | b3d3bcf | 2004-11-13 00:36:15 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3762 | /* We don't have any specific information on it, so |
| 3763 | try to do something reasonable based on direction and |
| 3764 | size bits. The encoding scheme is described in |
| 3765 | /usr/include/asm/ioctl.h. |
| 3766 | |
| 3767 | According to Simon Hausmann, _IOC_READ means the kernel |
| 3768 | writes a value to the ioctl value passed from the user |
| 3769 | space and the other way around with _IOC_WRITE. */ |
| 3770 | default: { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3771 | UInt dir = _VKI_IOC_DIR(ARG2); |
| 3772 | UInt size = _VKI_IOC_SIZE(ARG2); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3773 | if (VG_(strstr)(VG_(clo_weird_hacks), "lax-ioctls") != NULL) { |
| 3774 | /* |
| 3775 | * Be very lax about ioctl handling; the only |
| 3776 | * assumption is that the size is correct. Doesn't |
| 3777 | * require the full buffer to be initialized when |
| 3778 | * writing. Without this, using some device |
| 3779 | * drivers with a large number of strange ioctl |
| 3780 | * commands becomes very tiresome. |
| 3781 | */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3782 | } else if (/* size == 0 || */ dir == _VKI_IOC_NONE) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3783 | static Int moans = 3; |
sewardj | 1fa7d2c | 2005-06-13 18:22:17 +0000 | [diff] [blame] | 3784 | if (moans > 0 && !VG_(clo_xml)) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3785 | moans--; |
| 3786 | VG_(message)(Vg_UserMsg, |
| 3787 | "Warning: noted but unhandled ioctl 0x%x" |
| 3788 | " with no size/direction hints", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3789 | ARG2); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3790 | VG_(message)(Vg_UserMsg, |
| 3791 | " This could cause spurious value errors" |
| 3792 | " to appear."); |
| 3793 | VG_(message)(Vg_UserMsg, |
| 3794 | " See README_MISSING_SYSCALL_OR_IOCTL for " |
| 3795 | "guidance on writing a proper wrapper." ); |
| 3796 | } |
| 3797 | } else { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3798 | if ((dir & _VKI_IOC_WRITE) && size > 0) |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3799 | PRE_MEM_READ( "ioctl(generic)", ARG3, size); |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3800 | if ((dir & _VKI_IOC_READ) && size > 0) |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3801 | PRE_MEM_WRITE( "ioctl(generic)", ARG3, size); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3802 | } |
| 3803 | break; |
| 3804 | } |
| 3805 | } |
| 3806 | } |
| 3807 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 3808 | POST(sys_ioctl) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3809 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 3810 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3811 | switch (ARG2 /* request */) { |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3812 | case VKI_TCSETS: |
| 3813 | case VKI_TCSETSW: |
| 3814 | case VKI_TCSETSF: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3815 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3816 | case VKI_TCGETS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3817 | POST_MEM_WRITE( ARG3, sizeof(struct vki_termios) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3818 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3819 | case VKI_TCSETA: |
| 3820 | case VKI_TCSETAW: |
| 3821 | case VKI_TCSETAF: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3822 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3823 | case VKI_TCGETA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3824 | POST_MEM_WRITE( ARG3, sizeof(struct vki_termio) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3825 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3826 | case VKI_TCSBRK: |
| 3827 | case VKI_TCXONC: |
| 3828 | case VKI_TCSBRKP: |
| 3829 | case VKI_TCFLSH: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3830 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3831 | case VKI_TIOCGWINSZ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3832 | POST_MEM_WRITE( ARG3, sizeof(struct vki_winsize) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3833 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3834 | case VKI_TIOCSWINSZ: |
| 3835 | case VKI_TIOCMBIS: |
| 3836 | case VKI_TIOCMBIC: |
| 3837 | case VKI_TIOCMSET: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3838 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3839 | case VKI_TIOCLINUX: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3840 | POST_MEM_WRITE( ARG3, sizeof(char *) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3841 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3842 | case VKI_TIOCGPGRP: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3843 | /* Get process group ID for foreground processing group. */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3844 | POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3845 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3846 | case VKI_TIOCSPGRP: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3847 | /* Set a process group ID? */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3848 | POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3849 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3850 | case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3851 | POST_MEM_WRITE( ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3852 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3853 | case VKI_TIOCSCTTY: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3854 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3855 | case VKI_TIOCSPTLCK: /* Lock/unlock Pty */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3856 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3857 | case VKI_FIONBIO: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3858 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3859 | case VKI_FIOASYNC: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3860 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3861 | case VKI_FIONREAD: /* identical to SIOCINQ */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3862 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3863 | break; |
| 3864 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3865 | case VKI_SG_SET_COMMAND_Q: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3866 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3867 | case VKI_SG_IO: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3868 | POST_MEM_WRITE(ARG3, sizeof(vki_sg_io_hdr_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3869 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3870 | case VKI_SG_GET_SCSI_ID: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3871 | POST_MEM_WRITE(ARG3, sizeof(vki_sg_scsi_id_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3872 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3873 | case VKI_SG_SET_RESERVED_SIZE: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3874 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3875 | case VKI_SG_SET_TIMEOUT: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3876 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3877 | case VKI_SG_GET_RESERVED_SIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3878 | POST_MEM_WRITE(ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3879 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3880 | case VKI_SG_GET_TIMEOUT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3881 | POST_MEM_WRITE(ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3882 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3883 | case VKI_SG_GET_VERSION_NUM: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3884 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3885 | case VKI_SG_EMULATED_HOST: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3886 | POST_MEM_WRITE(ARG3, sizeof(int)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3887 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3888 | case VKI_SG_GET_SG_TABLESIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3889 | POST_MEM_WRITE(ARG3, sizeof(int)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 3890 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3891 | |
mueller | a4b153a | 2003-11-19 22:07:14 +0000 | [diff] [blame] | 3892 | case VKI_IIOCGETCPS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3893 | POST_MEM_WRITE( ARG3, VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3894 | break; |
mueller | a4b153a | 2003-11-19 22:07:14 +0000 | [diff] [blame] | 3895 | case VKI_IIOCNETGPN: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3896 | POST_MEM_WRITE( ARG3, sizeof(vki_isdn_net_ioctl_phone) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3897 | break; |
| 3898 | |
| 3899 | /* These all use struct ifreq AFAIK */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3900 | case VKI_SIOCGIFINDEX: /* get iface index */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3901 | POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_ifindex, |
| 3902 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3903 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3904 | case VKI_SIOCGIFFLAGS: /* get flags */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3905 | POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, |
| 3906 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3907 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3908 | case VKI_SIOCGIFHWADDR: /* Get hardware address */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3909 | POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->ifr_hwaddr, |
| 3910 | sizeof(((struct vki_ifreq *)ARG3)->ifr_hwaddr) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3911 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3912 | case VKI_SIOCGIFMTU: /* get MTU size */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3913 | POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu, |
| 3914 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3915 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3916 | case VKI_SIOCGIFADDR: /* get PA address */ |
| 3917 | case VKI_SIOCGIFDSTADDR: /* get remote PA address */ |
| 3918 | case VKI_SIOCGIFBRDADDR: /* get broadcast PA address */ |
| 3919 | case VKI_SIOCGIFNETMASK: /* get network PA mask */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3920 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3921 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_addr, |
| 3922 | sizeof(((struct vki_ifreq *)ARG3)->ifr_addr) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3923 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3924 | case VKI_SIOCGIFMETRIC: /* get metric */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3925 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3926 | (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric, |
| 3927 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3928 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3929 | case VKI_SIOCGIFMAP: /* Get device parameters */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3930 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3931 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_map, |
| 3932 | sizeof(((struct vki_ifreq *)ARG3)->ifr_map) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3933 | break; |
| 3934 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3935 | case VKI_SIOCGIFTXQLEN: /* Get the tx queue length */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3936 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3937 | (Addr)&((struct vki_ifreq *)ARG3)->ifr_qlen, |
| 3938 | sizeof(((struct vki_ifreq *)ARG3)->ifr_qlen) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3939 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3940 | case VKI_SIOCGIFNAME: /* get iface name */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3941 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3942 | (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name, |
| 3943 | sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3944 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3945 | case VKI_SIOCGMIIPHY: /* get hardware entry */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3946 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3947 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, |
| 3948 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3949 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3950 | case VKI_SIOCGMIIREG: /* get hardware entry registers */ |
njn | cf45fd4 | 2004-11-24 16:30:22 +0000 | [diff] [blame] | 3951 | POST_MEM_WRITE( |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3952 | (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out, |
| 3953 | sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out) ); |
thughes | be81171 | 2004-06-17 23:04:58 +0000 | [diff] [blame] | 3954 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3955 | case VKI_SIOCGIFCONF: /* get iface list */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3956 | /* WAS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3957 | PRE_MEM_WRITE("ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf)); |
| 3958 | KERNEL_DO_SYSCALL(tid,RES); |
| 3959 | if (!VG_(is_kerror)(RES) && RES == 0) |
| 3960 | POST_MEM_WRITE(ARG3, sizeof(struct ifconf)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3961 | */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3962 | if (RES == 0 && ARG3 ) { |
| 3963 | struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3964 | if (ifc->vki_ifc_buf != NULL) |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 3965 | POST_MEM_WRITE( (Addr)(ifc->vki_ifc_buf), ifc->ifc_len ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3966 | } |
| 3967 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3968 | case VKI_SIOCGSTAMP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3969 | POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3970 | break; |
| 3971 | /* SIOCOUTQ is an ioctl that, when called on a socket, returns |
| 3972 | the number of bytes currently in that socket's send buffer. |
| 3973 | It writes this value as an int to the memory location |
| 3974 | indicated by the third argument of ioctl(2). */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3975 | case VKI_SIOCOUTQ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3976 | POST_MEM_WRITE(ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3977 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3978 | case VKI_SIOCGRARP: /* get RARP table entry */ |
| 3979 | case VKI_SIOCGARP: /* get ARP table entry */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 3980 | POST_MEM_WRITE(ARG3, sizeof(struct vki_arpreq)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3981 | break; |
| 3982 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3983 | case VKI_SIOCSIFFLAGS: /* set flags */ |
| 3984 | case VKI_SIOCSIFMAP: /* Set device parameters */ |
| 3985 | case VKI_SIOCSIFTXQLEN: /* Set the tx queue length */ |
| 3986 | case VKI_SIOCSIFDSTADDR: /* set remote PA address */ |
| 3987 | case VKI_SIOCSIFBRDADDR: /* set broadcast PA address */ |
| 3988 | case VKI_SIOCSIFNETMASK: /* set network PA mask */ |
| 3989 | case VKI_SIOCSIFMETRIC: /* set metric */ |
| 3990 | case VKI_SIOCSIFADDR: /* set PA address */ |
| 3991 | case VKI_SIOCSIFMTU: /* set MTU size */ |
| 3992 | case VKI_SIOCSIFHWADDR: /* set hardware address */ |
| 3993 | case VKI_SIOCSMIIREG: /* set hardware entry registers */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3994 | break; |
| 3995 | /* Routing table calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 3996 | case VKI_SIOCADDRT: /* add routing table entry */ |
| 3997 | case VKI_SIOCDELRT: /* delete routing table entry */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 3998 | break; |
| 3999 | |
| 4000 | /* RARP cache control calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4001 | case VKI_SIOCDRARP: /* delete RARP table entry */ |
| 4002 | case VKI_SIOCSRARP: /* set RARP table entry */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4003 | /* ARP cache control calls. */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4004 | case VKI_SIOCSARP: /* set ARP table entry */ |
| 4005 | case VKI_SIOCDARP: /* delete ARP table entry */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4006 | break; |
| 4007 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4008 | case VKI_SIOCGPGRP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4009 | POST_MEM_WRITE(ARG3, sizeof(int)); |
thughes | 1174fed | 2004-09-11 15:33:17 +0000 | [diff] [blame] | 4010 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4011 | case VKI_SIOCSPGRP: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4012 | break; |
| 4013 | |
| 4014 | /* linux/soundcard interface (OSS) */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4015 | case VKI_SNDCTL_SEQ_GETOUTCOUNT: |
| 4016 | case VKI_SNDCTL_SEQ_GETINCOUNT: |
| 4017 | case VKI_SNDCTL_SEQ_PERCMODE: |
| 4018 | case VKI_SNDCTL_SEQ_TESTMIDI: |
| 4019 | case VKI_SNDCTL_SEQ_RESETSAMPLES: |
| 4020 | case VKI_SNDCTL_SEQ_NRSYNTHS: |
| 4021 | case VKI_SNDCTL_SEQ_NRMIDIS: |
| 4022 | case VKI_SNDCTL_SEQ_GETTIME: |
| 4023 | case VKI_SNDCTL_DSP_GETFMTS: |
| 4024 | case VKI_SNDCTL_DSP_GETTRIGGER: |
| 4025 | case VKI_SNDCTL_DSP_GETODELAY: |
| 4026 | case VKI_SNDCTL_DSP_GETSPDIF: |
| 4027 | case VKI_SNDCTL_DSP_GETCAPS: |
| 4028 | case VKI_SOUND_PCM_READ_RATE: |
| 4029 | case VKI_SOUND_PCM_READ_CHANNELS: |
| 4030 | case VKI_SOUND_PCM_READ_BITS: |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 4031 | #if !defined(VGA_ppc32) |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4032 | case (VKI_SOUND_PCM_READ_BITS|0x40000000): /* what the fuck ? */ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 4033 | #endif |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4034 | case VKI_SOUND_PCM_READ_FILTER: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4035 | POST_MEM_WRITE(ARG3, sizeof(int)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4036 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4037 | case VKI_SNDCTL_SEQ_CTRLRATE: |
| 4038 | case VKI_SNDCTL_DSP_SPEED: |
| 4039 | case VKI_SNDCTL_DSP_STEREO: |
| 4040 | case VKI_SNDCTL_DSP_GETBLKSIZE: |
| 4041 | case VKI_SNDCTL_DSP_CHANNELS: |
| 4042 | case VKI_SOUND_PCM_WRITE_FILTER: |
| 4043 | case VKI_SNDCTL_DSP_SUBDIVIDE: |
| 4044 | case VKI_SNDCTL_DSP_SETFRAGMENT: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4045 | case VKI_SNDCTL_DSP_GETCHANNELMASK: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4046 | case VKI_SNDCTL_DSP_BIND_CHANNEL: |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4047 | case VKI_SNDCTL_TMR_TIMEBASE: |
| 4048 | case VKI_SNDCTL_TMR_TEMPO: |
| 4049 | case VKI_SNDCTL_TMR_SOURCE: |
| 4050 | case VKI_SNDCTL_MIDI_PRETIME: |
| 4051 | case VKI_SNDCTL_MIDI_MPUMODE: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4052 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4053 | case VKI_SNDCTL_DSP_GETOSPACE: |
| 4054 | case VKI_SNDCTL_DSP_GETISPACE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4055 | POST_MEM_WRITE(ARG3, sizeof(vki_audio_buf_info)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4056 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4057 | case VKI_SNDCTL_DSP_SETTRIGGER: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4058 | break; |
| 4059 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4060 | case VKI_SNDCTL_DSP_POST: |
| 4061 | case VKI_SNDCTL_DSP_RESET: |
| 4062 | case VKI_SNDCTL_DSP_SYNC: |
| 4063 | case VKI_SNDCTL_DSP_SETSYNCRO: |
| 4064 | case VKI_SNDCTL_DSP_SETDUPLEX: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4065 | break; |
| 4066 | |
| 4067 | /* Real Time Clock (/dev/rtc) ioctls */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4068 | case VKI_RTC_UIE_ON: |
| 4069 | case VKI_RTC_UIE_OFF: |
| 4070 | case VKI_RTC_AIE_ON: |
| 4071 | case VKI_RTC_AIE_OFF: |
| 4072 | case VKI_RTC_PIE_ON: |
| 4073 | case VKI_RTC_PIE_OFF: |
| 4074 | case VKI_RTC_IRQP_SET: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4075 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4076 | case VKI_RTC_RD_TIME: |
| 4077 | case VKI_RTC_ALM_READ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4078 | POST_MEM_WRITE(ARG3, sizeof(struct vki_rtc_time)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4079 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4080 | case VKI_RTC_ALM_SET: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4081 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4082 | case VKI_RTC_IRQP_READ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4083 | POST_MEM_WRITE(ARG3, sizeof(unsigned long)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4084 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4085 | |
nethercote | 95a9786 | 2004-11-06 16:31:43 +0000 | [diff] [blame] | 4086 | case VKI_BLKGETSIZE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4087 | POST_MEM_WRITE(ARG3, sizeof(unsigned long)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4088 | break; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4089 | |
thughes | acbbc32 | 2004-06-19 12:12:01 +0000 | [diff] [blame] | 4090 | /* Hard disks */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4091 | case VKI_HDIO_GET_IDENTITY: /* 0x030d */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4092 | POST_MEM_WRITE(ARG3, VKI_SIZEOF_STRUCT_HD_DRIVEID ); |
thughes | acbbc32 | 2004-06-19 12:12:01 +0000 | [diff] [blame] | 4093 | break; |
| 4094 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4095 | /* CD ROM stuff (??) */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4096 | case VKI_CDROMSUBCHNL: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4097 | POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_subchnl)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4098 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4099 | case VKI_CDROMREADTOCHDR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4100 | POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tochdr)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4101 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4102 | case VKI_CDROMREADTOCENTRY: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4103 | POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tochdr)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4104 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4105 | case VKI_CDROMMULTISESSION: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4106 | POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_multisession)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 4107 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4108 | case VKI_CDROMVOLREAD: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4109 | POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_volctrl)); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 4110 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4111 | case VKI_CDROMREADAUDIO: |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 4112 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4113 | struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4114 | POST_MEM_WRITE( (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW); |
thughes | 5b788fb | 2004-09-11 15:07:14 +0000 | [diff] [blame] | 4115 | break; |
| 4116 | } |
| 4117 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4118 | case VKI_CDROMPLAYMSF: |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4119 | break; |
| 4120 | /* The following two are probably bogus (should check args |
| 4121 | for readability). JRS 20021117 */ |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4122 | case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */ |
| 4123 | case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4124 | break; |
| 4125 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4126 | case VKI_FIGETBSZ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4127 | POST_MEM_WRITE(ARG3, sizeof(unsigned long)); |
thughes | 66d8009 | 2004-06-19 12:41:05 +0000 | [diff] [blame] | 4128 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4129 | case VKI_FIBMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4130 | POST_MEM_WRITE(ARG3, sizeof(unsigned long)); |
thughes | 66d8009 | 2004-06-19 12:41:05 +0000 | [diff] [blame] | 4131 | break; |
| 4132 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4133 | case VKI_FBIOGET_VSCREENINFO: //0x4600 |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4134 | POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_var_screeninfo)); |
thughes | 44e3558 | 2004-04-21 15:52:33 +0000 | [diff] [blame] | 4135 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4136 | case VKI_FBIOGET_FSCREENINFO: //0x4602 |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4137 | POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_fix_screeninfo)); |
thughes | 44e3558 | 2004-04-21 15:52:33 +0000 | [diff] [blame] | 4138 | break; |
| 4139 | |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4140 | case VKI_PPCLAIM: |
| 4141 | case VKI_PPEXCL: |
| 4142 | case VKI_PPYIELD: |
| 4143 | case VKI_PPRELEASE: |
| 4144 | case VKI_PPSETMODE: |
| 4145 | case VKI_PPSETPHASE: |
| 4146 | case VKI_PPSETFLAGS: |
| 4147 | case VKI_PPWDATA: |
| 4148 | case VKI_PPWCONTROL: |
| 4149 | case VKI_PPFCONTROL: |
| 4150 | case VKI_PPDATADIR: |
| 4151 | case VKI_PPNEGOT: |
| 4152 | case VKI_PPWCTLONIRQ: |
| 4153 | case VKI_PPSETTIME: |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4154 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4155 | case VKI_PPGETMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4156 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4157 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4158 | case VKI_PPGETPHASE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4159 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4160 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4161 | case VKI_PPGETMODES: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4162 | POST_MEM_WRITE( ARG3, sizeof(unsigned int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4163 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4164 | case VKI_PPGETFLAGS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4165 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4166 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4167 | case VKI_PPRSTATUS: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4168 | POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4169 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4170 | case VKI_PPRDATA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4171 | POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4172 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4173 | case VKI_PPRCONTROL: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4174 | POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4175 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4176 | case VKI_PPCLRIRQ: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4177 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4178 | break; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4179 | case VKI_PPGETTIME: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4180 | POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) ); |
thughes | d989548 | 2004-08-16 19:46:55 +0000 | [diff] [blame] | 4181 | break; |
| 4182 | |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4183 | case VKI_GIO_FONT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4184 | POST_MEM_WRITE( ARG3, 32 * 256 ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4185 | break; |
| 4186 | case VKI_PIO_FONT: |
| 4187 | break; |
| 4188 | |
| 4189 | case VKI_GIO_FONTX: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4190 | POST_MEM_WRITE( (Addr)((struct vki_consolefontdesc *)ARG3)->chardata, |
| 4191 | 32 * ((struct vki_consolefontdesc *)ARG3)->charcount ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | case VKI_PIO_FONTX: |
| 4194 | break; |
| 4195 | |
| 4196 | case VKI_PIO_FONTRESET: |
| 4197 | break; |
| 4198 | |
| 4199 | case VKI_GIO_CMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4200 | POST_MEM_WRITE( ARG3, 16 * 3 ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4201 | break; |
| 4202 | case VKI_PIO_CMAP: |
| 4203 | break; |
| 4204 | |
| 4205 | case VKI_KIOCSOUND: |
| 4206 | case VKI_KDMKTONE: |
| 4207 | break; |
| 4208 | |
| 4209 | case VKI_KDGETLED: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4210 | POST_MEM_WRITE( ARG3, sizeof(char) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4211 | break; |
| 4212 | case VKI_KDSETLED: |
| 4213 | break; |
| 4214 | |
| 4215 | case VKI_KDGKBTYPE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4216 | POST_MEM_WRITE( ARG3, sizeof(char) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4217 | break; |
| 4218 | |
| 4219 | case VKI_KDADDIO: |
| 4220 | case VKI_KDDELIO: |
| 4221 | case VKI_KDENABIO: |
| 4222 | case VKI_KDDISABIO: |
| 4223 | break; |
| 4224 | |
| 4225 | case VKI_KDSETMODE: |
| 4226 | break; |
| 4227 | case VKI_KDGETMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4228 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4229 | break; |
| 4230 | |
| 4231 | case VKI_KDMAPDISP: |
| 4232 | case VKI_KDUNMAPDISP: |
| 4233 | break; |
| 4234 | |
| 4235 | case VKI_GIO_SCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4236 | POST_MEM_WRITE( ARG3, VKI_E_TABSZ ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4237 | break; |
| 4238 | case VKI_PIO_SCRNMAP: |
| 4239 | break; |
| 4240 | case VKI_GIO_UNISCRNMAP: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4241 | POST_MEM_WRITE( ARG3, VKI_E_TABSZ * sizeof(unsigned short) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4242 | break; |
| 4243 | case VKI_PIO_UNISCRNMAP: |
| 4244 | break; |
| 4245 | |
| 4246 | case VKI_KDGKBMODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4247 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4248 | break; |
| 4249 | case VKI_KDSKBMODE: |
| 4250 | break; |
| 4251 | |
| 4252 | case VKI_KDGKBMETA: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4253 | POST_MEM_WRITE( ARG3, sizeof(int) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4254 | break; |
| 4255 | case VKI_KDSKBMETA: |
| 4256 | break; |
| 4257 | |
| 4258 | case VKI_KDGKBLED: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4259 | POST_MEM_WRITE( ARG3, sizeof(char) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4260 | break; |
| 4261 | case VKI_KDSKBLED: |
| 4262 | break; |
| 4263 | |
| 4264 | case VKI_KDGKBENT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4265 | POST_MEM_WRITE( (Addr)&((struct vki_kbentry *)ARG3)->kb_value, |
| 4266 | sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4267 | break; |
| 4268 | case VKI_KDSKBENT: |
| 4269 | break; |
| 4270 | |
| 4271 | case VKI_KDGKBSENT: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4272 | POST_MEM_WRITE( (Addr)((struct vki_kbsentry *)ARG3)->kb_string, |
| 4273 | sizeof(((struct vki_kbsentry *)ARG3)->kb_string) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4274 | break; |
| 4275 | case VKI_KDSKBSENT: |
| 4276 | break; |
| 4277 | |
| 4278 | case VKI_KDGKBDIACR: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4279 | POST_MEM_WRITE( ARG3, sizeof(struct vki_kbdiacrs) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4280 | break; |
| 4281 | case VKI_KDSKBDIACR: |
| 4282 | break; |
| 4283 | |
| 4284 | case VKI_KDGETKEYCODE: |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4285 | POST_MEM_WRITE( (Addr)((struct vki_kbkeycode *)ARG3)->keycode, |
| 4286 | sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); |
thughes | c3b842d | 2004-11-13 10:38:04 +0000 | [diff] [blame] | 4287 | break; |
| 4288 | case VKI_KDSETKEYCODE: |
| 4289 | break; |
| 4290 | |
| 4291 | case VKI_KDSIGACCEPT: |
| 4292 | break; |
| 4293 | |
| 4294 | case VKI_KDKBDREP: |
| 4295 | break; |
| 4296 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4297 | /* We don't have any specific information on it, so |
| 4298 | try to do something reasonable based on direction and |
| 4299 | size bits. The encoding scheme is described in |
| 4300 | /usr/include/asm/ioctl.h. |
| 4301 | |
| 4302 | According to Simon Hausmann, _IOC_READ means the kernel |
| 4303 | writes a value to the ioctl value passed from the user |
| 4304 | space and the other way around with _IOC_WRITE. */ |
| 4305 | default: { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4306 | UInt dir = _VKI_IOC_DIR(ARG2); |
| 4307 | UInt size = _VKI_IOC_SIZE(ARG2); |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4308 | if (size > 0 && (dir & _VKI_IOC_READ) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4309 | && RES == 0 |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4310 | && ARG3 != (Addr)NULL) |
| 4311 | POST_MEM_WRITE(ARG3, size); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4312 | break; |
| 4313 | } |
| 4314 | } |
| 4315 | } |
| 4316 | |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4317 | /* |
| 4318 | If we're sending a SIGKILL to one of our own threads, then simulate |
| 4319 | it rather than really sending the signal, so that the target thread |
| 4320 | gets a chance to clean up. Returns True if we did the killing (or |
| 4321 | no killing is necessary), and False if the caller should use the |
| 4322 | normal kill syscall. |
| 4323 | |
| 4324 | "pid" is any pid argument which can be passed to kill; group kills |
| 4325 | (< -1, 0), and owner kills (-1) are ignored, on the grounds that |
| 4326 | they'll most likely hit all the threads and we won't need to worry |
| 4327 | about cleanup. In truth, we can't fully emulate these multicast |
| 4328 | kills. |
| 4329 | |
| 4330 | "tgid" is a thread group id. If it is not -1, then the target |
| 4331 | thread must be in that thread group. |
| 4332 | */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4333 | Bool ML_(do_sigkill)(Int pid, Int tgid) |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4334 | { |
| 4335 | ThreadState *tst; |
| 4336 | ThreadId tid; |
| 4337 | |
| 4338 | if (pid <= 0) |
| 4339 | return False; |
| 4340 | |
| 4341 | tid = VG_(get_lwp_tid)(pid); |
| 4342 | if (tid == VG_INVALID_THREADID) |
| 4343 | return False; /* none of our threads */ |
| 4344 | |
| 4345 | tst = VG_(get_ThreadState)(tid); |
| 4346 | if (tst == NULL || tst->status == VgTs_Empty) |
| 4347 | return False; /* hm, shouldn't happen */ |
| 4348 | |
| 4349 | if (tgid != -1 && tst->os_state.threadgroup != tgid) |
| 4350 | return False; /* not the right thread group */ |
| 4351 | |
| 4352 | /* Check to see that the target isn't already exiting. */ |
| 4353 | if (!VG_(is_exiting)(tid)) { |
| 4354 | if (VG_(clo_trace_signals)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4355 | VG_(message)(Vg_DebugMsg, "Thread %d being killed with SIGKILL", |
| 4356 | tst->tid); |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4357 | |
| 4358 | tst->exitreason = VgSrc_FatalSig; |
| 4359 | tst->os_state.fatalsig = VKI_SIGKILL; |
| 4360 | |
| 4361 | if (!VG_(is_running_thread)(tid)) |
| 4362 | VG_(kill_thread)(tid); |
| 4363 | } |
| 4364 | |
| 4365 | return True; |
| 4366 | } |
| 4367 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4368 | PRE(sys_kill) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4369 | { |
| 4370 | /* int kill(pid_t pid, int sig); */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4371 | PRINT("sys_kill ( %d, %d )", ARG1,ARG2); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 4372 | PRE_REG_READ2(long, "kill", int, pid, int, sig); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4373 | if (!ML_(client_signal_OK)(ARG2)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4374 | SET_STATUS_Failure( VKI_EINVAL ); |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4375 | return; |
| 4376 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4377 | |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4378 | /* If we're sending SIGKILL, check to see if the target is one of |
| 4379 | our threads and handle it specially. */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4380 | if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4381 | SET_STATUS_Success(0); |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4382 | else |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4383 | SET_STATUS_from_SysRes( VG_(do_syscall2)(SYSNO, ARG1, ARG2) ); |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4384 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 4385 | if (VG_(clo_trace_signals)) |
| 4386 | VG_(message)(Vg_DebugMsg, "kill: sent signal %d to pid %d", |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 4387 | ARG2, ARG1); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4388 | |
| 4389 | /* This kill might have given us a pending signal. Ask for a check once |
| 4390 | the syscall is done. */ |
| 4391 | *flags |= SfPollAfter; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4394 | PRE(sys_link) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4395 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4396 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4397 | PRINT("sys_link ( %p, %p)", ARG1, ARG2); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 4398 | PRE_REG_READ2(long, "link", const char *, oldpath, const char *, newpath); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4399 | PRE_MEM_RASCIIZ( "link(oldpath)", ARG1); |
| 4400 | PRE_MEM_RASCIIZ( "link(newpath)", ARG2); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4403 | PRE(sys_lseek) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4404 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4405 | PRINT("sys_lseek ( %d, %d, %d )", ARG1,ARG2,ARG3); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 4406 | PRE_REG_READ3(vki_off_t, "lseek", |
| 4407 | unsigned int, fd, vki_off_t, offset, unsigned int, whence); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 4410 | PRE(sys_newlstat) |
| 4411 | { |
| 4412 | PRINT("sys_newlstat ( %p(%s), %p )", ARG1,ARG1,ARG2); |
| 4413 | PRE_REG_READ2(long, "lstat", char *, file_name, struct stat *, buf); |
| 4414 | PRE_MEM_RASCIIZ( "lstat(file_name)", ARG1 ); |
| 4415 | PRE_MEM_WRITE( "lstat(buf)", ARG2, sizeof(struct vki_stat) ); |
| 4416 | } |
| 4417 | |
| 4418 | POST(sys_newlstat) |
| 4419 | { |
| 4420 | vg_assert(SUCCESS); |
| 4421 | if (RES == 0) { |
| 4422 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); |
| 4423 | } |
| 4424 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4425 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4426 | PRE(sys_mkdir) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4427 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4428 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4429 | PRINT("sys_mkdir ( %p, %d )", ARG1,ARG2); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 4430 | PRE_REG_READ2(long, "mkdir", const char *, pathname, int, mode); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4431 | PRE_MEM_RASCIIZ( "mkdir(pathname)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4434 | PRE(sys_mmap2) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4435 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4436 | // Exactly like old_mmap() in x86-linux except: |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4437 | // - all 6 args are passed in regs, rather than in a memory-block. |
| 4438 | // - the file offset is specified in pagesize units rather than bytes, |
| 4439 | // so that it can be used for files bigger than 2^32 bytes. |
| 4440 | PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4441 | ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 ); |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4442 | PRE_REG_READ6(long, "mmap2", |
| 4443 | unsigned long, start, unsigned long, length, |
| 4444 | unsigned long, prot, unsigned long, flags, |
| 4445 | unsigned long, fd, unsigned long, offset); |
| 4446 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 4447 | if (ARG2 == 0) { |
| 4448 | /* SuSV3 says: If len is zero, mmap() shall fail and no mapping |
| 4449 | shall be established. */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4450 | SET_STATUS_Failure( VKI_EINVAL ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 4451 | return; |
| 4452 | } |
| 4453 | |
sewardj | 565b1ed | 2005-03-11 14:12:38 +0000 | [diff] [blame] | 4454 | if (/*(ARG4 & VKI_MAP_FIXED) && */ (0 != (ARG1 & (VKI_PAGE_SIZE-1)))) { |
| 4455 | /* zap any misaligned addresses. */ |
sewardj | d0d9731 | 2005-03-23 02:53:13 +0000 | [diff] [blame] | 4456 | /* SuSV3 says misaligned addresses only cause the MAP_FIXED case |
| 4457 | to fail. Here, we catch them all. */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4458 | SET_STATUS_Failure( VKI_EINVAL ); |
sewardj | 565b1ed | 2005-03-11 14:12:38 +0000 | [diff] [blame] | 4459 | return; |
| 4460 | } |
| 4461 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4462 | if (ARG4 & VKI_MAP_FIXED) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4463 | if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "mmap2")) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4464 | SET_STATUS_Failure( VKI_ENOMEM ); |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4465 | } else { |
sewardj | d0d9731 | 2005-03-23 02:53:13 +0000 | [diff] [blame] | 4466 | Addr a = VG_(find_map_space)(ARG1, ARG2, True); |
| 4467 | if (a == 0 && ARG1 != 0) |
| 4468 | ARG1 = VG_(find_map_space)(0, ARG2, True); |
| 4469 | else |
| 4470 | ARG1 = a; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4471 | if (ARG1 == 0) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4472 | SET_STATUS_Failure( VKI_ENOMEM ); |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4473 | else |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4474 | ARG4 |= VKI_MAP_FIXED; |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | |
| 4478 | POST(sys_mmap2) |
| 4479 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4480 | vg_assert(SUCCESS); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4481 | vg_assert(ML_(valid_client_addr)(RES, ARG2, tid, "mmap2")); |
| 4482 | ML_(mmap_segment)( (Addr)RES, ARG2, ARG3, ARG4, ARG5, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4483 | ARG6 * (ULong)VKI_PAGE_SIZE ); |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 4484 | } |
| 4485 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4486 | PRE(sys_mprotect) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4487 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4488 | PRINT("sys_mprotect ( %p, %llu, %d )", ARG1,(ULong)ARG2,ARG3); |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 4489 | PRE_REG_READ3(long, "mprotect", |
| 4490 | unsigned long, addr, vki_size_t, len, unsigned long, prot); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 4491 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4492 | if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "mprotect")) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4493 | SET_STATUS_Failure( VKI_ENOMEM ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4496 | POST(sys_mprotect) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4497 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4498 | Addr a = ARG1; |
| 4499 | SizeT len = ARG2; |
| 4500 | Int prot = ARG3; |
nethercote | 27ea8bc | 2004-07-10 17:21:14 +0000 | [diff] [blame] | 4501 | Bool rr = prot & VKI_PROT_READ; |
| 4502 | Bool ww = prot & VKI_PROT_WRITE; |
| 4503 | Bool xx = prot & VKI_PROT_EXEC; |
| 4504 | |
nethercote | 27ea8bc | 2004-07-10 17:21:14 +0000 | [diff] [blame] | 4505 | mash_addr_and_len(&a, &len); |
| 4506 | VG_(mprotect_range)(a, len, prot); |
| 4507 | VG_TRACK( change_mem_mprotect, a, len, rr, ww, xx ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4510 | PRE(sys_munmap) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4511 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4512 | if (0) VG_(printf)(" munmap( %p )\n", ARG1); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4513 | PRINT("sys_munmap ( %p, %llu )", ARG1,(ULong)ARG2); |
nethercote | 06c7bd7 | 2004-11-14 19:11:56 +0000 | [diff] [blame] | 4514 | PRE_REG_READ2(long, "munmap", unsigned long, start, vki_size_t, length); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 4515 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4516 | if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "munmap")) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4517 | SET_STATUS_Failure( VKI_EINVAL ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4520 | POST(sys_munmap) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4521 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4522 | Addr a = ARG1; |
| 4523 | SizeT len = ARG2; |
nethercote | 27ea8bc | 2004-07-10 17:21:14 +0000 | [diff] [blame] | 4524 | |
| 4525 | mash_addr_and_len(&a, &len); |
| 4526 | VG_(unmap_range)(a, len); |
| 4527 | VG_TRACK( die_mem_munmap, a, len ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4528 | } |
| 4529 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4530 | PRE(sys_mincore) |
| 4531 | { |
| 4532 | PRINT("sys_mincore ( %p, %llu, %p )", ARG1,(ULong)ARG2,ARG3); |
| 4533 | PRE_REG_READ3(long, "mincore", |
| 4534 | unsigned long, start, vki_size_t, length, |
| 4535 | unsigned char *, vec); |
njn | cdaec51 | 2005-06-30 00:16:02 +0000 | [diff] [blame] | 4536 | PRE_MEM_WRITE( "mincore(vec)", ARG3, VG_PGROUNDUP(ARG2) / VKI_PAGE_SIZE ); |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4537 | } |
| 4538 | POST(sys_mincore) |
| 4539 | { |
njn | cdaec51 | 2005-06-30 00:16:02 +0000 | [diff] [blame] | 4540 | POST_MEM_WRITE( ARG3, VG_PGROUNDUP(ARG2) / VKI_PAGE_SIZE ); |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4541 | } |
mueller | 6ceb231 | 2004-01-02 22:52:34 +0000 | [diff] [blame] | 4542 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4543 | PRE(sys_nanosleep) |
mueller | 6ceb231 | 2004-01-02 22:52:34 +0000 | [diff] [blame] | 4544 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4545 | *flags |= SfMayBlock|SfPostOnFail; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4546 | PRINT("sys_nanosleep ( %p, %p )", ARG1,ARG2); |
nethercote | 5b653bc | 2004-11-15 14:32:12 +0000 | [diff] [blame] | 4547 | PRE_REG_READ2(long, "nanosleep", |
| 4548 | struct timespec *, req, struct timespec *, rem); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4549 | PRE_MEM_READ( "nanosleep(req)", ARG1, sizeof(struct vki_timespec) ); |
| 4550 | if (ARG2 != 0) |
| 4551 | PRE_MEM_WRITE( "nanosleep(rem)", ARG2, sizeof(struct vki_timespec) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4552 | } |
| 4553 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4554 | POST(sys_nanosleep) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4555 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4556 | vg_assert(SUCCESS || FAILURE); |
| 4557 | if (ARG2 != 0 && FAILURE && RES_unchecked == VKI_EINTR) |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4558 | POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4561 | PRE(sys_open) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4562 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4563 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4564 | if (ARG2 & VKI_O_CREAT) { |
nethercote | e824cc4 | 2004-11-09 16:20:46 +0000 | [diff] [blame] | 4565 | // 3-arg version |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4566 | PRINT("sys_open ( %p(%s), %d, %d )",ARG1,ARG1,ARG2,ARG3); |
nethercote | e824cc4 | 2004-11-09 16:20:46 +0000 | [diff] [blame] | 4567 | PRE_REG_READ3(long, "open", |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 4568 | const char *, filename, int, flags, int, mode); |
nethercote | e70bd7d | 2004-08-18 14:37:17 +0000 | [diff] [blame] | 4569 | } else { |
nethercote | e824cc4 | 2004-11-09 16:20:46 +0000 | [diff] [blame] | 4570 | // 2-arg version |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4571 | PRINT("sys_open ( %p(%s), %d )",ARG1,ARG1,ARG2); |
nethercote | e824cc4 | 2004-11-09 16:20:46 +0000 | [diff] [blame] | 4572 | PRE_REG_READ2(long, "open", |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 4573 | const char *, filename, int, flags); |
nethercote | e70bd7d | 2004-08-18 14:37:17 +0000 | [diff] [blame] | 4574 | } |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4575 | PRE_MEM_RASCIIZ( "open(filename)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4578 | POST(sys_open) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4579 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4580 | vg_assert(SUCCESS); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4581 | if (!ML_(fd_allowed)(RES, "open", tid, True)) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4582 | VG_(close)(RES); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4583 | SET_STATUS_Failure( VKI_EMFILE ); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 4584 | } else { |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 4585 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 4586 | record_fd_open_with_given_name(tid, RES, (Char*)ARG1); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4587 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4588 | } |
| 4589 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4590 | PRE(sys_read) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4591 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4592 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4593 | PRINT("sys_read ( %d, %p, %llu )", ARG1, ARG2, (ULong)ARG3); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 4594 | PRE_REG_READ3(ssize_t, "read", |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 4595 | unsigned int, fd, char *, buf, vki_size_t, count); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4596 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4597 | if (!ML_(fd_allowed)(ARG1, "read", tid, False)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4598 | SET_STATUS_Failure( VKI_EBADF ); |
thughes | 26ab77b | 2004-08-14 12:10:49 +0000 | [diff] [blame] | 4599 | else |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4600 | PRE_MEM_WRITE( "read(buf)", ARG2, ARG3 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4603 | POST(sys_read) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4604 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4605 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4606 | POST_MEM_WRITE( ARG2, RES ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4607 | } |
| 4608 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4609 | PRE(sys_write) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4610 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4611 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4612 | PRINT("sys_write ( %d, %p, %llu )", ARG1, ARG2, (ULong)ARG3); |
nethercote | 8b76fe5 | 2004-11-08 19:20:09 +0000 | [diff] [blame] | 4613 | PRE_REG_READ3(ssize_t, "write", |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 4614 | unsigned int, fd, const char *, buf, vki_size_t, count); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4615 | if (!ML_(fd_allowed)(ARG1, "write", tid, False)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4616 | SET_STATUS_Failure( VKI_EBADF ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4617 | else |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4618 | PRE_MEM_READ( "write(buf)", ARG2, ARG3 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4621 | PRE(sys_creat) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4622 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4623 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4624 | PRINT("sys_creat ( %p(%s), %d )", ARG1,ARG1,ARG2); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 4625 | PRE_REG_READ2(long, "creat", const char *, pathname, int, mode); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4626 | PRE_MEM_RASCIIZ( "creat(pathname)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4629 | POST(sys_creat) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4630 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4631 | vg_assert(SUCCESS); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4632 | if (!ML_(fd_allowed)(RES, "creat", tid, True)) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4633 | VG_(close)(RES); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4634 | SET_STATUS_Failure( VKI_EMFILE ); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 4635 | } else { |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 4636 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 4637 | record_fd_open_with_given_name(tid, RES, (Char*)ARG1); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4638 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4639 | } |
| 4640 | |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 4641 | // XXX: sort of x86-specific |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4642 | PRE(sys_pipe) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4643 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4644 | PRINT("sys_pipe ( %p )", ARG1); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 4645 | PRE_REG_READ1(int, "pipe", unsigned long *, filedes); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4646 | PRE_MEM_WRITE( "pipe(filedes)", ARG1, 2*sizeof(long) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4649 | POST(sys_pipe) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4650 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4651 | Int *p = (Int *)ARG1; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4652 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4653 | if (!ML_(fd_allowed)(p[0], "pipe", tid, True) || |
| 4654 | !ML_(fd_allowed)(p[1], "pipe", tid, True)) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4655 | VG_(close)(p[0]); |
| 4656 | VG_(close)(p[1]); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4657 | SET_STATUS_Failure( VKI_EMFILE ); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 4658 | } else { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4659 | POST_MEM_WRITE( ARG1, 2*sizeof(int) ); |
nethercote | 493dd18 | 2004-02-24 23:57:47 +0000 | [diff] [blame] | 4660 | if (VG_(clo_track_fds)) { |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 4661 | ML_(record_fd_open_nameless)(tid, p[0]); |
| 4662 | ML_(record_fd_open_nameless)(tid, p[1]); |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 4663 | } |
| 4664 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4665 | } |
| 4666 | |
nethercote | f90953e | 2004-11-15 14:50:02 +0000 | [diff] [blame] | 4667 | // XXX: x86-specific, due to pollfd struct |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4668 | PRE(sys_poll) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4669 | { |
| 4670 | /* struct pollfd { |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4671 | int fd; -- file descriptor |
| 4672 | short events; -- requested events |
| 4673 | short revents; -- returned events |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4674 | }; |
nethercote | eb0592d | 2004-11-05 12:02:27 +0000 | [diff] [blame] | 4675 | int poll(struct pollfd *ufds, unsigned int nfds, int timeout) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4676 | */ |
nethercote | eb0592d | 2004-11-05 12:02:27 +0000 | [diff] [blame] | 4677 | UInt i; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4678 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4679 | struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1; |
| 4680 | PRINT("sys_poll ( %p, %d, %d )\n", ARG1,ARG2,ARG3); |
nethercote | f90953e | 2004-11-15 14:50:02 +0000 | [diff] [blame] | 4681 | PRE_REG_READ3(long, "poll", |
| 4682 | struct pollfd *, ufds, unsigned int, nfds, long, timeout); |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4683 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4684 | for (i = 0; i < ARG2; i++) { |
nethercote | eb0592d | 2004-11-05 12:02:27 +0000 | [diff] [blame] | 4685 | // 'fd' and 'events' field are inputs; 'revents' is output. |
| 4686 | // XXX: this is x86 specific -- the pollfd struct varies across |
| 4687 | // different architectures. |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4688 | PRE_MEM_READ( "poll(ufds)", |
| 4689 | (Addr)(&ufds[i]), sizeof(int) + sizeof(short) ); |
| 4690 | PRE_MEM_WRITE( "poll(ufds)", (Addr)(&ufds[i].revents), sizeof(short) ); |
| 4691 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4694 | POST(sys_poll) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4695 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4696 | if (RES > 0) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4697 | UInt i; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4698 | struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1; |
nethercote | eb0592d | 2004-11-05 12:02:27 +0000 | [diff] [blame] | 4699 | // XXX: again, this is x86-specific |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4700 | for (i = 0; i < ARG2; i++) |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4701 | POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(Short) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4702 | } |
| 4703 | } |
| 4704 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4705 | PRE(sys_readlink) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4706 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4707 | Word saved = SYSNO; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4708 | PRINT("sys_readlink ( %p, %p, %llu )", ARG1,ARG2,(ULong)ARG3); |
nethercote | 5a945af | 2004-11-14 18:37:07 +0000 | [diff] [blame] | 4709 | PRE_REG_READ3(long, "readlink", |
| 4710 | const char *, path, char *, buf, int, bufsiz); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4711 | PRE_MEM_RASCIIZ( "readlink(path)", ARG1 ); |
| 4712 | PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4713 | |
rjwalsh | 17d8530 | 2004-11-18 22:56:09 +0000 | [diff] [blame] | 4714 | /* |
rjwalsh | 093047d | 2004-11-19 02:11:56 +0000 | [diff] [blame] | 4715 | * Handle the case where readlink is looking at /proc/self/exe or |
| 4716 | * /proc/<pid>/exe. |
rjwalsh | 17d8530 | 2004-11-18 22:56:09 +0000 | [diff] [blame] | 4717 | */ |
| 4718 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4719 | SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3)); |
rjwalsh | 093047d | 2004-11-19 02:11:56 +0000 | [diff] [blame] | 4720 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4721 | /* jrs 20050604: where does the magic value 2 come from? It seems |
| 4722 | like it should be a kernel error value, but we don't know of any |
| 4723 | such. */ |
| 4724 | if (SWHAT == SsFailure && RES_unchecked == 2) { |
| 4725 | HChar name[25]; |
rjwalsh | 093047d | 2004-11-19 02:11:56 +0000 | [diff] [blame] | 4726 | VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)()); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4727 | if (VG_(strcmp)((Char *)ARG1, name) == 0 || |
| 4728 | VG_(strcmp)((Char *)ARG1, "/proc/self/exe") == 0) { |
rjwalsh | 093047d | 2004-11-19 02:11:56 +0000 | [diff] [blame] | 4729 | VG_(sprintf)(name, "/proc/self/fd/%d", VG_(clexecfd)); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4730 | SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, (UWord)name, ARG2, ARG3)); |
rjwalsh | 093047d | 2004-11-19 02:11:56 +0000 | [diff] [blame] | 4731 | } |
rjwalsh | 17d8530 | 2004-11-18 22:56:09 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4734 | if (SUCCESS && RES > 0) |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4735 | POST_MEM_WRITE( ARG2, RES ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4738 | PRE(sys_readv) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4739 | { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4740 | Int i; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 4741 | struct vki_iovec * vec; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4742 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4743 | PRINT("sys_readv ( %d, %p, %llu )",ARG1,ARG2,(ULong)ARG3); |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 4744 | PRE_REG_READ3(ssize_t, "readv", |
| 4745 | unsigned long, fd, const struct iovec *, vector, |
| 4746 | unsigned long, count); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 4747 | if (!ML_(fd_allowed)(ARG1, "readv", tid, False)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4748 | SET_STATUS_Failure( VKI_EBADF ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4749 | } else { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4750 | PRE_MEM_READ( "readv(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) ); |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 4751 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4752 | if (ARG2 != 0) { |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 4753 | /* ToDo: don't do any of the following if the vector is invalid */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4754 | vec = (struct vki_iovec *)ARG2; |
| 4755 | for (i = 0; i < (Int)ARG3; i++) |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 4756 | PRE_MEM_WRITE( "readv(vector[...])", |
| 4757 | (Addr)vec[i].iov_base, vec[i].iov_len ); |
| 4758 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 4762 | POST(sys_readv) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4763 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4764 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4765 | if (RES > 0) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4766 | Int i; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4767 | struct vki_iovec * vec = (struct vki_iovec *)ARG2; |
| 4768 | Int remains = RES; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4769 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4770 | /* RES holds the number of bytes read. */ |
| 4771 | for (i = 0; i < (Int)ARG3; i++) { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4772 | Int nReadThisBuf = vec[i].iov_len; |
| 4773 | if (nReadThisBuf > remains) nReadThisBuf = remains; |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 4774 | POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4775 | remains -= nReadThisBuf; |
| 4776 | if (remains < 0) VG_(core_panic)("readv: remains < 0"); |
| 4777 | } |
| 4778 | } |
| 4779 | } |
| 4780 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4781 | PRE(sys_rename) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4782 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4783 | PRINT("sys_rename ( %p, %p )", ARG1, ARG2 ); |
nethercote | 9a3beb9 | 2004-11-12 17:07:26 +0000 | [diff] [blame] | 4784 | PRE_REG_READ2(long, "rename", const char *, oldpath, const char *, newpath); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4785 | PRE_MEM_RASCIIZ( "rename(oldpath)", ARG1 ); |
| 4786 | PRE_MEM_RASCIIZ( "rename(newpath)", ARG2 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4787 | } |
| 4788 | |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 4789 | PRE(sys_rmdir) |
| 4790 | { |
| 4791 | *flags |= SfMayBlock; |
| 4792 | PRINT("sys_rmdir ( %p )", ARG1); |
| 4793 | PRE_REG_READ1(long, "rmdir", const char *, pathname); |
| 4794 | PRE_MEM_RASCIIZ( "rmdir(pathname)", ARG1 ); |
| 4795 | } |
| 4796 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4797 | PRE(sys_sched_setparam) |
| 4798 | { |
| 4799 | PRINT("sched_setparam ( %d, %p )", ARG1, ARG2 ); |
| 4800 | PRE_REG_READ2(long, "sched_setparam", |
| 4801 | vki_pid_t, pid, struct sched_param *, p); |
| 4802 | PRE_MEM_READ( "sched_setparam(p)", ARG2, sizeof(struct vki_sched_param) ); |
| 4803 | } |
| 4804 | POST(sys_sched_setparam) |
| 4805 | { |
| 4806 | POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) ); |
| 4807 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 4808 | |
| 4809 | PRE(sys_sched_getparam) |
| 4810 | { |
| 4811 | PRINT("sched_getparam ( %d, %p )", ARG1, ARG2 ); |
| 4812 | PRE_REG_READ2(long, "sched_getparam", |
| 4813 | vki_pid_t, pid, struct sched_param *, p); |
| 4814 | PRE_MEM_WRITE( "sched_getparam(p)", ARG2, sizeof(struct vki_sched_param) ); |
| 4815 | } |
| 4816 | |
| 4817 | POST(sys_sched_getparam) |
| 4818 | { |
| 4819 | POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) ); |
| 4820 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4821 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4822 | PRE(sys_select) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4823 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4824 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4825 | PRINT("sys_select ( %d, %p, %p, %p, %p )", ARG1,ARG2,ARG3,ARG4,ARG5); |
nethercote | f1049bf | 2004-11-14 17:03:47 +0000 | [diff] [blame] | 4826 | PRE_REG_READ5(long, "select", |
| 4827 | int, n, vki_fd_set *, readfds, vki_fd_set *, writefds, |
| 4828 | vki_fd_set *, exceptfds, struct timeval *, timeout); |
| 4829 | // XXX: this possibly understates how much memory is read. |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4830 | if (ARG2 != 0) |
nethercote | f1049bf | 2004-11-14 17:03:47 +0000 | [diff] [blame] | 4831 | PRE_MEM_READ( "select(readfds)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4832 | ARG2, ARG1/8 /* __FD_SETSIZE/8 */ ); |
| 4833 | if (ARG3 != 0) |
nethercote | f1049bf | 2004-11-14 17:03:47 +0000 | [diff] [blame] | 4834 | PRE_MEM_READ( "select(writefds)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4835 | ARG3, ARG1/8 /* __FD_SETSIZE/8 */ ); |
| 4836 | if (ARG4 != 0) |
nethercote | f1049bf | 2004-11-14 17:03:47 +0000 | [diff] [blame] | 4837 | PRE_MEM_READ( "select(exceptfds)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4838 | ARG4, ARG1/8 /* __FD_SETSIZE/8 */ ); |
| 4839 | if (ARG5 != 0) |
| 4840 | PRE_MEM_READ( "select(timeout)", ARG5, sizeof(struct vki_timeval) ); |
nethercote | f1049bf | 2004-11-14 17:03:47 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 4843 | PRE(sys_setgid16) |
| 4844 | { |
| 4845 | PRINT("sys_setgid16 ( %d )", ARG1); |
| 4846 | PRE_REG_READ1(long, "setgid16", vki_old_gid_t, gid); |
| 4847 | } |
| 4848 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4849 | PRE(sys_setgid) |
| 4850 | { |
| 4851 | PRINT("sys_setgid ( %d )", ARG1); |
| 4852 | PRE_REG_READ1(long, "setgid", vki_gid_t, gid); |
| 4853 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 4854 | |
| 4855 | PRE(sys_setsid) |
| 4856 | { |
| 4857 | PRINT("sys_setsid ( )"); |
| 4858 | PRE_REG_READ0(long, "setsid"); |
| 4859 | } |
| 4860 | |
| 4861 | PRE(sys_setgroups16) |
| 4862 | { |
| 4863 | PRINT("sys_setgroups16 ( %llu, %p )", (ULong)ARG1, ARG2); |
| 4864 | PRE_REG_READ2(long, "setgroups16", int, size, vki_old_gid_t *, list); |
| 4865 | if (ARG1 > 0) |
| 4866 | PRE_MEM_READ( "setgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) ); |
| 4867 | } |
| 4868 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4869 | PRE(sys_setgroups) |
| 4870 | { |
| 4871 | PRINT("setgroups ( %llu, %p )", (ULong)ARG1, ARG2); |
| 4872 | PRE_REG_READ2(long, "setgroups", int, size, vki_gid_t *, list); |
| 4873 | if (ARG1 > 0) |
| 4874 | PRE_MEM_READ( "setgroups(list)", ARG2, ARG1 * sizeof(vki_gid_t) ); |
| 4875 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 4876 | |
| 4877 | PRE(sys_setpgid) |
| 4878 | { |
| 4879 | PRINT("setpgid ( %d, %d )", ARG1, ARG2); |
| 4880 | PRE_REG_READ2(long, "setpgid", vki_pid_t, pid, vki_pid_t, pgid); |
| 4881 | } |
| 4882 | |
| 4883 | PRE(sys_setregid) |
| 4884 | { |
| 4885 | PRINT("sys_setregid ( %d, %d )", ARG1, ARG2); |
| 4886 | PRE_REG_READ2(long, "setregid", vki_gid_t, rgid, vki_gid_t, egid); |
| 4887 | } |
| 4888 | |
| 4889 | PRE(sys_setreuid16) |
| 4890 | { |
| 4891 | PRINT("setreuid16 ( 0x%x, 0x%x )", ARG1, ARG2); |
| 4892 | PRE_REG_READ2(long, "setreuid16", vki_old_uid_t, ruid, vki_old_uid_t, euid); |
| 4893 | } |
| 4894 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4895 | PRE(sys_setreuid) |
| 4896 | { |
| 4897 | PRINT("sys_setreuid ( 0x%x, 0x%x )", ARG1, ARG2); |
| 4898 | PRE_REG_READ2(long, "setreuid", vki_uid_t, ruid, vki_uid_t, euid); |
| 4899 | } |
nethercote | 9c311eb | 2004-11-12 18:20:12 +0000 | [diff] [blame] | 4900 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4901 | PRE(sys_setrlimit) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4902 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4903 | PRINT("sys_setrlimit ( %d, %p )", ARG1,ARG2); |
nethercote | 17258dc | 2004-11-12 19:55:08 +0000 | [diff] [blame] | 4904 | PRE_REG_READ2(long, "setrlimit", |
| 4905 | unsigned int, resource, struct rlimit *, rlim); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4906 | PRE_MEM_READ( "setrlimit(rlim)", ARG2, sizeof(struct vki_rlimit) ); |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 4907 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4908 | if (ARG1 == VKI_RLIMIT_NOFILE) { |
| 4909 | if (((struct vki_rlimit *)ARG2)->rlim_cur > VG_(fd_hard_limit) || |
| 4910 | ((struct vki_rlimit *)ARG2)->rlim_max != VG_(fd_hard_limit)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4911 | SET_STATUS_Failure( VKI_EPERM ); |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 4912 | } |
| 4913 | else { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4914 | VG_(fd_soft_limit) = ((struct vki_rlimit *)ARG2)->rlim_cur; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4915 | SET_STATUS_Success( 0 ); |
thughes | ad1c956 | 2004-06-26 11:27:52 +0000 | [diff] [blame] | 4916 | } |
| 4917 | } |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4918 | else if (ARG1 == VKI_RLIMIT_DATA) { |
| 4919 | if (((struct vki_rlimit *)ARG2)->rlim_cur > ((struct vki_rlimit *)ARG2)->rlim_max || |
| 4920 | ((struct vki_rlimit *)ARG2)->rlim_max > ((struct vki_rlimit *)ARG2)->rlim_max) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4921 | SET_STATUS_Failure( VKI_EPERM ); |
thughes | aa4fb11 | 2004-09-11 14:19:25 +0000 | [diff] [blame] | 4922 | } |
| 4923 | else { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4924 | VG_(client_rlimit_data) = *(struct vki_rlimit *)ARG2; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4925 | SET_STATUS_Success( 0 ); |
thughes | aa4fb11 | 2004-09-11 14:19:25 +0000 | [diff] [blame] | 4926 | } |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 4927 | } |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4928 | else if (ARG1 == VKI_RLIMIT_STACK && tid == 1) { |
| 4929 | if (((struct vki_rlimit *)ARG2)->rlim_cur > ((struct vki_rlimit *)ARG2)->rlim_max || |
| 4930 | ((struct vki_rlimit *)ARG2)->rlim_max > ((struct vki_rlimit *)ARG2)->rlim_max) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4931 | SET_STATUS_Failure( VKI_EPERM ); |
thughes | c37184f | 2004-09-11 14:16:57 +0000 | [diff] [blame] | 4932 | } |
| 4933 | else { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4934 | VG_(threads)[tid].client_stack_szB = ((struct vki_rlimit *)ARG2)->rlim_cur; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4935 | VG_(client_rlimit_stack) = *(struct vki_rlimit *)ARG2; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4936 | SET_STATUS_Success( 0 ); |
thughes | c37184f | 2004-09-11 14:16:57 +0000 | [diff] [blame] | 4937 | } |
| 4938 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 4941 | PRE(sys_setuid16) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4942 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 4943 | PRINT("sys_setuid16 ( %d )", ARG1); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 4944 | PRE_REG_READ1(long, "setuid16", vki_old_uid_t, uid); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4947 | PRE(sys_setuid) |
| 4948 | { |
| 4949 | PRINT("sys_setuid ( %d )", ARG1); |
| 4950 | PRE_REG_READ1(long, "setuid", vki_uid_t, uid); |
| 4951 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 4952 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 4953 | PRE(sys_newstat) |
| 4954 | { |
| 4955 | PRINT("sys_newstat ( %p(%s), %p )", ARG1,ARG1,ARG2); |
| 4956 | PRE_REG_READ2(long, "stat", char *, file_name, struct stat *, buf); |
| 4957 | PRE_MEM_RASCIIZ( "stat(file_name)", ARG1 ); |
| 4958 | PRE_MEM_WRITE( "stat(buf)", ARG2, sizeof(struct vki_stat) ); |
| 4959 | } |
| 4960 | |
| 4961 | POST(sys_newstat) |
| 4962 | { |
| 4963 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) ); |
| 4964 | } |
| 4965 | |
| 4966 | PRE(sys_statfs) |
| 4967 | { |
| 4968 | PRINT("sys_statfs ( %p, %p )",ARG1,ARG2); |
| 4969 | PRE_REG_READ2(long, "statfs", const char *, path, struct statfs *, buf); |
| 4970 | PRE_MEM_RASCIIZ( "statfs(path)", ARG1 ); |
| 4971 | PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_statfs) ); |
| 4972 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 4973 | POST(sys_statfs) |
| 4974 | { |
| 4975 | POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) ); |
| 4976 | } |
| 4977 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 4978 | PRE(sys_statfs64) |
| 4979 | { |
| 4980 | PRINT("sys_statfs64 ( %p, %llu, %p )",ARG1,(ULong)ARG2,ARG3); |
| 4981 | PRE_REG_READ3(long, "statfs64", |
| 4982 | const char *, path, vki_size_t, size, struct statfs64 *, buf); |
| 4983 | PRE_MEM_RASCIIZ( "statfs64(path)", ARG1 ); |
| 4984 | PRE_MEM_WRITE( "statfs64(buf)", ARG3, ARG2 ); |
| 4985 | } |
| 4986 | POST(sys_statfs64) |
| 4987 | { |
| 4988 | POST_MEM_WRITE( ARG3, ARG2 ); |
| 4989 | } |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 4990 | |
| 4991 | PRE(sys_symlink) |
| 4992 | { |
| 4993 | *flags |= SfMayBlock; |
| 4994 | PRINT("sys_symlink ( %p, %p )",ARG1,ARG2); |
| 4995 | PRE_REG_READ2(long, "symlink", const char *, oldpath, const char *, newpath); |
| 4996 | PRE_MEM_RASCIIZ( "symlink(oldpath)", ARG1 ); |
| 4997 | PRE_MEM_RASCIIZ( "symlink(newpath)", ARG2 ); |
| 4998 | } |
sewardj | 9efbbef | 2005-03-01 16:45:23 +0000 | [diff] [blame] | 4999 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5000 | PRE(sys_time) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5001 | { |
| 5002 | /* time_t time(time_t *t); */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5003 | PRINT("sys_time ( %p )",ARG1); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 5004 | PRE_REG_READ1(long, "time", int *, t); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5005 | if (ARG1 != 0) { |
| 5006 | PRE_MEM_WRITE( "time(t)", ARG1, sizeof(vki_time_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5007 | } |
| 5008 | } |
| 5009 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5010 | POST(sys_time) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5011 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5012 | if (ARG1 != 0) { |
| 5013 | POST_MEM_WRITE( ARG1, sizeof(vki_time_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5014 | } |
| 5015 | } |
| 5016 | |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 5017 | PRE(sys_times) |
| 5018 | { |
| 5019 | PRINT("sys_times ( %p )", ARG1); |
| 5020 | PRE_REG_READ1(long, "times", struct tms *, buf); |
| 5021 | PRE_MEM_WRITE( "times(buf)", ARG1, sizeof(struct vki_tms) ); |
| 5022 | } |
| 5023 | |
| 5024 | POST(sys_times) |
| 5025 | { |
| 5026 | if (ARG1 != 0) { |
| 5027 | POST_MEM_WRITE( ARG1, sizeof(struct vki_tms) ); |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | PRE(sys_umask) |
| 5032 | { |
| 5033 | PRINT("sys_umask ( %d )", ARG1); |
| 5034 | PRE_REG_READ1(long, "umask", int, mask); |
| 5035 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5036 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5037 | PRE(sys_unlink) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5038 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5039 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5040 | PRINT("sys_unlink ( %p(%s) )", ARG1,ARG1); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 5041 | PRE_REG_READ1(long, "unlink", const char *, pathname); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5042 | PRE_MEM_RASCIIZ( "unlink(pathname)", ARG1 ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5045 | PRE(sys_newuname) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5046 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5047 | PRINT("sys_newuname ( %p )", ARG1); |
nethercote | 1a1b9b7 | 2004-11-12 11:19:36 +0000 | [diff] [blame] | 5048 | PRE_REG_READ1(long, "uname", struct new_utsname *, buf); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5049 | PRE_MEM_WRITE( "uname(buf)", ARG1, sizeof(struct vki_new_utsname) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5052 | POST(sys_newuname) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5053 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5054 | if (ARG1 != 0) { |
| 5055 | POST_MEM_WRITE( ARG1, sizeof(struct vki_new_utsname) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5056 | } |
| 5057 | } |
| 5058 | |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5059 | PRE(sys_utime) |
| 5060 | { |
| 5061 | *flags |= SfMayBlock; |
| 5062 | PRINT("sys_utime ( %p, %p )", ARG1,ARG2); |
| 5063 | PRE_REG_READ2(long, "utime", char *, filename, struct utimbuf *, buf); |
| 5064 | PRE_MEM_RASCIIZ( "utime(filename)", ARG1 ); |
| 5065 | if (ARG2 != 0) |
| 5066 | PRE_MEM_READ( "utime(buf)", ARG2, sizeof(struct vki_utimbuf) ); |
| 5067 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5068 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5069 | PRE(sys_waitpid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5070 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5071 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5072 | PRINT("sys_waitpid ( %d, %p, %d )", ARG1,ARG2,ARG3); |
nethercote | c6851dd | 2004-11-11 18:00:47 +0000 | [diff] [blame] | 5073 | PRE_REG_READ3(long, "waitpid", |
| 5074 | vki_pid_t, pid, unsigned int *, status, int, options); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5075 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5076 | if (ARG2 != (Addr)NULL) |
| 5077 | PRE_MEM_WRITE( "waitpid(status)", ARG2, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5080 | POST(sys_waitpid) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5081 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5082 | if (ARG2 != (Addr)NULL) |
| 5083 | POST_MEM_WRITE( ARG2, sizeof(int) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5084 | } |
| 5085 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5086 | PRE(sys_wait4) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5087 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5088 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5089 | PRINT("sys_wait4 ( %d, %p, %d, %p )", ARG1,ARG2,ARG3,ARG4); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5090 | |
nethercote | 7f7e4d1 | 2004-11-15 12:28:58 +0000 | [diff] [blame] | 5091 | PRE_REG_READ4(long, "wait4", |
| 5092 | vki_pid_t, pid, unsigned int *, status, int, options, |
| 5093 | struct rusage *, rusage); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5094 | if (ARG2 != (Addr)NULL) |
| 5095 | PRE_MEM_WRITE( "wait4(status)", ARG2, sizeof(int) ); |
| 5096 | if (ARG4 != (Addr)NULL) |
| 5097 | PRE_MEM_WRITE( "wait4(rusage)", ARG4, sizeof(struct vki_rusage) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5100 | POST(sys_wait4) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5101 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5102 | if (ARG2 != (Addr)NULL) |
| 5103 | POST_MEM_WRITE( ARG2, sizeof(int) ); |
| 5104 | if (ARG4 != (Addr)NULL) |
| 5105 | POST_MEM_WRITE( ARG4, sizeof(struct vki_rusage) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5108 | PRE(sys_writev) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5109 | { |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5110 | Int i; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 5111 | struct vki_iovec * vec; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5112 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5113 | PRINT("sys_writev ( %d, %p, %llu )",ARG1,ARG2,(ULong)ARG3); |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 5114 | PRE_REG_READ3(ssize_t, "writev", |
| 5115 | unsigned long, fd, const struct iovec *, vector, |
| 5116 | unsigned long, count); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5117 | if (!ML_(fd_allowed)(ARG1, "writev", tid, False)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5118 | SET_STATUS_Failure( VKI_EBADF ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5119 | } else { |
nethercote | ef0c766 | 2004-11-06 15:38:43 +0000 | [diff] [blame] | 5120 | PRE_MEM_READ( "writev(vector)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5121 | ARG2, ARG3 * sizeof(struct vki_iovec) ); |
| 5122 | if (ARG2 != 0) { |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 5123 | /* ToDo: don't do any of the following if the vector is invalid */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5124 | vec = (struct vki_iovec *)ARG2; |
| 5125 | for (i = 0; i < (Int)ARG3; i++) |
nethercote | d6b5a21 | 2004-11-15 17:04:14 +0000 | [diff] [blame] | 5126 | PRE_MEM_READ( "writev(vector[...])", |
| 5127 | (Addr)vec[i].iov_base, vec[i].iov_len ); |
| 5128 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5129 | } |
| 5130 | } |
| 5131 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5132 | PRE(sys_utimes) |
| 5133 | { |
| 5134 | PRINT("sys_utimes ( %p, %p )", ARG1,ARG2); |
| 5135 | PRE_REG_READ2(long, "utimes", char *, filename, struct timeval *, tvp); |
| 5136 | PRE_MEM_RASCIIZ( "utimes(filename)", ARG1 ); |
| 5137 | if (ARG2 != 0) |
| 5138 | PRE_MEM_READ( "utimes(tvp)", ARG2, sizeof(struct vki_timeval) ); |
| 5139 | } |
| 5140 | |
| 5141 | PRE(sys_sched_setaffinity) |
| 5142 | { |
| 5143 | PRINT("sched_setaffinity ( %d, %d, %p )", ARG1, ARG2, ARG3); |
| 5144 | PRE_REG_READ3(long, "sched_setaffinity", |
| 5145 | vki_pid_t, pid, unsigned int, len, unsigned long *, mask); |
| 5146 | PRE_MEM_READ( "sched_setaffinity(mask)", ARG3, ARG2); |
| 5147 | } |
| 5148 | |
| 5149 | PRE(sys_sched_getaffinity) |
| 5150 | { |
| 5151 | PRINT("sched_getaffinity ( %d, %d, %p )", ARG1, ARG2, ARG3); |
| 5152 | PRE_REG_READ3(long, "sched_getaffinity", |
| 5153 | vki_pid_t, pid, unsigned int, len, unsigned long *, mask); |
| 5154 | PRE_MEM_WRITE( "sched_getaffinity(mask)", ARG3, ARG2); |
| 5155 | } |
| 5156 | POST(sys_sched_getaffinity) |
| 5157 | { |
| 5158 | POST_MEM_WRITE(ARG3, ARG2); |
| 5159 | } |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 5160 | |
| 5161 | PRE(sys_acct) |
| 5162 | { |
| 5163 | PRINT("sys_acct ( %p )", ARG1); |
| 5164 | PRE_REG_READ1(long, "acct", const char *, filename); |
| 5165 | PRE_MEM_RASCIIZ( "acct(filename)", ARG1 ); |
| 5166 | } |
mueller | d3502b6 | 2003-11-19 00:43:57 +0000 | [diff] [blame] | 5167 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5168 | PRE(sys_pause) |
thughes | 2f8d5f8 | 2004-09-11 14:29:19 +0000 | [diff] [blame] | 5169 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5170 | *flags |= SfMayBlock; |
nethercote | 0df495a | 2004-11-11 16:38:21 +0000 | [diff] [blame] | 5171 | PRINT("sys_pause ( )"); |
| 5172 | PRE_REG_READ0(long, "pause"); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5175 | //zz // XXX: x86-specific |
| 5176 | //zz PRE(sys_sigsuspend, SfMayBlock) |
| 5177 | //zz { |
| 5178 | //zz /* The C library interface to sigsuspend just takes a pointer to |
| 5179 | //zz a signal mask but this system call has three arguments - the first |
| 5180 | //zz two don't appear to be used by the kernel and are always passed as |
| 5181 | //zz zero by glibc and the third is the first word of the signal mask |
| 5182 | //zz so only 32 signals are supported. |
| 5183 | //zz |
| 5184 | //zz In fact glibc normally uses rt_sigsuspend if it is available as |
| 5185 | //zz that takes a pointer to the signal mask so supports more signals. |
| 5186 | //zz */ |
| 5187 | //zz PRINT("sys_sigsuspend ( %d, %d, %d )", ARG1,ARG2,ARG3 ); |
| 5188 | //zz PRE_REG_READ3(int, "sigsuspend", |
| 5189 | //zz int, history0, int, history1, |
| 5190 | //zz vki_old_sigset_t, mask); |
| 5191 | //zz } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5192 | |
nethercote | a3a2c14 | 2004-11-14 14:13:05 +0000 | [diff] [blame] | 5193 | // XXX: x86-specific |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5194 | PRE(sys_rt_sigsuspend) |
nethercote | a3a2c14 | 2004-11-14 14:13:05 +0000 | [diff] [blame] | 5195 | { |
thughes | c3e85df | 2004-11-15 09:27:24 +0000 | [diff] [blame] | 5196 | /* The C library interface to sigsuspend just takes a pointer to |
| 5197 | a signal mask but this system call has two arguments - a pointer |
| 5198 | to the mask and the number of bytes used by it. The kernel insists |
| 5199 | on the size being equal to sizeof(sigset_t) however and will just |
| 5200 | return EINVAL if it isn't. |
| 5201 | */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5202 | *flags |= SfMayBlock; |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5203 | PRINT("sys_rt_sigsuspend ( %p, %d )", ARG1,ARG2 ); |
nethercote | a3a2c14 | 2004-11-14 14:13:05 +0000 | [diff] [blame] | 5204 | PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t *, mask, vki_size_t, size) |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5205 | if (ARG1 != (Addr)NULL) { |
| 5206 | PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1, sizeof(vki_sigset_t) ); |
nethercote | a3a2c14 | 2004-11-14 14:13:05 +0000 | [diff] [blame] | 5207 | } |
| 5208 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5209 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5210 | PRE(sys_rt_sigtimedwait) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5211 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5212 | *flags |= SfMayBlock; |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 5213 | PRINT("sys_rt_sigtimedwait ( %p, %p, %p, %lld )", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5214 | ARG1,ARG2,ARG3,(ULong)ARG4); |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 5215 | PRE_REG_READ4(long, "rt_sigtimedwait", |
| 5216 | const vki_sigset_t *, set, vki_siginfo_t *, info, |
| 5217 | const struct timespec *, timeout, vki_size_t, sigsetsize); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5218 | if (ARG1 != 0) |
| 5219 | PRE_MEM_READ( "rt_sigtimedwait(set)", ARG1, sizeof(vki_sigset_t)); |
| 5220 | if (ARG2 != 0) |
| 5221 | PRE_MEM_WRITE( "rt_sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) ); |
nethercote | ac866b9 | 2004-11-15 20:23:15 +0000 | [diff] [blame] | 5222 | PRE_MEM_READ( "rt_sigtimedwait(timeout)", |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5223 | ARG4, sizeof(struct vki_timespec) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5226 | POST(sys_rt_sigtimedwait) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5227 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5228 | if (ARG2 != 0) |
| 5229 | POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5232 | PRE(sys_rt_sigqueueinfo) |
| 5233 | { |
| 5234 | PRINT("sys_rt_sigqueueinfo(%d, %d, %p)", ARG1, ARG2, ARG3); |
| 5235 | PRE_REG_READ3(long, "rt_sigqueueinfo", |
| 5236 | int, pid, int, sig, vki_siginfo_t *, uinfo); |
| 5237 | if (ARG2 != 0) |
| 5238 | PRE_MEM_READ( "rt_sigqueueinfo(uinfo)", ARG3, sizeof(vki_siginfo_t) ); |
| 5239 | } |
| 5240 | POST(sys_rt_sigqueueinfo) |
| 5241 | { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5242 | if (!ML_(client_signal_OK)(ARG2)) |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5243 | SET_STATUS_Failure( VKI_EINVAL ); |
| 5244 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5245 | |
nethercote | b77dee6 | 2004-11-16 17:13:24 +0000 | [diff] [blame] | 5246 | // XXX: x86-specific |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5247 | PRE(sys_sigaltstack) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5248 | { |
| 5249 | /* int sigaltstack(const stack_t *ss, stack_t *oss); */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5250 | PRINT("sigaltstack ( %p, %p )",ARG1,ARG2); |
nethercote | b77dee6 | 2004-11-16 17:13:24 +0000 | [diff] [blame] | 5251 | PRE_REG_READ2(int, "sigaltstack", |
| 5252 | const vki_stack_t *, ss, vki_stack_t *, oss); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5253 | if (ARG1 != 0) { |
| 5254 | PRE_MEM_READ( "sigaltstack(ss)", ARG1, sizeof(vki_stack_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5255 | } |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5256 | if (ARG2 != 0) { |
| 5257 | PRE_MEM_WRITE( "sigaltstack(oss)", ARG2, sizeof(vki_stack_t) ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5260 | SET_STATUS_from_SysRes( |
| 5261 | VG_(do_sys_sigaltstack) (tid, (vki_stack_t*)ARG1, |
| 5262 | (vki_stack_t*)ARG2) |
| 5263 | ); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5264 | } |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5265 | POST(sys_sigaltstack) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5266 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5267 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5268 | if (RES == 0 && ARG2 != 0) |
| 5269 | POST_MEM_WRITE( ARG2, sizeof(vki_stack_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5270 | } |
| 5271 | |
nethercote | 71f05f3 | 2004-11-12 18:49:27 +0000 | [diff] [blame] | 5272 | // XXX: x86-specific |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5273 | PRE(sys_rt_sigaction) |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5274 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5275 | PRINT("sys_rt_sigaction ( %d, %p, %p, %d )", ARG1,ARG2,ARG3,ARG4); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5276 | PRE_REG_READ4(long, "rt_sigaction", |
| 5277 | int, signum, const struct sigaction *, act, |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5278 | struct sigaction *, oldact, vki_size_t, sigsetsize); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5279 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5280 | if (ARG2 != 0) |
| 5281 | PRE_MEM_READ( "rt_sigaction(act)", ARG2, sizeof(struct vki_sigaction)); |
| 5282 | if (ARG3 != 0) |
| 5283 | PRE_MEM_WRITE( "rt_sigaction(oldact)", ARG3, sizeof(struct vki_sigaction)); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5284 | |
njn | b249fd7 | 2004-11-29 14:24:57 +0000 | [diff] [blame] | 5285 | // XXX: doesn't seem right to be calling do_sys_sigaction for |
| 5286 | // sys_rt_sigaction... perhaps this function should be renamed |
| 5287 | // VG_(do_sys_rt_sigaction)() --njn |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 5288 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5289 | SET_STATUS_from_SysRes( |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 5290 | VG_(do_sys_sigaction)(ARG1, (const struct vki_sigaction *)ARG2, |
| 5291 | (struct vki_sigaction *)ARG3) |
| 5292 | ); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5293 | } |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5294 | POST(sys_rt_sigaction) |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5295 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5296 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5297 | if (RES == 0 && ARG3 != 0) |
| 5298 | POST_MEM_WRITE( ARG3, sizeof(struct vki_sigaction)); |
nethercote | 686b5db | 2004-11-14 13:42:51 +0000 | [diff] [blame] | 5299 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5300 | |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 5301 | // XXX: This syscall is not used on amd64 -- it only provides |
| 5302 | // sys_rt_sigprocmask, which uses sigset_t rather than old_sigset_t. |
| 5303 | // This wrapper is only suitable for 32-bit architectures. |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5304 | #if defined(VGP_x86_linux) |
| 5305 | PRE(sys_sigprocmask) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5306 | { |
sewardj | 970ac79 | 2004-12-31 18:09:32 +0000 | [diff] [blame] | 5307 | vki_old_sigset_t* set; |
| 5308 | vki_old_sigset_t* oldset; |
| 5309 | vki_sigset_t bigger_set; |
| 5310 | vki_sigset_t bigger_oldset; |
| 5311 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5312 | PRINT("sys_sigprocmask ( %d, %p, %p )",ARG1,ARG2,ARG3); |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5313 | PRE_REG_READ3(long, "sigprocmask", |
| 5314 | int, how, vki_old_sigset_t *, set, vki_old_sigset_t *, oldset); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5315 | if (ARG2 != 0) |
| 5316 | PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_old_sigset_t)); |
| 5317 | if (ARG3 != 0) |
| 5318 | PRE_MEM_WRITE( "sigprocmask(oldset)", ARG3, sizeof(vki_old_sigset_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5319 | |
njn | b249fd7 | 2004-11-29 14:24:57 +0000 | [diff] [blame] | 5320 | // Nb: We must convert the smaller vki_old_sigset_t params into bigger |
| 5321 | // vki_sigset_t params. |
sewardj | 970ac79 | 2004-12-31 18:09:32 +0000 | [diff] [blame] | 5322 | set = (vki_old_sigset_t*)ARG2; |
| 5323 | oldset = (vki_old_sigset_t*)ARG3; |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5324 | |
sewardj | 1f27662 | 2004-12-06 16:18:58 +0000 | [diff] [blame] | 5325 | VG_(memset)(&bigger_set, 0, sizeof(vki_sigset_t)); |
| 5326 | VG_(memset)(&bigger_oldset, 0, sizeof(vki_sigset_t)); |
| 5327 | if (set) |
| 5328 | bigger_set.sig[0] = *(vki_old_sigset_t*)set; |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5329 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5330 | SET_STATUS_from_SysRes( |
njn | 4fbc86c | 2005-05-08 00:45:11 +0000 | [diff] [blame] | 5331 | VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/, |
| 5332 | set ? &bigger_set : NULL, |
| 5333 | oldset ? &bigger_oldset : NULL) |
| 5334 | ); |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5335 | |
njn | b249fd7 | 2004-11-29 14:24:57 +0000 | [diff] [blame] | 5336 | if (oldset) |
| 5337 | *oldset = bigger_oldset.sig[0]; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5338 | |
| 5339 | if (SUCCESS) |
| 5340 | *flags |= SfPollAfter; |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5343 | POST(sys_sigprocmask) |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5344 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5345 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5346 | if (RES == 0 && ARG3 != 0) |
| 5347 | POST_MEM_WRITE( ARG3, sizeof(vki_old_sigset_t)); |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5348 | } |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 5349 | #endif |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5350 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5351 | PRE(sys_rt_sigprocmask) |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5352 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5353 | PRINT("sys_rt_sigprocmask ( %d, %p, %p, %llu )",ARG1,ARG2,ARG3,(ULong)ARG4); |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5354 | PRE_REG_READ4(long, "rt_sigprocmask", |
| 5355 | int, how, vki_sigset_t *, set, vki_sigset_t *, oldset, |
| 5356 | vki_size_t, sigsetsize); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5357 | if (ARG2 != 0) |
| 5358 | PRE_MEM_READ( "rt_sigprocmask(set)", ARG2, sizeof(vki_sigset_t)); |
| 5359 | if (ARG3 != 0) |
| 5360 | PRE_MEM_WRITE( "rt_sigprocmask(oldset)", ARG3, sizeof(vki_sigset_t)); |
nethercote | 7fbe08a | 2004-11-15 19:03:27 +0000 | [diff] [blame] | 5361 | |
| 5362 | // Like the kernel, we fail if the sigsetsize is not exactly what we expect. |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5363 | if (sizeof(vki_sigset_t) != ARG4) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5364 | SET_STATUS_Failure( VKI_EMFILE ); |
sewardj | 004e8ca | 2005-02-28 17:27:04 +0000 | [diff] [blame] | 5365 | else { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5366 | SET_STATUS_from_SysRes( |
| 5367 | VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/, |
njn | 4fbc86c | 2005-05-08 00:45:11 +0000 | [diff] [blame] | 5368 | (vki_sigset_t*) ARG2, |
| 5369 | (vki_sigset_t*) ARG3 ) |
| 5370 | ); |
sewardj | 004e8ca | 2005-02-28 17:27:04 +0000 | [diff] [blame] | 5371 | } |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5372 | |
| 5373 | if (SUCCESS) |
| 5374 | *flags |= SfPollAfter; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5375 | } |
| 5376 | |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5377 | POST(sys_rt_sigprocmask) |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5378 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5379 | vg_assert(SUCCESS); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5380 | if (RES == 0 && ARG3 != 0) |
| 5381 | POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t)); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 5384 | PRE(sys_sigpending) |
| 5385 | { |
| 5386 | PRINT( "sys_sigpending ( %p )", ARG1 ); |
| 5387 | PRE_REG_READ1(long, "sigpending", vki_old_sigset_t *, set); |
| 5388 | PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_old_sigset_t)); |
| 5389 | } |
| 5390 | |
| 5391 | POST(sys_sigpending) |
| 5392 | { |
| 5393 | POST_MEM_WRITE( ARG1, sizeof(vki_old_sigset_t) ) ; |
| 5394 | } |
| 5395 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5396 | PRE(sys_rt_sigpending) |
| 5397 | { |
| 5398 | PRINT( "sys_rt_sigpending ( %p )", ARG1 ); |
| 5399 | PRE_REG_READ2(long, "rt_sigpending", |
| 5400 | vki_sigset_t *, set, vki_size_t, sigsetsize); |
| 5401 | PRE_MEM_WRITE( "rt_sigpending(set)", ARG1, sizeof(vki_sigset_t)); |
| 5402 | } |
| 5403 | POST(sys_rt_sigpending) |
| 5404 | { |
| 5405 | POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ; |
| 5406 | } |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 5407 | |
| 5408 | PRE(sys_mq_open) |
| 5409 | { |
| 5410 | PRINT("sys_mq_open( %p(%s), %d, %lld, %p )", |
| 5411 | ARG1,ARG1,ARG2,(ULong)ARG3,ARG4); |
| 5412 | PRE_REG_READ4(long, "mq_open", |
| 5413 | const char *, name, int, oflag, vki_mode_t, mode, |
| 5414 | struct mq_attr *, attr); |
| 5415 | PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 ); |
| 5416 | if ((ARG2 & VKI_O_CREAT) != 0 && ARG4 != 0) { |
| 5417 | const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4; |
| 5418 | PRE_MEM_READ( "mq_open(attr->mq_maxmsg)", |
| 5419 | (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) ); |
| 5420 | PRE_MEM_READ( "mq_open(attr->mq_msgsize)", |
| 5421 | (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) ); |
| 5422 | } |
| 5423 | } |
| 5424 | |
| 5425 | POST(sys_mq_open) |
| 5426 | { |
| 5427 | vg_assert(SUCCESS); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5428 | if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) { |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 5429 | VG_(close)(RES); |
| 5430 | SET_STATUS_Failure( VKI_EMFILE ); |
| 5431 | } else { |
| 5432 | if (VG_(clo_track_fds)) |
njn | f845f8f | 2005-06-23 02:26:47 +0000 | [diff] [blame] | 5433 | record_fd_open_with_given_name(tid, RES, (Char*)ARG1); |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | PRE(sys_mq_unlink) |
| 5438 | { |
| 5439 | PRINT("sys_mq_unlink ( %p(%s) )", ARG1,ARG1); |
| 5440 | PRE_REG_READ1(long, "mq_unlink", const char *, name); |
| 5441 | PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 ); |
| 5442 | } |
| 5443 | |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5444 | PRE(sys_mq_timedsend) |
| 5445 | { |
| 5446 | *flags |= SfMayBlock; |
| 5447 | PRINT("sys_mq_timedsend ( %d, %p, %llu, %d, %p )", |
| 5448 | ARG1,ARG2,(ULong)ARG3,ARG4,ARG5); |
| 5449 | PRE_REG_READ5(long, "mq_timedsend", |
| 5450 | vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len, |
| 5451 | unsigned int, msg_prio, const struct timespec *, abs_timeout); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5452 | if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) { |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5453 | SET_STATUS_Failure( VKI_EBADF ); |
| 5454 | } else { |
| 5455 | PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 ); |
| 5456 | if (ARG5 != 0) |
| 5457 | PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5, |
| 5458 | sizeof(struct vki_timespec) ); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | PRE(sys_mq_timedreceive) |
| 5463 | { |
| 5464 | *flags |= SfMayBlock; |
| 5465 | PRINT("sys_mq_timedreceive( %d, %p, %llu, %p, %p )", |
| 5466 | ARG1,ARG2,(ULong)ARG3,ARG4,ARG5); |
| 5467 | PRE_REG_READ5(ssize_t, "mq_timedreceive", |
| 5468 | vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len, |
| 5469 | unsigned int *, msg_prio, |
| 5470 | const struct timespec *, abs_timeout); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5471 | if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) { |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5472 | SET_STATUS_Failure( VKI_EBADF ); |
| 5473 | } else { |
| 5474 | PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 ); |
| 5475 | if (ARG4 != 0) |
| 5476 | PRE_MEM_WRITE( "mq_timedreceive(msg_prio)", |
| 5477 | ARG4, sizeof(unsigned int) ); |
| 5478 | if (ARG5 != 0) |
| 5479 | PRE_MEM_READ( "mq_timedreceive(abs_timeout)", |
| 5480 | ARG5, sizeof(struct vki_timespec) ); |
| 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | POST(sys_mq_timedreceive) |
| 5485 | { |
| 5486 | POST_MEM_WRITE( ARG2, ARG3 ); |
| 5487 | if (ARG4 != 0) |
| 5488 | POST_MEM_WRITE( ARG4, sizeof(unsigned int) ); |
| 5489 | } |
| 5490 | |
| 5491 | PRE(sys_mq_notify) |
| 5492 | { |
| 5493 | PRINT("sys_mq_notify( %d, %p )", ARG1,ARG2 ); |
| 5494 | PRE_REG_READ2(long, "mq_notify", |
| 5495 | vki_mqd_t, mqdes, const struct sigevent *, notification); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5496 | if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5497 | SET_STATUS_Failure( VKI_EBADF ); |
| 5498 | else if (ARG2 != 0) |
| 5499 | PRE_MEM_READ( "mq_notify(notification)", |
| 5500 | ARG2, sizeof(struct vki_sigevent) ); |
| 5501 | } |
| 5502 | |
| 5503 | PRE(sys_mq_getsetattr) |
| 5504 | { |
| 5505 | PRINT("sys_mq_getsetattr( %d, %p, %p )", ARG1,ARG2,ARG3 ); |
| 5506 | PRE_REG_READ3(long, "mq_getsetattr", |
| 5507 | vki_mqd_t, mqdes, const struct mq_attr *, mqstat, |
| 5508 | struct mq_attr *, omqstat); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 5509 | if (!ML_(fd_allowed)(ARG1, "mq_getsetattr", tid, False)) { |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 5510 | SET_STATUS_Failure( VKI_EBADF ); |
| 5511 | } else { |
| 5512 | if (ARG2 != 0) { |
| 5513 | const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2; |
| 5514 | PRE_MEM_READ( "mq_getsetattr(mqstat->mq_flags)", |
| 5515 | (Addr)&attr->mq_flags, sizeof(attr->mq_flags) ); |
| 5516 | } |
| 5517 | if (ARG3 != 0) |
| 5518 | PRE_MEM_WRITE( "mq_getsetattr(omqstat)", ARG3, |
| 5519 | sizeof(struct vki_mq_attr) ); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | POST(sys_mq_getsetattr) |
| 5524 | { |
| 5525 | if (ARG3 != 0) |
| 5526 | POST_MEM_WRITE( ARG3, sizeof(struct vki_mq_attr) ); |
| 5527 | } |
| 5528 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5529 | PRE(sys_timer_create) |
| 5530 | { |
| 5531 | PRINT("sys_timer_create( %d, %p, %p )", ARG1,ARG2,ARG3); |
| 5532 | PRE_REG_READ3(long, "timer_create", |
| 5533 | vki_clockid_t, clockid, struct sigevent *, evp, |
| 5534 | vki_timer_t *, timerid); |
| 5535 | if (ARG2 != 0) |
| 5536 | PRE_MEM_READ( "timer_create(evp)", ARG2, sizeof(struct vki_sigevent) ); |
| 5537 | PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) ); |
| 5538 | } |
| 5539 | POST(sys_timer_create) |
| 5540 | { |
| 5541 | POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) ); |
| 5542 | } |
| 5543 | |
| 5544 | PRE(sys_timer_settime) |
| 5545 | { |
| 5546 | PRINT("sys_timer_settime( %lld, %d, %p, %p )", (ULong)ARG1,ARG2,ARG3,ARG4); |
| 5547 | PRE_REG_READ4(long, "timer_settime", |
| 5548 | vki_timer_t, timerid, int, flags, |
| 5549 | const struct itimerspec *, value, |
| 5550 | struct itimerspec *, ovalue); |
| 5551 | PRE_MEM_READ( "timer_settime(value)", ARG3, |
| 5552 | sizeof(struct vki_itimerspec) ); |
| 5553 | if (ARG4 != 0) |
| 5554 | PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4, |
| 5555 | sizeof(struct vki_itimerspec) ); |
| 5556 | } |
| 5557 | POST(sys_timer_settime) |
| 5558 | { |
| 5559 | if (ARG4 != 0) |
| 5560 | POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) ); |
| 5561 | } |
| 5562 | |
| 5563 | PRE(sys_timer_gettime) |
| 5564 | { |
| 5565 | PRINT("sys_timer_gettime( %lld, %p )", (ULong)ARG1,ARG2); |
| 5566 | PRE_REG_READ2(long, "timer_gettime", |
| 5567 | vki_timer_t, timerid, struct itimerspec *, value); |
| 5568 | PRE_MEM_WRITE( "timer_gettime(value)", ARG2, |
| 5569 | sizeof(struct vki_itimerspec)); |
| 5570 | } |
| 5571 | POST(sys_timer_gettime) |
| 5572 | { |
| 5573 | POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) ); |
| 5574 | } |
| 5575 | |
| 5576 | PRE(sys_timer_getoverrun) |
| 5577 | { |
| 5578 | PRINT("sys_timer_getoverrun( %p )", ARG1); |
| 5579 | PRE_REG_READ1(long, "timer_getoverrun", vki_timer_t, timerid); |
| 5580 | } |
| 5581 | |
| 5582 | PRE(sys_timer_delete) |
| 5583 | { |
| 5584 | PRINT("sys_timer_delete( %p )", ARG1); |
| 5585 | PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid); |
| 5586 | } |
| 5587 | |
| 5588 | PRE(sys_clock_settime) |
| 5589 | { |
| 5590 | PRINT("sys_clock_settime( %d, %p )", ARG1,ARG2); |
| 5591 | PRE_REG_READ2(long, "clock_settime", |
| 5592 | vki_clockid_t, clk_id, const struct timespec *, tp); |
| 5593 | PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) ); |
| 5594 | } |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 5595 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 5596 | PRE(sys_clock_gettime) |
thughes | e1a925d | 2004-08-30 19:50:02 +0000 | [diff] [blame] | 5597 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5598 | PRINT("sys_clock_gettime( %d, %p )" , ARG1,ARG2); |
nethercote | 92b2fd5 | 2004-11-16 16:15:41 +0000 | [diff] [blame] | 5599 | PRE_REG_READ2(long, "clock_gettime", |
| 5600 | vki_clockid_t, clk_id, struct timespec *, tp); |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5601 | PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) ); |
thughes | e1a925d | 2004-08-30 19:50:02 +0000 | [diff] [blame] | 5602 | } |
nethercote | 85a456f | 2004-11-16 17:31:56 +0000 | [diff] [blame] | 5603 | POST(sys_clock_gettime) |
thughes | e1a925d | 2004-08-30 19:50:02 +0000 | [diff] [blame] | 5604 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 5605 | POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); |
thughes | e1a925d | 2004-08-30 19:50:02 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5608 | PRE(sys_clock_getres) |
| 5609 | { |
| 5610 | PRINT("sys_clock_getres( %d, %p )" , ARG1,ARG2); |
| 5611 | // Nb: we can't use "RES" as the param name because that's a macro |
| 5612 | // defined above! |
| 5613 | PRE_REG_READ2(long, "clock_getres", |
| 5614 | vki_clockid_t, clk_id, struct timespec *, res); |
| 5615 | PRE_MEM_WRITE( "clock_getres(res)", ARG2, sizeof(struct vki_timespec) ); |
| 5616 | } |
| 5617 | POST(sys_clock_getres) |
| 5618 | { |
| 5619 | POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); |
| 5620 | } |
thughes | e1a925d | 2004-08-30 19:50:02 +0000 | [diff] [blame] | 5621 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 5622 | #undef PRE |
| 5623 | #undef POST |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 5624 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 5625 | /*--------------------------------------------------------------------*/ |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 5626 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 5627 | /*--------------------------------------------------------------------*/ |