njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- File- and socket-related libc stuff. m_libcfile.c ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
| 10 | Copyright (C) 2000-2005 Julian Seward |
| 11 | jseward@acm.org |
| 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 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #include "core.h" |
| 32 | #include "pub_core_libcbase.h" |
| 33 | #include "pub_core_libcassert.h" |
| 34 | #include "pub_core_libcfile.h" |
| 35 | #include "pub_core_options.h" |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 36 | #include "vki_unistd.h" |
| 37 | |
| 38 | /* --------------------------------------------------------------------- |
| 39 | File stuff |
| 40 | ------------------------------------------------------------------ */ |
| 41 | |
njn | 63004dc | 2005-06-10 22:39:04 +0000 | [diff] [blame^] | 42 | /* Application-visible file descriptor limits */ |
| 43 | Int VG_(fd_soft_limit) = -1; |
| 44 | Int VG_(fd_hard_limit) = -1; |
| 45 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 46 | static inline Bool fd_exists(Int fd) |
| 47 | { |
| 48 | struct vki_stat st; |
| 49 | |
| 50 | return VG_(fstat)(fd, &st) == 0; |
| 51 | } |
| 52 | |
| 53 | /* Move an fd into the Valgrind-safe range */ |
| 54 | Int VG_(safe_fd)(Int oldfd) |
| 55 | { |
| 56 | Int newfd; |
| 57 | |
| 58 | vg_assert(VG_(fd_hard_limit) != -1); |
| 59 | |
| 60 | newfd = VG_(fcntl)(oldfd, VKI_F_DUPFD, VG_(fd_hard_limit)); |
| 61 | if (newfd != -1) |
| 62 | VG_(close)(oldfd); |
| 63 | |
| 64 | VG_(fcntl)(newfd, VKI_F_SETFD, VKI_FD_CLOEXEC); |
| 65 | |
| 66 | vg_assert(newfd >= VG_(fd_hard_limit)); |
| 67 | return newfd; |
| 68 | } |
| 69 | |
| 70 | /* Returns -1 on failure. */ |
| 71 | Int VG_(open) ( const Char* pathname, Int flags, Int mode ) |
| 72 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 73 | SysRes res = VG_(do_syscall3)(__NR_open, (UWord)pathname, flags, mode); |
| 74 | return res.isError ? -1 : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void VG_(close) ( Int fd ) |
| 78 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 79 | (void)VG_(do_syscall1)(__NR_close, fd); |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | Int VG_(read) ( Int fd, void* buf, Int count) |
| 83 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 84 | SysRes res = VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count); |
| 85 | return res.isError ? -1 : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | Int VG_(write) ( Int fd, const void* buf, Int count) |
| 89 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 90 | SysRes res = VG_(do_syscall3)(__NR_write, fd, (UWord)buf, count); |
| 91 | return res.isError ? -1 : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | Int VG_(pipe) ( Int fd[2] ) |
| 95 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 96 | SysRes res = VG_(do_syscall1)(__NR_pipe, (UWord)fd); |
| 97 | return res.isError ? -1 : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | OffT VG_(lseek) ( Int fd, OffT offset, Int whence) |
| 101 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 102 | SysRes res = VG_(do_syscall3)(__NR_lseek, fd, offset, whence); |
| 103 | return res.isError ? (-1) : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | Int VG_(stat) ( Char* file_name, struct vki_stat* buf ) |
| 107 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 108 | SysRes res = VG_(do_syscall2)(__NR_stat, (UWord)file_name, (UWord)buf); |
| 109 | return res.isError ? (-1) : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | Int VG_(fstat) ( Int fd, struct vki_stat* buf ) |
| 113 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 114 | SysRes res = VG_(do_syscall2)(__NR_fstat, fd, (UWord)buf); |
| 115 | return res.isError ? (-1) : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | Int VG_(dup2) ( Int oldfd, Int newfd ) |
| 119 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 120 | SysRes res = VG_(do_syscall2)(__NR_dup2, oldfd, newfd); |
| 121 | return res.isError ? (-1) : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | Int VG_(rename) ( Char* old_name, Char* new_name ) |
| 125 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 126 | SysRes res = VG_(do_syscall2)(__NR_rename, (UWord)old_name, (UWord)new_name); |
| 127 | return res.isError ? (-1) : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | Int VG_(unlink) ( Char* file_name ) |
| 131 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 132 | SysRes res = VG_(do_syscall1)(__NR_unlink, (UWord)file_name); |
| 133 | return res.isError ? (-1) : 0; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* Nb: we do not allow the Linux extension which malloc()s memory for the |
| 137 | buffer if buf==NULL, because we don't want Linux calling malloc() */ |
| 138 | Char* VG_(getcwd) ( Char* buf, SizeT size ) |
| 139 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 140 | SysRes res; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 141 | vg_assert(buf != NULL); |
| 142 | res = VG_(do_syscall2)(__NR_getcwd, (UWord)buf, size); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 143 | return res.isError ? ((Char*)NULL) : (Char*)res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* Alternative version that does allocate the memory. Easier to use. */ |
| 147 | Bool VG_(getcwd_alloc) ( Char** out ) |
| 148 | { |
| 149 | SizeT size = 4; |
| 150 | |
| 151 | *out = NULL; |
| 152 | while (True) { |
| 153 | *out = VG_(malloc)(size); |
| 154 | if (NULL == VG_(getcwd)(*out, size)) { |
| 155 | VG_(free)(*out); |
| 156 | if (size > 65535) |
| 157 | return False; |
| 158 | size *= 2; |
| 159 | } else { |
| 160 | return True; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | Int VG_(readlink) (Char* path, Char* buf, UInt bufsiz) |
| 166 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 167 | SysRes res; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 168 | /* res = readlink( path, buf, bufsiz ); */ |
| 169 | res = VG_(do_syscall3)(__NR_readlink, (UWord)path, (UWord)buf, bufsiz); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 170 | return res.isError ? -1 : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | Int VG_(getdents) (UInt fd, struct vki_dirent *dirp, UInt count) |
| 174 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 175 | SysRes res; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 176 | /* res = getdents( fd, dirp, count ); */ |
| 177 | res = VG_(do_syscall3)(__NR_getdents, fd, (UWord)dirp, count); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 178 | return res.isError ? -1 : res.val; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* --------------------------------------------------------------------- |
| 182 | Socket-related stuff. This is very Linux-kernel specific. |
| 183 | ------------------------------------------------------------------ */ |
| 184 | |
| 185 | static |
| 186 | Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port ); |
| 187 | |
| 188 | static |
| 189 | Int my_socket ( Int domain, Int type, Int protocol ); |
| 190 | |
| 191 | static |
| 192 | Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr, |
| 193 | Int addrlen ); |
| 194 | |
| 195 | static |
| 196 | UInt my_htonl ( UInt x ) |
| 197 | { |
| 198 | return |
| 199 | (((x >> 24) & 0xFF) << 0) | (((x >> 16) & 0xFF) << 8) |
| 200 | | (((x >> 8) & 0xFF) << 16) | (((x >> 0) & 0xFF) << 24); |
| 201 | } |
| 202 | |
| 203 | static |
| 204 | UShort my_htons ( UShort x ) |
| 205 | { |
| 206 | return |
| 207 | (((x >> 8) & 0xFF) << 0) | (((x >> 0) & 0xFF) << 8); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /* The main function. |
| 212 | |
| 213 | Supplied string contains either an ip address "192.168.0.1" or |
| 214 | an ip address and port pair, "192.168.0.1:1500". Parse these, |
| 215 | and return: |
| 216 | -1 if there is a parse error |
| 217 | -2 if no parse error, but specified host:port cannot be opened |
| 218 | the relevant file (socket) descriptor, otherwise. |
| 219 | is used. |
| 220 | */ |
| 221 | Int VG_(connect_via_socket)( UChar* str ) |
| 222 | { |
| 223 | Int sd, res; |
| 224 | struct vki_sockaddr_in servAddr; |
| 225 | UInt ip = 0; |
| 226 | UShort port = VG_CLO_DEFAULT_LOGPORT; |
| 227 | Bool ok = parse_inet_addr_and_port(str, &ip, &port); |
| 228 | if (!ok) |
| 229 | return -1; |
| 230 | |
| 231 | //if (0) |
| 232 | // VG_(printf)("ip = %d.%d.%d.%d, port %d\n", |
| 233 | // (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, |
| 234 | // (ip >> 8) & 0xFF, ip & 0xFF, |
| 235 | // (UInt)port ); |
| 236 | |
| 237 | servAddr.sin_family = VKI_AF_INET; |
| 238 | servAddr.sin_addr.s_addr = my_htonl(ip); |
| 239 | servAddr.sin_port = my_htons(port); |
| 240 | |
| 241 | /* create socket */ |
| 242 | sd = my_socket(VKI_AF_INET, VKI_SOCK_STREAM, 0 /* IPPROTO_IP ? */); |
| 243 | if (sd < 0) { |
| 244 | /* this shouldn't happen ... nevertheless */ |
| 245 | return -2; |
| 246 | } |
| 247 | |
| 248 | /* connect to server */ |
| 249 | res = my_connect(sd, (struct vki_sockaddr_in *) &servAddr, |
| 250 | sizeof(servAddr)); |
| 251 | if (res < 0) { |
| 252 | /* connection failed */ |
| 253 | return -2; |
| 254 | } |
| 255 | |
| 256 | return sd; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | /* Let d = one or more digits. Accept either: |
| 261 | d.d.d.d or d.d.d.d:d |
| 262 | */ |
| 263 | Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port ) |
| 264 | { |
| 265 | # define GET_CH ((*str) ? (*str++) : 0) |
| 266 | UInt ipa, i, j, c, any; |
| 267 | ipa = 0; |
| 268 | for (i = 0; i < 4; i++) { |
| 269 | j = 0; |
| 270 | any = 0; |
| 271 | while (1) { |
| 272 | c = GET_CH; |
| 273 | if (c < '0' || c > '9') break; |
| 274 | j = 10 * j + (int)(c - '0'); |
| 275 | any = 1; |
| 276 | } |
| 277 | if (any == 0 || j > 255) goto syntaxerr; |
| 278 | ipa = (ipa << 8) + j; |
| 279 | if (i <= 2 && c != '.') goto syntaxerr; |
| 280 | } |
| 281 | if (c == 0 || c == ':') |
| 282 | *ip_addr = ipa; |
| 283 | if (c == 0) goto ok; |
| 284 | if (c != ':') goto syntaxerr; |
| 285 | j = 0; |
| 286 | any = 0; |
| 287 | while (1) { |
| 288 | c = GET_CH; |
| 289 | if (c < '0' || c > '9') break; |
| 290 | j = j * 10 + (int)(c - '0'); |
| 291 | any = 1; |
| 292 | if (j > 65535) goto syntaxerr; |
| 293 | } |
| 294 | if (any == 0 || c != 0) goto syntaxerr; |
| 295 | if (j < 1024) goto syntaxerr; |
| 296 | *port = (UShort)j; |
| 297 | ok: |
| 298 | return 1; |
| 299 | syntaxerr: |
| 300 | return 0; |
| 301 | # undef GET_CH |
| 302 | } |
| 303 | |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 304 | static |
| 305 | Int my_socket ( Int domain, Int type, Int protocol ) |
| 306 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 307 | # if defined(VGP_x86_linux) |
| 308 | SysRes res; |
| 309 | UWord args[3]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 310 | args[0] = domain; |
| 311 | args[1] = type; |
| 312 | args[2] = protocol; |
| 313 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SOCKET, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 314 | return res.isError ? -1 : res.val; |
| 315 | # else |
| 316 | // AMD64/Linux doesn't define __NR_socketcall... see comment above |
| 317 | // VG_(sigpending)() for more details. |
| 318 | I_die_here; |
| 319 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static |
| 323 | Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr, |
| 324 | Int addrlen ) |
| 325 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 326 | # if defined(VGP_x86_linux) |
| 327 | SysRes res; |
| 328 | UWord args[3]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 329 | args[0] = sockfd; |
| 330 | args[1] = (UWord)serv_addr; |
| 331 | args[2] = addrlen; |
| 332 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_CONNECT, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 333 | return res.isError ? -1 : res.val; |
| 334 | # else |
| 335 | // AMD64/Linux doesn't define __NR_socketcall... see comment above |
| 336 | // VG_(sigpending)() for more details. |
| 337 | I_die_here; |
| 338 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | Int VG_(write_socket)( Int sd, void *msg, Int count ) |
| 342 | { |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 343 | /* This is actually send(). */ |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 344 | /* Requests not to send SIGPIPE on errors on stream oriented |
| 345 | sockets when the other end breaks the connection. The EPIPE |
| 346 | error is still returned. */ |
| 347 | Int flags = VKI_MSG_NOSIGNAL; |
| 348 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 349 | # if defined(VGP_x86_linux) |
| 350 | SysRes res; |
| 351 | UWord args[4]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 352 | args[0] = sd; |
| 353 | args[1] = (UWord)msg; |
| 354 | args[2] = count; |
| 355 | args[3] = flags; |
| 356 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SEND, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 357 | return res.isError ? -1 : res.val; |
| 358 | # else |
| 359 | // AMD64/Linux doesn't define __NR_socketcall... see comment above |
| 360 | // VG_(sigpending)() for more details. |
| 361 | I_die_here; |
| 362 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen) |
| 366 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 367 | SysRes res; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 368 | |
| 369 | # if defined(VGP_x86_linux) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 370 | UWord args[3]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 371 | args[0] = sd; |
| 372 | args[1] = (UWord)name; |
| 373 | args[2] = (UWord)namelen; |
| 374 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKNAME, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 375 | return res.isError ? -1 : res.val; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 376 | |
| 377 | # elif defined(VGP_amd64_linux) |
| 378 | res = VG_(do_syscall3)( __NR_getsockname, |
| 379 | (UWord)sd, (UWord)name, (UWord)namelen ); |
| 380 | return res.isError ? -1 : res.val; |
| 381 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 382 | # else |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 383 | I_die_here; |
| 384 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen) |
| 388 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 389 | SysRes res; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 390 | |
| 391 | # if defined(VGP_x86_linux) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 392 | UWord args[3]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 393 | args[0] = sd; |
| 394 | args[1] = (UWord)name; |
| 395 | args[2] = (UWord)namelen; |
| 396 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETPEERNAME, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 397 | return res.isError ? -1 : res.val; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 398 | |
| 399 | # elif defined(VGP_amd64_linux) |
| 400 | res = VG_(do_syscall3)( __NR_getpeername, |
| 401 | (UWord)sd, (UWord)name, (UWord)namelen ); |
| 402 | return res.isError ? -1 : res.val; |
| 403 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 404 | # else |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 405 | I_die_here; |
| 406 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval, |
| 410 | Int *optlen) |
| 411 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 412 | SysRes res; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 413 | |
| 414 | # if defined(VGP_x86_linux) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 415 | UWord args[5]; |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 416 | args[0] = sd; |
| 417 | args[1] = level; |
| 418 | args[2] = optname; |
| 419 | args[3] = (UWord)optval; |
| 420 | args[4] = (UWord)optlen; |
| 421 | res = VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKOPT, (UWord)&args); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 422 | return res.isError ? -1 : res.val; |
sewardj | a5c9e4a | 2005-06-09 13:21:58 +0000 | [diff] [blame] | 423 | |
| 424 | # elif defined(VGP_amd64_linux) |
| 425 | res = VG_(do_syscall5)( __NR_getsockopt, |
| 426 | (UWord)sd, (UWord)level, (UWord)optname, |
| 427 | (UWord)optval, (UWord)optlen ); |
| 428 | return res.isError ? -1 : res.val; |
| 429 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 430 | # else |
| 431 | I_die_here; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 432 | # endif |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| 436 | |
| 437 | /*--------------------------------------------------------------------*/ |
| 438 | /*--- end ---*/ |
| 439 | /*--------------------------------------------------------------------*/ |
| 440 | |