src/os/solaris/vm/os_solaris.cpp

changeset 2322
828eafbd85cc
parent 2314
f95d63e2154a
child 2365
54f5dd2aa1d9
child 2403
c04052fd6ae1
     1.1 --- a/src/os/solaris/vm/os_solaris.cpp	Tue Nov 23 13:22:55 2010 -0800
     1.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Wed Dec 01 18:26:32 2010 -0500
     1.3 @@ -42,7 +42,6 @@
     1.4  #include "runtime/arguments.hpp"
     1.5  #include "runtime/extendedPC.hpp"
     1.6  #include "runtime/globals.hpp"
     1.7 -#include "runtime/hpi.hpp"
     1.8  #include "runtime/interfaceSupport.hpp"
     1.9  #include "runtime/java.hpp"
    1.10  #include "runtime/javaCalls.hpp"
    1.11 @@ -115,6 +114,7 @@
    1.12  # include <sys/iapriocntl.h>
    1.13  # include <sys/loadavg.h>
    1.14  # include <string.h>
    1.15 +# include <stdio.h>
    1.16  
    1.17  # define _STRUCTURED_PROC 1  //  this gets us the new structured proc interfaces of 5.6 & later
    1.18  # include <sys/procfs.h>     //  see comment in <sys/procfs.h>
    1.19 @@ -219,6 +219,9 @@
    1.20  // System parameters used internally
    1.21  static clock_t clock_tics_per_sec = 100;
    1.22  
    1.23 +// Track if we have called enable_extended_FILE_stdio (on Solaris 10u4+)
    1.24 +static bool enabled_extended_FILE_stdio = false;
    1.25 +
    1.26  // For diagnostics to print a message once. see run_periodic_checks
    1.27  static bool check_addr0_done = false;
    1.28  static sigset_t check_signal_done;
    1.29 @@ -386,7 +389,7 @@
    1.30  // The saved state is used to restore the thread to
    1.31  // its former state whether or not an interrupt is received.
    1.32  // Used by classloader os::read
    1.33 -// hpi calls skip this layer and stay in _thread_in_native
    1.34 +// os::restartable_read calls skip this layer and stay in _thread_in_native
    1.35  
    1.36  void os::Solaris::setup_interruptible(JavaThread* thread) {
    1.37  
    1.38 @@ -1750,13 +1753,13 @@
    1.39  bool os::supports_vtime() { return true; }
    1.40  
    1.41  bool os::enable_vtime() {
    1.42 -  int fd = open("/proc/self/ctl", O_WRONLY);
    1.43 +  int fd = ::open("/proc/self/ctl", O_WRONLY);
    1.44    if (fd == -1)
    1.45      return false;
    1.46  
    1.47    long cmd[] = { PCSET, PR_MSACCT };
    1.48 -  int res = write(fd, cmd, sizeof(long) * 2);
    1.49 -  close(fd);
    1.50 +  int res = ::write(fd, cmd, sizeof(long) * 2);
    1.51 +  ::close(fd);
    1.52    if (res != sizeof(long) * 2)
    1.53      return false;
    1.54  
    1.55 @@ -1764,13 +1767,13 @@
    1.56  }
    1.57  
    1.58  bool os::vtime_enabled() {
    1.59 -  int fd = open("/proc/self/status", O_RDONLY);
    1.60 +  int fd = ::open("/proc/self/status", O_RDONLY);
    1.61    if (fd == -1)
    1.62      return false;
    1.63  
    1.64    pstatus_t status;
    1.65 -  int res = read(fd, (void*) &status, sizeof(pstatus_t));
    1.66 -  close(fd);
    1.67 +  int res = os::read(fd, (void*) &status, sizeof(pstatus_t));
    1.68 +  ::close(fd);
    1.69    if (res != sizeof(pstatus_t))
    1.70      return false;
    1.71  
    1.72 @@ -1886,7 +1889,6 @@
    1.73  
    1.74  void os::dll_build_name(char* buffer, size_t buflen,
    1.75                          const char* pname, const char* fname) {
    1.76 -  // Copied from libhpi
    1.77    const size_t pnamelen = pname ? strlen(pname) : 0;
    1.78  
    1.79    // Quietly truncate on buffer overflow.  Should be an error.
    1.80 @@ -2182,20 +2184,29 @@
    1.81    return dlsym(handle, name);
    1.82  }
    1.83  
    1.84 -
    1.85 -bool _print_ascii_file(const char* filename, outputStream* st) {
    1.86 -  int fd = open(filename, O_RDONLY);
    1.87 +int os::stat(const char *path, struct stat *sbuf) {
    1.88 +  char pathbuf[MAX_PATH];
    1.89 +  if (strlen(path) > MAX_PATH - 1) {
    1.90 +    errno = ENAMETOOLONG;
    1.91 +    return -1;
    1.92 +  }
    1.93 +  os::native_path(strcpy(pathbuf, path));
    1.94 +  return ::stat(pathbuf, sbuf);
    1.95 +}
    1.96 +
    1.97 +static bool _print_ascii_file(const char* filename, outputStream* st) {
    1.98 +  int fd = ::open(filename, O_RDONLY);
    1.99    if (fd == -1) {
   1.100       return false;
   1.101    }
   1.102  
   1.103    char buf[32];
   1.104    int bytes;
   1.105 -  while ((bytes = read(fd, buf, sizeof(buf))) > 0) {
   1.106 +  while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
   1.107      st->print_raw(buf, bytes);
   1.108    }
   1.109  
   1.110 -  close(fd);
   1.111 +  ::close(fd);
   1.112  
   1.113    return true;
   1.114  }
   1.115 @@ -2258,10 +2269,10 @@
   1.116  
   1.117  static bool check_addr0(outputStream* st) {
   1.118    jboolean status = false;
   1.119 -  int fd = open("/proc/self/map",O_RDONLY);
   1.120 +  int fd = ::open("/proc/self/map",O_RDONLY);
   1.121    if (fd >= 0) {
   1.122      prmap_t p;
   1.123 -    while(read(fd, &p, sizeof(p)) > 0) {
   1.124 +    while(::read(fd, &p, sizeof(p)) > 0) {
   1.125        if (p.pr_vaddr == 0x0) {
   1.126          st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname);
   1.127          st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname);
   1.128 @@ -2272,7 +2283,7 @@
   1.129          st->cr();
   1.130          status = true;
   1.131        }
   1.132 -      close(fd);
   1.133 +      ::close(fd);
   1.134      }
   1.135    }
   1.136    return status;
   1.137 @@ -2520,8 +2531,6 @@
   1.138            // Use current module name "libjvm[_g].so" instead of
   1.139            // "libjvm"debug_only("_g")".so" since for fastdebug version
   1.140            // we should have "libjvm.so" but debug_only("_g") adds "_g"!
   1.141 -          // It is used when we are choosing the HPI library's name
   1.142 -          // "libhpi[_g].so" in hpi::initialize_get_interface().
   1.143            len = strlen(buf);
   1.144            snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p);
   1.145          } else {
   1.146 @@ -2545,6 +2554,23 @@
   1.147    // no suffix required
   1.148  }
   1.149  
   1.150 +// This method is a copy of JDK's sysGetLastErrorString
   1.151 +// from src/solaris/hpi/src/system_md.c
   1.152 +
   1.153 +size_t os::lasterror(char *buf, size_t len) {
   1.154 +
   1.155 +  if (errno == 0)  return 0;
   1.156 +
   1.157 +  const char *s = ::strerror(errno);
   1.158 +  size_t n = ::strlen(s);
   1.159 +  if (n >= len) {
   1.160 +    n = len - 1;
   1.161 +  }
   1.162 +  ::strncpy(buf, s, n);
   1.163 +  buf[n] = '\0';
   1.164 +  return n;
   1.165 +}
   1.166 +
   1.167  
   1.168  // sun.misc.Signal
   1.169  
   1.170 @@ -3454,6 +3480,10 @@
   1.171    INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
   1.172  }
   1.173  
   1.174 +size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
   1.175 +  INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted);
   1.176 +}
   1.177 +
   1.178  int os::sleep(Thread* thread, jlong millis, bool interruptible) {
   1.179    assert(thread == Thread::current(),  "thread consistency check");
   1.180  
   1.181 @@ -4623,16 +4653,16 @@
   1.182  #define ADR(x)  ((uintptr_t)(x))
   1.183  #define LWPINDEX(ary,ix)   ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1))))
   1.184  
   1.185 -  lwpFile = open("/proc/self/lstatus", O_RDONLY, 0);
   1.186 +  lwpFile = ::open("/proc/self/lstatus", O_RDONLY, 0);
   1.187    if (lwpFile < 0) {
   1.188        if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n");
   1.189        return false;
   1.190    }
   1.191    lwpSize = 16*1024;
   1.192    for (;;) {
   1.193 -    lseek (lwpFile, 0, SEEK_SET);
   1.194 +    ::lseek64 (lwpFile, 0, SEEK_SET);
   1.195      lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize);
   1.196 -    if (read(lwpFile, lwpArray, lwpSize) < 0) {
   1.197 +    if (::read(lwpFile, lwpArray, lwpSize) < 0) {
   1.198        if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n");
   1.199        break;
   1.200      }
   1.201 @@ -4653,7 +4683,7 @@
   1.202    }
   1.203  
   1.204    FREE_C_HEAP_ARRAY(char, lwpArray);
   1.205 -  close (lwpFile);
   1.206 +  ::close (lwpFile);
   1.207    if (ThreadPriorityVerbose) {
   1.208      if (isT2) tty->print_cr("We are running with a T2 libthread\n");
   1.209      else tty->print_cr("We are not running with a T2 libthread\n");
   1.210 @@ -4849,7 +4879,7 @@
   1.211    // if we need them.
   1.212    Solaris::misc_sym_init();
   1.213  
   1.214 -  int fd = open("/dev/zero", O_RDWR);
   1.215 +  int fd = ::open("/dev/zero", O_RDWR);
   1.216    if (fd < 0) {
   1.217      fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno)));
   1.218    } else {
   1.219 @@ -5019,13 +5049,6 @@
   1.220      }
   1.221    }
   1.222  
   1.223 -  // Initialize HPI.
   1.224 -  jint hpi_result = hpi::initialize();
   1.225 -  if (hpi_result != JNI_OK) {
   1.226 -    tty->print_cr("There was an error trying to initialize the HPI library.");
   1.227 -    return hpi_result;
   1.228 -  }
   1.229 -
   1.230    // Calculate theoretical max. size of Threads to guard gainst
   1.231    // artifical out-of-memory situations, where all available address-
   1.232    // space has been reserved by thread stacks. Default stack size is 1Mb.
   1.233 @@ -5085,17 +5108,6 @@
   1.234  
   1.235  // OS interface.
   1.236  
   1.237 -int os::stat(const char *path, struct stat *sbuf) {
   1.238 -  char pathbuf[MAX_PATH];
   1.239 -  if (strlen(path) > MAX_PATH - 1) {
   1.240 -    errno = ENAMETOOLONG;
   1.241 -    return -1;
   1.242 -  }
   1.243 -  hpi::native_path(strcpy(pathbuf, path));
   1.244 -  return ::stat(pathbuf, sbuf);
   1.245 -}
   1.246 -
   1.247 -
   1.248  bool os::check_heap(bool force) { return true; }
   1.249  
   1.250  typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr);
   1.251 @@ -5140,6 +5152,125 @@
   1.252    return result;
   1.253  }
   1.254  
   1.255 +// This code originates from JDK's sysOpen and open64_w
   1.256 +// from src/solaris/hpi/src/system_md.c
   1.257 +
   1.258 +#ifndef O_DELETE
   1.259 +#define O_DELETE 0x10000
   1.260 +#endif
   1.261 +
   1.262 +// Open a file. Unlink the file immediately after open returns
   1.263 +// if the specified oflag has the O_DELETE flag set.
   1.264 +// O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
   1.265 +
   1.266 +int os::open(const char *path, int oflag, int mode) {
   1.267 +  if (strlen(path) > MAX_PATH - 1) {
   1.268 +    errno = ENAMETOOLONG;
   1.269 +    return -1;
   1.270 +  }
   1.271 +  int fd;
   1.272 +  int o_delete = (oflag & O_DELETE);
   1.273 +  oflag = oflag & ~O_DELETE;
   1.274 +
   1.275 +  fd = ::open(path, oflag, mode);
   1.276 +  if (fd == -1) return -1;
   1.277 +
   1.278 +  //If the open succeeded, the file might still be a directory
   1.279 +  {
   1.280 +    struct stat64 buf64;
   1.281 +    int ret = ::fstat64(fd, &buf64);
   1.282 +    int st_mode = buf64.st_mode;
   1.283 +
   1.284 +    if (ret != -1) {
   1.285 +      if ((st_mode & S_IFMT) == S_IFDIR) {
   1.286 +        errno = EISDIR;
   1.287 +        ::close(fd);
   1.288 +        return -1;
   1.289 +      }
   1.290 +    } else {
   1.291 +      ::close(fd);
   1.292 +      return -1;
   1.293 +    }
   1.294 +  }
   1.295 +    /*
   1.296 +     * 32-bit Solaris systems suffer from:
   1.297 +     *
   1.298 +     * - an historical default soft limit of 256 per-process file
   1.299 +     *   descriptors that is too low for many Java programs.
   1.300 +     *
   1.301 +     * - a design flaw where file descriptors created using stdio
   1.302 +     *   fopen must be less than 256, _even_ when the first limit above
   1.303 +     *   has been raised.  This can cause calls to fopen (but not calls to
   1.304 +     *   open, for example) to fail mysteriously, perhaps in 3rd party
   1.305 +     *   native code (although the JDK itself uses fopen).  One can hardly
   1.306 +     *   criticize them for using this most standard of all functions.
   1.307 +     *
   1.308 +     * We attempt to make everything work anyways by:
   1.309 +     *
   1.310 +     * - raising the soft limit on per-process file descriptors beyond
   1.311 +     *   256
   1.312 +     *
   1.313 +     * - As of Solaris 10u4, we can request that Solaris raise the 256
   1.314 +     *   stdio fopen limit by calling function enable_extended_FILE_stdio.
   1.315 +     *   This is done in init_2 and recorded in enabled_extended_FILE_stdio
   1.316 +     *
   1.317 +     * - If we are stuck on an old (pre 10u4) Solaris system, we can
   1.318 +     *   workaround the bug by remapping non-stdio file descriptors below
   1.319 +     *   256 to ones beyond 256, which is done below.
   1.320 +     *
   1.321 +     * See:
   1.322 +     * 1085341: 32-bit stdio routines should support file descriptors >255
   1.323 +     * 6533291: Work around 32-bit Solaris stdio limit of 256 open files
   1.324 +     * 6431278: Netbeans crash on 32 bit Solaris: need to call
   1.325 +     *          enable_extended_FILE_stdio() in VM initialisation
   1.326 +     * Giri Mandalika's blog
   1.327 +     * http://technopark02.blogspot.com/2005_05_01_archive.html
   1.328 +     */
   1.329 +#ifndef  _LP64
   1.330 +     if ((!enabled_extended_FILE_stdio) && fd < 256) {
   1.331 +         int newfd = ::fcntl(fd, F_DUPFD, 256);
   1.332 +         if (newfd != -1) {
   1.333 +             ::close(fd);
   1.334 +             fd = newfd;
   1.335 +         }
   1.336 +     }
   1.337 +#endif // 32-bit Solaris
   1.338 +    /*
   1.339 +     * All file descriptors that are opened in the JVM and not
   1.340 +     * specifically destined for a subprocess should have the
   1.341 +     * close-on-exec flag set.  If we don't set it, then careless 3rd
   1.342 +     * party native code might fork and exec without closing all
   1.343 +     * appropriate file descriptors (e.g. as we do in closeDescriptors in
   1.344 +     * UNIXProcess.c), and this in turn might:
   1.345 +     *
   1.346 +     * - cause end-of-file to fail to be detected on some file
   1.347 +     *   descriptors, resulting in mysterious hangs, or
   1.348 +     *
   1.349 +     * - might cause an fopen in the subprocess to fail on a system
   1.350 +     *   suffering from bug 1085341.
   1.351 +     *
   1.352 +     * (Yes, the default setting of the close-on-exec flag is a Unix
   1.353 +     * design flaw)
   1.354 +     *
   1.355 +     * See:
   1.356 +     * 1085341: 32-bit stdio routines should support file descriptors >255
   1.357 +     * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
   1.358 +     * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
   1.359 +     */
   1.360 +#ifdef FD_CLOEXEC
   1.361 +    {
   1.362 +        int flags = ::fcntl(fd, F_GETFD);
   1.363 +        if (flags != -1)
   1.364 +            ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
   1.365 +    }
   1.366 +#endif
   1.367 +
   1.368 +  if (o_delete != 0) {
   1.369 +    ::unlink(path);
   1.370 +  }
   1.371 +  return fd;
   1.372 +}
   1.373 +
   1.374  // create binary file, rewriting existing file if required
   1.375  int os::create_binary_file(const char* path, bool rewrite_existing) {
   1.376    int oflags = O_WRONLY | O_CREAT;
   1.377 @@ -5159,6 +5290,55 @@
   1.378    return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
   1.379  }
   1.380  
   1.381 +jlong os::lseek(int fd, jlong offset, int whence) {
   1.382 +  return (jlong) ::lseek64(fd, offset, whence);
   1.383 +}
   1.384 +
   1.385 +char * os::native_path(char *path) {
   1.386 +  return path;
   1.387 +}
   1.388 +
   1.389 +int os::ftruncate(int fd, jlong length) {
   1.390 +  return ::ftruncate64(fd, length);
   1.391 +}
   1.392 +
   1.393 +int os::fsync(int fd)  {
   1.394 +  RESTARTABLE_RETURN_INT(::fsync(fd));
   1.395 +}
   1.396 +
   1.397 +int os::available(int fd, jlong *bytes) {
   1.398 +  jlong cur, end;
   1.399 +  int mode;
   1.400 +  struct stat64 buf64;
   1.401 +
   1.402 +  if (::fstat64(fd, &buf64) >= 0) {
   1.403 +    mode = buf64.st_mode;
   1.404 +    if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
   1.405 +      /*
   1.406 +      * XXX: is the following call interruptible? If so, this might
   1.407 +      * need to go through the INTERRUPT_IO() wrapper as for other
   1.408 +      * blocking, interruptible calls in this file.
   1.409 +      */
   1.410 +      int n,ioctl_return;
   1.411 +
   1.412 +      INTERRUPTIBLE(::ioctl(fd, FIONREAD, &n),ioctl_return,os::Solaris::clear_interrupted);
   1.413 +      if (ioctl_return>= 0) {
   1.414 +          *bytes = n;
   1.415 +        return 1;
   1.416 +      }
   1.417 +    }
   1.418 +  }
   1.419 +  if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
   1.420 +    return 0;
   1.421 +  } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
   1.422 +    return 0;
   1.423 +  } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
   1.424 +    return 0;
   1.425 +  }
   1.426 +  *bytes = end - cur;
   1.427 +  return 1;
   1.428 +}
   1.429 +
   1.430  // Map a block of memory.
   1.431  char* os::map_memory(int fd, const char* file_name, size_t file_offset,
   1.432                       char *addr, size_t bytes, bool read_only,
   1.433 @@ -5217,7 +5397,7 @@
   1.434    int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
   1.435    if (fd != -1) {
   1.436      struct stat buf;
   1.437 -    close(fd);
   1.438 +    ::close(fd);
   1.439      while (::stat(filename, &buf) == 0) {
   1.440        (void)::poll(NULL, 0, 100);
   1.441      }
   1.442 @@ -5414,16 +5594,16 @@
   1.443    sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage",
   1.444                       getpid(),
   1.445                       thread->osthread()->lwp_id());
   1.446 -  fd = open(proc_name, O_RDONLY);
   1.447 +  fd = ::open(proc_name, O_RDONLY);
   1.448    if ( fd == -1 ) return -1;
   1.449  
   1.450    do {
   1.451 -    count = pread(fd,
   1.452 +    count = ::pread(fd,
   1.453                    (void *)&prusage.pr_utime,
   1.454                    thr_time_size,
   1.455                    thr_time_off);
   1.456    } while (count < 0 && errno == EINTR);
   1.457 -  close(fd);
   1.458 +  ::close(fd);
   1.459    if ( count < 0 ) return -1;
   1.460  
   1.461    if (user_sys_cpu_time) {
   1.462 @@ -6095,4 +6275,127 @@
   1.463      return true;
   1.464  }
   1.465  
   1.466 -
   1.467 +size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   1.468 +  INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted);
   1.469 +}
   1.470 +
   1.471 +int os::close(int fd) {
   1.472 +  RESTARTABLE_RETURN_INT(::close(fd));
   1.473 +}
   1.474 +
   1.475 +int os::socket_close(int fd) {
   1.476 +  RESTARTABLE_RETURN_INT(::close(fd));
   1.477 +}
   1.478 +
   1.479 +int os::recv(int fd, char *buf, int nBytes, int flags) {
   1.480 +  INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted);
   1.481 +}
   1.482 +
   1.483 +
   1.484 +int os::send(int fd, char *buf, int nBytes, int flags) {
   1.485 +  INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted);
   1.486 +}
   1.487 +
   1.488 +int os::raw_send(int fd, char *buf, int nBytes, int flags) {
   1.489 +  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
   1.490 +}
   1.491 +
   1.492 +// As both poll and select can be interrupted by signals, we have to be
   1.493 +// prepared to restart the system call after updating the timeout, unless
   1.494 +// a poll() is done with timeout == -1, in which case we repeat with this
   1.495 +// "wait forever" value.
   1.496 +
   1.497 +int os::timeout(int fd, long timeout) {
   1.498 +  int res;
   1.499 +  struct timeval t;
   1.500 +  julong prevtime, newtime;
   1.501 +  static const char* aNull = 0;
   1.502 +  struct pollfd pfd;
   1.503 +  pfd.fd = fd;
   1.504 +  pfd.events = POLLIN;
   1.505 +
   1.506 +  gettimeofday(&t, &aNull);
   1.507 +  prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
   1.508 +
   1.509 +  for(;;) {
   1.510 +    INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted);
   1.511 +    if(res == OS_ERR && errno == EINTR) {
   1.512 +        if(timeout != -1) {
   1.513 +          gettimeofday(&t, &aNull);
   1.514 +          newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
   1.515 +          timeout -= newtime - prevtime;
   1.516 +          if(timeout <= 0)
   1.517 +            return OS_OK;
   1.518 +          prevtime = newtime;
   1.519 +        }
   1.520 +    } else return res;
   1.521 +  }
   1.522 +}
   1.523 +
   1.524 +int os::connect(int fd, struct sockaddr *him, int len) {
   1.525 +  int _result;
   1.526 +  INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result,
   1.527 +                          os::Solaris::clear_interrupted);
   1.528 +
   1.529 +  // Depending on when thread interruption is reset, _result could be
   1.530 +  // one of two values when errno == EINTR
   1.531 +
   1.532 +  if (((_result == OS_INTRPT) || (_result == OS_ERR))
   1.533 +                                        && (errno == EINTR)) {
   1.534 +     /* restarting a connect() changes its errno semantics */
   1.535 +     INTERRUPTIBLE(::connect(fd, him, len), _result,
   1.536 +                     os::Solaris::clear_interrupted);
   1.537 +     /* undo these changes */
   1.538 +     if (_result == OS_ERR) {
   1.539 +       if (errno == EALREADY) {
   1.540 +         errno = EINPROGRESS; /* fall through */
   1.541 +       } else if (errno == EISCONN) {
   1.542 +         errno = 0;
   1.543 +         return OS_OK;
   1.544 +       }
   1.545 +     }
   1.546 +   }
   1.547 +   return _result;
   1.548 + }
   1.549 +
   1.550 +int os::accept(int fd, struct sockaddr *him, int *len) {
   1.551 +  if (fd < 0)
   1.552 +   return OS_ERR;
   1.553 +  INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him,\
   1.554 +    (socklen_t*) len), os::Solaris::clear_interrupted);
   1.555 + }
   1.556 +
   1.557 +int os::recvfrom(int fd, char *buf, int nBytes, int flags,
   1.558 +                             sockaddr *from, int *fromlen) {
   1.559 +   //%%note jvm_r11
   1.560 +  INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes,\
   1.561 +    flags, from, fromlen), os::Solaris::clear_interrupted);
   1.562 +}
   1.563 +
   1.564 +int os::sendto(int fd, char *buf, int len, int flags,
   1.565 +                           struct sockaddr *to, int tolen) {
   1.566 +  //%%note jvm_r11
   1.567 +  INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, flags,\
   1.568 +    to, tolen), os::Solaris::clear_interrupted);
   1.569 +}
   1.570 +
   1.571 +int os::socket_available(int fd, jint *pbytes) {
   1.572 +   if (fd < 0)
   1.573 +     return OS_OK;
   1.574 +
   1.575 +   int ret;
   1.576 +
   1.577 +   RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
   1.578 +
   1.579 +   //%% note ioctl can return 0 when successful, JVM_SocketAvailable
   1.580 +   // is expected to return 0 on failure and 1 on success to the jdk.
   1.581 +
   1.582 +   return (ret == OS_ERR) ? 0 : 1;
   1.583 +}
   1.584 +
   1.585 +
   1.586 +int os::bind(int fd, struct sockaddr *him, int len) {
   1.587 +   INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),\
   1.588 +     os::Solaris::clear_interrupted);
   1.589 +}
   1.590 +

mercurial