src/os/windows/vm/os_windows.cpp

changeset 2365
54f5dd2aa1d9
parent 2364
2d4762ec74af
parent 2327
cb2d0a362639
child 2369
aa6e219afbf1
child 2391
1e637defdda6
     1.1 --- a/src/os/windows/vm/os_windows.cpp	Sat Dec 11 13:20:56 2010 -0500
     1.2 +++ b/src/os/windows/vm/os_windows.cpp	Sat Dec 11 13:46:36 2010 -0500
     1.3 @@ -47,7 +47,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 @@ -1045,8 +1044,6 @@
    1.12      return 0;
    1.13  }
    1.14  
    1.15 -const char* os::dll_file_extension() { return ".dll"; }
    1.16 -
    1.17  const char* os::get_temp_directory() {
    1.18    const char *prop = Arguments::get_property("java.io.tmpdir");
    1.19    if (prop != 0) return prop;
    1.20 @@ -1068,7 +1065,6 @@
    1.21  
    1.22  void os::dll_build_name(char *buffer, size_t buflen,
    1.23                          const char* pname, const char* fname) {
    1.24 -  // Copied from libhpi
    1.25    const size_t pnamelen = pname ? strlen(pname) : 0;
    1.26    const char c = (pnamelen > 0) ? pname[pnamelen-1] : 0;
    1.27  
    1.28 @@ -1378,10 +1374,6 @@
    1.29    return false;
    1.30  }
    1.31  
    1.32 -void* os::dll_lookup(void* handle, const char* name) {
    1.33 -  return GetProcAddress((HMODULE)handle, name);
    1.34 -}
    1.35 -
    1.36  // save the start and end address of jvm.dll into param[0] and param[1]
    1.37  static int _locate_jvm_dll(int pid, char* mod_fname, address base_addr,
    1.38                      unsigned size, void * param) {
    1.39 @@ -1716,7 +1708,37 @@
    1.40      return;
    1.41    }
    1.42  
    1.43 +  buf[0] = '\0';
    1.44 +  if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) {
    1.45 +     // Support for the gamma launcher. Check for an
    1.46 +     // ALT_JAVA_HOME or JAVA_HOME environment variable
    1.47 +     // and fix up the path so it looks like
    1.48 +     // libjvm.so is installed there (append a fake suffix
    1.49 +     // hotspot/libjvm.so).
    1.50 +     char* java_home_var = ::getenv("ALT_JAVA_HOME");
    1.51 +     if (java_home_var == NULL) {
    1.52 +        java_home_var = ::getenv("JAVA_HOME");
    1.53 +     }
    1.54 +     if (java_home_var != NULL && java_home_var[0] != 0) {
    1.55 +
    1.56 +        strncpy(buf, java_home_var, buflen);
    1.57 +
    1.58 +        // determine if this is a legacy image or modules image
    1.59 +        // modules image doesn't have "jre" subdirectory
    1.60 +        size_t len = strlen(buf);
    1.61 +        char* jrebin_p = buf + len;
    1.62 +        jio_snprintf(jrebin_p, buflen-len, "\\jre\\bin\\");
    1.63 +        if (0 != _access(buf, 0)) {
    1.64 +          jio_snprintf(jrebin_p, buflen-len, "\\bin\\");
    1.65 +        }
    1.66 +        len = strlen(buf);
    1.67 +        jio_snprintf(buf + len, buflen-len, "hotspot\\jvm.dll");
    1.68 +     }
    1.69 +  }
    1.70 +
    1.71 +  if(buf[0] == '\0') {
    1.72    GetModuleFileName(vm_lib_handle, buf, buflen);
    1.73 +  }
    1.74    strcpy(saved_jvm_path, buf);
    1.75  }
    1.76  
    1.77 @@ -1734,6 +1756,44 @@
    1.78  #endif
    1.79  }
    1.80  
    1.81 +// This method is a copy of JDK's sysGetLastErrorString
    1.82 +// from src/windows/hpi/src/system_md.c
    1.83 +
    1.84 +size_t os::lasterror(char *buf, size_t len) {
    1.85 +  long errval;
    1.86 +
    1.87 +  if ((errval = GetLastError()) != 0) {
    1.88 +      /* DOS error */
    1.89 +    int n = (int)FormatMessage(
    1.90 +          FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
    1.91 +          NULL,
    1.92 +          errval,
    1.93 +          0,
    1.94 +          buf,
    1.95 +          (DWORD)len,
    1.96 +          NULL);
    1.97 +    if (n > 3) {
    1.98 +      /* Drop final '.', CR, LF */
    1.99 +      if (buf[n - 1] == '\n') n--;
   1.100 +      if (buf[n - 1] == '\r') n--;
   1.101 +      if (buf[n - 1] == '.') n--;
   1.102 +      buf[n] = '\0';
   1.103 +    }
   1.104 +    return n;
   1.105 +  }
   1.106 +
   1.107 +  if (errno != 0) {
   1.108 +    /* C runtime error that has no corresponding DOS error code */
   1.109 +    const char *s = strerror(errno);
   1.110 +    size_t n = strlen(s);
   1.111 +    if (n >= len) n = len - 1;
   1.112 +    strncpy(buf, s, n);
   1.113 +    buf[n] = '\0';
   1.114 +    return n;
   1.115 +  }
   1.116 +  return 0;
   1.117 +}
   1.118 +
   1.119  // sun.misc.Signal
   1.120  // NOTE that this is a workaround for an apparent kernel bug where if
   1.121  // a signal handler for SIGBREAK is installed then that signal handler
   1.122 @@ -2941,10 +3001,6 @@
   1.123    assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back
   1.124  }
   1.125  
   1.126 -size_t os::read(int fd, void *buf, unsigned int nBytes) {
   1.127 -  return ::read(fd, buf, nBytes);
   1.128 -}
   1.129 -
   1.130  class HighResolutionInterval {
   1.131    // The default timer resolution seems to be 10 milliseconds.
   1.132    // (Where is this written down?)
   1.133 @@ -3423,10 +3479,6 @@
   1.134  #endif
   1.135    }
   1.136  
   1.137 -  // Initialize HPI.
   1.138 -  jint hpi_result = hpi::initialize();
   1.139 -  if (hpi_result != JNI_OK) { return hpi_result; }
   1.140 -
   1.141    // If stack_commit_size is 0, windows will reserve the default size,
   1.142    // but only commit a small portion of it.
   1.143    size_t stack_commit_size = round_to(ThreadStackSize*K, os::vm_page_size());
   1.144 @@ -3531,7 +3583,7 @@
   1.145      errno = ENAMETOOLONG;
   1.146      return -1;
   1.147    }
   1.148 -  hpi::native_path(strcpy(pathbuf, path));
   1.149 +  os::native_path(strcpy(pathbuf, path));
   1.150    int ret = ::stat(pathbuf, sbuf);
   1.151    if (sbuf != NULL && UseUTCFileTimestamp) {
   1.152      // Fix for 6539723.  st_mtime returned from stat() is dependent on
   1.153 @@ -3675,6 +3727,20 @@
   1.154    return DontYieldALot;
   1.155  }
   1.156  
   1.157 +// This method is a slightly reworked copy of JDK's sysOpen
   1.158 +// from src/windows/hpi/src/sys_api_md.c
   1.159 +
   1.160 +int os::open(const char *path, int oflag, int mode) {
   1.161 +  char pathbuf[MAX_PATH];
   1.162 +
   1.163 +  if (strlen(path) > MAX_PATH - 1) {
   1.164 +    errno = ENAMETOOLONG;
   1.165 +          return -1;
   1.166 +  }
   1.167 +  os::native_path(strcpy(pathbuf, path));
   1.168 +  return ::open(pathbuf, oflag | O_BINARY | O_NOINHERIT, mode);
   1.169 +}
   1.170 +
   1.171  // Is a (classpath) directory empty?
   1.172  bool os::dir_is_empty(const char* path) {
   1.173    WIN32_FIND_DATA fd;
   1.174 @@ -3706,6 +3772,297 @@
   1.175  }
   1.176  
   1.177  
   1.178 +jlong os::lseek(int fd, jlong offset, int whence) {
   1.179 +  return (jlong) ::_lseeki64(fd, offset, whence);
   1.180 +}
   1.181 +
   1.182 +// This method is a slightly reworked copy of JDK's sysNativePath
   1.183 +// from src/windows/hpi/src/path_md.c
   1.184 +
   1.185 +/* Convert a pathname to native format.  On win32, this involves forcing all
   1.186 +   separators to be '\\' rather than '/' (both are legal inputs, but Win95
   1.187 +   sometimes rejects '/') and removing redundant separators.  The input path is
   1.188 +   assumed to have been converted into the character encoding used by the local
   1.189 +   system.  Because this might be a double-byte encoding, care is taken to
   1.190 +   treat double-byte lead characters correctly.
   1.191 +
   1.192 +   This procedure modifies the given path in place, as the result is never
   1.193 +   longer than the original.  There is no error return; this operation always
   1.194 +   succeeds. */
   1.195 +char * os::native_path(char *path) {
   1.196 +  char *src = path, *dst = path, *end = path;
   1.197 +  char *colon = NULL;           /* If a drive specifier is found, this will
   1.198 +                                        point to the colon following the drive
   1.199 +                                        letter */
   1.200 +
   1.201 +  /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */
   1.202 +  assert(((!::IsDBCSLeadByte('/'))
   1.203 +    && (!::IsDBCSLeadByte('\\'))
   1.204 +    && (!::IsDBCSLeadByte(':'))),
   1.205 +    "Illegal lead byte");
   1.206 +
   1.207 +  /* Check for leading separators */
   1.208 +#define isfilesep(c) ((c) == '/' || (c) == '\\')
   1.209 +  while (isfilesep(*src)) {
   1.210 +    src++;
   1.211 +  }
   1.212 +
   1.213 +  if (::isalpha(*src) && !::IsDBCSLeadByte(*src) && src[1] == ':') {
   1.214 +    /* Remove leading separators if followed by drive specifier.  This
   1.215 +      hack is necessary to support file URLs containing drive
   1.216 +      specifiers (e.g., "file://c:/path").  As a side effect,
   1.217 +      "/c:/path" can be used as an alternative to "c:/path". */
   1.218 +    *dst++ = *src++;
   1.219 +    colon = dst;
   1.220 +    *dst++ = ':';
   1.221 +    src++;
   1.222 +  } else {
   1.223 +    src = path;
   1.224 +    if (isfilesep(src[0]) && isfilesep(src[1])) {
   1.225 +      /* UNC pathname: Retain first separator; leave src pointed at
   1.226 +         second separator so that further separators will be collapsed
   1.227 +         into the second separator.  The result will be a pathname
   1.228 +         beginning with "\\\\" followed (most likely) by a host name. */
   1.229 +      src = dst = path + 1;
   1.230 +      path[0] = '\\';     /* Force first separator to '\\' */
   1.231 +    }
   1.232 +  }
   1.233 +
   1.234 +  end = dst;
   1.235 +
   1.236 +  /* Remove redundant separators from remainder of path, forcing all
   1.237 +      separators to be '\\' rather than '/'. Also, single byte space
   1.238 +      characters are removed from the end of the path because those
   1.239 +      are not legal ending characters on this operating system.
   1.240 +  */
   1.241 +  while (*src != '\0') {
   1.242 +    if (isfilesep(*src)) {
   1.243 +      *dst++ = '\\'; src++;
   1.244 +      while (isfilesep(*src)) src++;
   1.245 +      if (*src == '\0') {
   1.246 +        /* Check for trailing separator */
   1.247 +        end = dst;
   1.248 +        if (colon == dst - 2) break;                      /* "z:\\" */
   1.249 +        if (dst == path + 1) break;                       /* "\\" */
   1.250 +        if (dst == path + 2 && isfilesep(path[0])) {
   1.251 +          /* "\\\\" is not collapsed to "\\" because "\\\\" marks the
   1.252 +            beginning of a UNC pathname.  Even though it is not, by
   1.253 +            itself, a valid UNC pathname, we leave it as is in order
   1.254 +            to be consistent with the path canonicalizer as well
   1.255 +            as the win32 APIs, which treat this case as an invalid
   1.256 +            UNC pathname rather than as an alias for the root
   1.257 +            directory of the current drive. */
   1.258 +          break;
   1.259 +        }
   1.260 +        end = --dst;  /* Path does not denote a root directory, so
   1.261 +                                    remove trailing separator */
   1.262 +        break;
   1.263 +      }
   1.264 +      end = dst;
   1.265 +    } else {
   1.266 +      if (::IsDBCSLeadByte(*src)) { /* Copy a double-byte character */
   1.267 +        *dst++ = *src++;
   1.268 +        if (*src) *dst++ = *src++;
   1.269 +        end = dst;
   1.270 +      } else {         /* Copy a single-byte character */
   1.271 +        char c = *src++;
   1.272 +        *dst++ = c;
   1.273 +        /* Space is not a legal ending character */
   1.274 +        if (c != ' ') end = dst;
   1.275 +      }
   1.276 +    }
   1.277 +  }
   1.278 +
   1.279 +  *end = '\0';
   1.280 +
   1.281 +  /* For "z:", add "." to work around a bug in the C runtime library */
   1.282 +  if (colon == dst - 1) {
   1.283 +          path[2] = '.';
   1.284 +          path[3] = '\0';
   1.285 +  }
   1.286 +
   1.287 +  #ifdef DEBUG
   1.288 +    jio_fprintf(stderr, "sysNativePath: %s\n", path);
   1.289 +  #endif DEBUG
   1.290 +  return path;
   1.291 +}
   1.292 +
   1.293 +// This code is a copy of JDK's sysSetLength
   1.294 +// from src/windows/hpi/src/sys_api_md.c
   1.295 +
   1.296 +int os::ftruncate(int fd, jlong length) {
   1.297 +  HANDLE h = (HANDLE)::_get_osfhandle(fd);
   1.298 +  long high = (long)(length >> 32);
   1.299 +  DWORD ret;
   1.300 +
   1.301 +  if (h == (HANDLE)(-1)) {
   1.302 +    return -1;
   1.303 +  }
   1.304 +
   1.305 +  ret = ::SetFilePointer(h, (long)(length), &high, FILE_BEGIN);
   1.306 +  if ((ret == 0xFFFFFFFF) && (::GetLastError() != NO_ERROR)) {
   1.307 +      return -1;
   1.308 +  }
   1.309 +
   1.310 +  if (::SetEndOfFile(h) == FALSE) {
   1.311 +    return -1;
   1.312 +  }
   1.313 +
   1.314 +  return 0;
   1.315 +}
   1.316 +
   1.317 +
   1.318 +// This code is a copy of JDK's sysSync
   1.319 +// from src/windows/hpi/src/sys_api_md.c
   1.320 +// except for the legacy workaround for a bug in Win 98
   1.321 +
   1.322 +int os::fsync(int fd) {
   1.323 +  HANDLE handle = (HANDLE)::_get_osfhandle(fd);
   1.324 +
   1.325 +  if ( (!::FlushFileBuffers(handle)) &&
   1.326 +         (GetLastError() != ERROR_ACCESS_DENIED) ) {
   1.327 +    /* from winerror.h */
   1.328 +    return -1;
   1.329 +  }
   1.330 +  return 0;
   1.331 +}
   1.332 +
   1.333 +static int nonSeekAvailable(int, long *);
   1.334 +static int stdinAvailable(int, long *);
   1.335 +
   1.336 +#define S_ISCHR(mode)   (((mode) & _S_IFCHR) == _S_IFCHR)
   1.337 +#define S_ISFIFO(mode)  (((mode) & _S_IFIFO) == _S_IFIFO)
   1.338 +
   1.339 +// This code is a copy of JDK's sysAvailable
   1.340 +// from src/windows/hpi/src/sys_api_md.c
   1.341 +
   1.342 +int os::available(int fd, jlong *bytes) {
   1.343 +  jlong cur, end;
   1.344 +  struct _stati64 stbuf64;
   1.345 +
   1.346 +  if (::_fstati64(fd, &stbuf64) >= 0) {
   1.347 +    int mode = stbuf64.st_mode;
   1.348 +    if (S_ISCHR(mode) || S_ISFIFO(mode)) {
   1.349 +      int ret;
   1.350 +      long lpbytes;
   1.351 +      if (fd == 0) {
   1.352 +        ret = stdinAvailable(fd, &lpbytes);
   1.353 +      } else {
   1.354 +        ret = nonSeekAvailable(fd, &lpbytes);
   1.355 +      }
   1.356 +      (*bytes) = (jlong)(lpbytes);
   1.357 +      return ret;
   1.358 +    }
   1.359 +    if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) {
   1.360 +      return FALSE;
   1.361 +    } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) {
   1.362 +      return FALSE;
   1.363 +    } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) {
   1.364 +      return FALSE;
   1.365 +    }
   1.366 +    *bytes = end - cur;
   1.367 +    return TRUE;
   1.368 +  } else {
   1.369 +    return FALSE;
   1.370 +  }
   1.371 +}
   1.372 +
   1.373 +// This code is a copy of JDK's nonSeekAvailable
   1.374 +// from src/windows/hpi/src/sys_api_md.c
   1.375 +
   1.376 +static int nonSeekAvailable(int fd, long *pbytes) {
   1.377 +  /* This is used for available on non-seekable devices
   1.378 +    * (like both named and anonymous pipes, such as pipes
   1.379 +    *  connected to an exec'd process).
   1.380 +    * Standard Input is a special case.
   1.381 +    *
   1.382 +    */
   1.383 +  HANDLE han;
   1.384 +
   1.385 +  if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) {
   1.386 +    return FALSE;
   1.387 +  }
   1.388 +
   1.389 +  if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) {
   1.390 +        /* PeekNamedPipe fails when at EOF.  In that case we
   1.391 +         * simply make *pbytes = 0 which is consistent with the
   1.392 +         * behavior we get on Solaris when an fd is at EOF.
   1.393 +         * The only alternative is to raise an Exception,
   1.394 +         * which isn't really warranted.
   1.395 +         */
   1.396 +    if (::GetLastError() != ERROR_BROKEN_PIPE) {
   1.397 +      return FALSE;
   1.398 +    }
   1.399 +    *pbytes = 0;
   1.400 +  }
   1.401 +  return TRUE;
   1.402 +}
   1.403 +
   1.404 +#define MAX_INPUT_EVENTS 2000
   1.405 +
   1.406 +// This code is a copy of JDK's stdinAvailable
   1.407 +// from src/windows/hpi/src/sys_api_md.c
   1.408 +
   1.409 +static int stdinAvailable(int fd, long *pbytes) {
   1.410 +  HANDLE han;
   1.411 +  DWORD numEventsRead = 0;      /* Number of events read from buffer */
   1.412 +  DWORD numEvents = 0;  /* Number of events in buffer */
   1.413 +  DWORD i = 0;          /* Loop index */
   1.414 +  DWORD curLength = 0;  /* Position marker */
   1.415 +  DWORD actualLength = 0;       /* Number of bytes readable */
   1.416 +  BOOL error = FALSE;         /* Error holder */
   1.417 +  INPUT_RECORD *lpBuffer;     /* Pointer to records of input events */
   1.418 +
   1.419 +  if ((han = ::GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
   1.420 +        return FALSE;
   1.421 +  }
   1.422 +
   1.423 +  /* Construct an array of input records in the console buffer */
   1.424 +  error = ::GetNumberOfConsoleInputEvents(han, &numEvents);
   1.425 +  if (error == 0) {
   1.426 +    return nonSeekAvailable(fd, pbytes);
   1.427 +  }
   1.428 +
   1.429 +  /* lpBuffer must fit into 64K or else PeekConsoleInput fails */
   1.430 +  if (numEvents > MAX_INPUT_EVENTS) {
   1.431 +    numEvents = MAX_INPUT_EVENTS;
   1.432 +  }
   1.433 +
   1.434 +  lpBuffer = (INPUT_RECORD *)os::malloc(numEvents * sizeof(INPUT_RECORD));
   1.435 +  if (lpBuffer == NULL) {
   1.436 +    return FALSE;
   1.437 +  }
   1.438 +
   1.439 +  error = ::PeekConsoleInput(han, lpBuffer, numEvents, &numEventsRead);
   1.440 +  if (error == 0) {
   1.441 +    os::free(lpBuffer);
   1.442 +    return FALSE;
   1.443 +  }
   1.444 +
   1.445 +  /* Examine input records for the number of bytes available */
   1.446 +  for(i=0; i<numEvents; i++) {
   1.447 +    if (lpBuffer[i].EventType == KEY_EVENT) {
   1.448 +
   1.449 +      KEY_EVENT_RECORD *keyRecord = (KEY_EVENT_RECORD *)
   1.450 +                                      &(lpBuffer[i].Event);
   1.451 +      if (keyRecord->bKeyDown == TRUE) {
   1.452 +        CHAR *keyPressed = (CHAR *) &(keyRecord->uChar);
   1.453 +        curLength++;
   1.454 +        if (*keyPressed == '\r') {
   1.455 +          actualLength = curLength;
   1.456 +        }
   1.457 +      }
   1.458 +    }
   1.459 +  }
   1.460 +
   1.461 +  if(lpBuffer != NULL) {
   1.462 +    os::free(lpBuffer);
   1.463 +  }
   1.464 +
   1.465 +  *pbytes = (long) actualLength;
   1.466 +  return TRUE;
   1.467 +}
   1.468 +
   1.469  // Map a block of memory.
   1.470  char* os::map_memory(int fd, const char* file_name, size_t file_offset,
   1.471                       char *addr, size_t bytes, bool read_only,
   1.472 @@ -3871,7 +4228,7 @@
   1.473    int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
   1.474    if (fd != -1) {
   1.475      struct stat buf;
   1.476 -    close(fd);
   1.477 +    ::close(fd);
   1.478      while (::stat(filename, &buf) == 0) {
   1.479        Sleep(100);
   1.480      }
   1.481 @@ -4232,3 +4589,164 @@
   1.482  // We don't build a headless jre for Windows
   1.483  bool os::is_headless_jre() { return false; }
   1.484  
   1.485 +// OS_SocketInterface
   1.486 +// Not used on Windows
   1.487 +
   1.488 +// OS_SocketInterface
   1.489 +typedef struct hostent * (PASCAL FAR *ws2_ifn_ptr_t)(...);
   1.490 +ws2_ifn_ptr_t *get_host_by_name_fn = NULL;
   1.491 +
   1.492 +typedef CRITICAL_SECTION mutex_t;
   1.493 +#define mutexInit(m)    InitializeCriticalSection(m)
   1.494 +#define mutexDestroy(m) DeleteCriticalSection(m)
   1.495 +#define mutexLock(m)    EnterCriticalSection(m)
   1.496 +#define mutexUnlock(m)  LeaveCriticalSection(m)
   1.497 +
   1.498 +static bool sockfnptrs_initialized = FALSE;
   1.499 +static mutex_t sockFnTableMutex;
   1.500 +
   1.501 +/* is Winsock2 loaded? better to be explicit than to rely on sockfnptrs */
   1.502 +static bool winsock2Available = FALSE;
   1.503 +
   1.504 +
   1.505 +static void initSockFnTable() {
   1.506 +  int (PASCAL FAR* WSAStartupPtr)(WORD, LPWSADATA);
   1.507 +  WSADATA wsadata;
   1.508 +
   1.509 +  ::mutexInit(&sockFnTableMutex);
   1.510 +  ::mutexLock(&sockFnTableMutex);
   1.511 +
   1.512 +  if (sockfnptrs_initialized == FALSE) {
   1.513 +        HMODULE hWinsock;
   1.514 +
   1.515 +          /* try to load Winsock2, and if that fails, load Winsock */
   1.516 +    hWinsock = ::LoadLibrary("ws2_32.dll");
   1.517 +
   1.518 +    if (hWinsock == NULL) {
   1.519 +      jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n",
   1.520 +      ::GetLastError());
   1.521 +      return;
   1.522 +    }
   1.523 +
   1.524 +    /* If we loaded a DLL, then we might as well initialize it.  */
   1.525 +    WSAStartupPtr = (int (PASCAL FAR *)(WORD, LPWSADATA))
   1.526 +    ::GetProcAddress(hWinsock, "WSAStartup");
   1.527 +
   1.528 +    if (WSAStartupPtr(MAKEWORD(1,1), &wsadata) != 0) {
   1.529 +        jio_fprintf(stderr, "Could not initialize Winsock\n");
   1.530 +    }
   1.531 +
   1.532 +    get_host_by_name_fn
   1.533 +        = (ws2_ifn_ptr_t*) GetProcAddress(hWinsock, "gethostbyname");
   1.534 +  }
   1.535 +
   1.536 +  assert(get_host_by_name_fn != NULL,
   1.537 +    "gethostbyname function not found");
   1.538 +  sockfnptrs_initialized = TRUE;
   1.539 +  ::mutexUnlock(&sockFnTableMutex);
   1.540 +}
   1.541 +
   1.542 +struct hostent*  os::get_host_by_name(char* name) {
   1.543 +  if (!sockfnptrs_initialized) {
   1.544 +    initSockFnTable();
   1.545 +  }
   1.546 +
   1.547 +  assert(sockfnptrs_initialized == TRUE && get_host_by_name_fn != NULL,
   1.548 +    "sockfnptrs is not initialized or pointer to gethostbyname function is NULL");
   1.549 +  return (*get_host_by_name_fn)(name);
   1.550 +}
   1.551 +
   1.552 +
   1.553 +int os::socket_close(int fd) {
   1.554 +  ShouldNotReachHere();
   1.555 +  return 0;
   1.556 +}
   1.557 +
   1.558 +int os::socket_available(int fd, jint *pbytes) {
   1.559 +  ShouldNotReachHere();
   1.560 +  return 0;
   1.561 +}
   1.562 +
   1.563 +int os::socket(int domain, int type, int protocol) {
   1.564 +  ShouldNotReachHere();
   1.565 +  return 0;
   1.566 +}
   1.567 +
   1.568 +int os::listen(int fd, int count) {
   1.569 +  ShouldNotReachHere();
   1.570 +  return 0;
   1.571 +}
   1.572 +
   1.573 +int os::connect(int fd, struct sockaddr *him, int len) {
   1.574 +  ShouldNotReachHere();
   1.575 +  return 0;
   1.576 +}
   1.577 +
   1.578 +int os::accept(int fd, struct sockaddr *him, int *len) {
   1.579 +  ShouldNotReachHere();
   1.580 +  return 0;
   1.581 +}
   1.582 +
   1.583 +int os::sendto(int fd, char *buf, int len, int flags,
   1.584 +                        struct sockaddr *to, int tolen) {
   1.585 +  ShouldNotReachHere();
   1.586 +  return 0;
   1.587 +}
   1.588 +
   1.589 +int os::recvfrom(int fd, char *buf, int nBytes, int flags,
   1.590 +                         sockaddr *from, int *fromlen) {
   1.591 +  ShouldNotReachHere();
   1.592 +  return 0;
   1.593 +}
   1.594 +
   1.595 +int os::recv(int fd, char *buf, int nBytes, int flags) {
   1.596 +  ShouldNotReachHere();
   1.597 +  return 0;
   1.598 +}
   1.599 +
   1.600 +int os::send(int fd, char *buf, int nBytes, int flags) {
   1.601 +  ShouldNotReachHere();
   1.602 +  return 0;
   1.603 +}
   1.604 +
   1.605 +int os::raw_send(int fd, char *buf, int nBytes, int flags) {
   1.606 +  ShouldNotReachHere();
   1.607 +  return 0;
   1.608 +}
   1.609 +
   1.610 +int os::timeout(int fd, long timeout) {
   1.611 +  ShouldNotReachHere();
   1.612 +  return 0;
   1.613 +}
   1.614 +
   1.615 +int os::get_host_name(char* name, int namelen) {
   1.616 +  ShouldNotReachHere();
   1.617 +  return 0;
   1.618 +}
   1.619 +
   1.620 +int os::socket_shutdown(int fd, int howto) {
   1.621 +  ShouldNotReachHere();
   1.622 +  return 0;
   1.623 +}
   1.624 +
   1.625 +int os::bind(int fd, struct sockaddr *him, int len) {
   1.626 +  ShouldNotReachHere();
   1.627 +  return 0;
   1.628 +}
   1.629 +
   1.630 +int os::get_sock_name(int fd, struct sockaddr *him, int *len) {
   1.631 +  ShouldNotReachHere();
   1.632 +  return 0;
   1.633 +}
   1.634 +
   1.635 +int os::get_sock_opt(int fd, int level, int optname,
   1.636 +                             char *optval, int* optlen) {
   1.637 +  ShouldNotReachHere();
   1.638 +  return 0;
   1.639 +}
   1.640 +
   1.641 +int os::set_sock_opt(int fd, int level, int optname,
   1.642 +                             const char *optval, int optlen) {
   1.643 +  ShouldNotReachHere();
   1.644 +  return 0;
   1.645 +}

mercurial