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