< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




  53 #include "runtime/javaCalls.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/objectMonitor.hpp"
  56 #include "runtime/orderAccess.inline.hpp"
  57 #include "runtime/osThread.hpp"
  58 #include "runtime/perfMemory.hpp"
  59 #include "runtime/sharedRuntime.hpp"
  60 #include "runtime/statSampler.hpp"
  61 #include "runtime/stubRoutines.hpp"
  62 #include "runtime/thread.inline.hpp"
  63 #include "runtime/threadCritical.hpp"
  64 #include "runtime/timer.hpp"
  65 #include "runtime/vm_version.hpp"
  66 #include "services/attachListener.hpp"
  67 #include "services/memTracker.hpp"
  68 #include "services/runtimeService.hpp"
  69 #include "utilities/decoder.hpp"
  70 #include "utilities/defaultStream.hpp"
  71 #include "utilities/events.hpp"
  72 #include "utilities/growableArray.hpp"

  73 #include "utilities/vmError.hpp"
  74 
  75 #ifdef _DEBUG
  76 #include <crtdbg.h>
  77 #endif
  78 
  79 
  80 #include <windows.h>
  81 #include <sys/types.h>
  82 #include <sys/stat.h>
  83 #include <sys/timeb.h>
  84 #include <objidl.h>
  85 #include <shlobj.h>
  86 
  87 #include <malloc.h>
  88 #include <signal.h>
  89 #include <direct.h>
  90 #include <errno.h>
  91 #include <fcntl.h>
  92 #include <io.h>


1876 
1877   if (errno != 0) {
1878     // C runtime error that has no corresponding DOS error code
1879     const char* s = strerror(errno);
1880     size_t n = strlen(s);
1881     if (n >= len) n = len - 1;
1882     strncpy(buf, s, n);
1883     buf[n] = '\0';
1884     return n;
1885   }
1886 
1887   return 0;
1888 }
1889 
1890 int os::get_last_error() {
1891   DWORD error = GetLastError();
1892   if (error == 0) {
1893     error = errno;
1894   }
1895   return (int)error;



























1896 }
1897 
1898 // sun.misc.Signal
1899 // NOTE that this is a workaround for an apparent kernel bug where if
1900 // a signal handler for SIGBREAK is installed then that signal handler
1901 // takes priority over the console control handler for CTRL_CLOSE_EVENT.
1902 // See bug 4416763.
1903 static void (*sigbreakHandler)(int) = NULL;
1904 
1905 static void UserHandler(int sig, void *siginfo, void *context) {
1906   os::signal_notify(sig);
1907   // We need to reinstate the signal handler each time...
1908   os::signal(sig, (void*)UserHandler);
1909 }
1910 
1911 void* os::user_handler() {
1912   return (void*) UserHandler;
1913 }
1914 
1915 void* os::signal(int signal_number, void* handler) {




  53 #include "runtime/javaCalls.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/objectMonitor.hpp"
  56 #include "runtime/orderAccess.inline.hpp"
  57 #include "runtime/osThread.hpp"
  58 #include "runtime/perfMemory.hpp"
  59 #include "runtime/sharedRuntime.hpp"
  60 #include "runtime/statSampler.hpp"
  61 #include "runtime/stubRoutines.hpp"
  62 #include "runtime/thread.inline.hpp"
  63 #include "runtime/threadCritical.hpp"
  64 #include "runtime/timer.hpp"
  65 #include "runtime/vm_version.hpp"
  66 #include "services/attachListener.hpp"
  67 #include "services/memTracker.hpp"
  68 #include "services/runtimeService.hpp"
  69 #include "utilities/decoder.hpp"
  70 #include "utilities/defaultStream.hpp"
  71 #include "utilities/events.hpp"
  72 #include "utilities/growableArray.hpp"
  73 #include "utilities/semaphore.hpp"
  74 #include "utilities/vmError.hpp"
  75 
  76 #ifdef _DEBUG
  77 #include <crtdbg.h>
  78 #endif
  79 
  80 
  81 #include <windows.h>
  82 #include <sys/types.h>
  83 #include <sys/stat.h>
  84 #include <sys/timeb.h>
  85 #include <objidl.h>
  86 #include <shlobj.h>
  87 
  88 #include <malloc.h>
  89 #include <signal.h>
  90 #include <direct.h>
  91 #include <errno.h>
  92 #include <fcntl.h>
  93 #include <io.h>


1877 
1878   if (errno != 0) {
1879     // C runtime error that has no corresponding DOS error code
1880     const char* s = strerror(errno);
1881     size_t n = strlen(s);
1882     if (n >= len) n = len - 1;
1883     strncpy(buf, s, n);
1884     buf[n] = '\0';
1885     return n;
1886   }
1887 
1888   return 0;
1889 }
1890 
1891 int os::get_last_error() {
1892   DWORD error = GetLastError();
1893   if (error == 0) {
1894     error = errno;
1895   }
1896   return (int)error;
1897 }
1898 
1899 Semaphore::Semaphore(uint value) {
1900   _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL);
1901 
1902   assert(_semaphore != NULL, err_msg("CreateSemaphore failed: %ld", GetLastError()));
1903 }
1904 
1905 Semaphore::~Semaphore() {
1906   if (_semaphore != NULL) {
1907     ::CloseHandle(_semaphore);
1908   }
1909 }
1910 
1911 void Semaphore::signal(uint count) {
1912   BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL);
1913 
1914   assert(ret != 0, err_msg("ReleaseSemaphore failed: %d", GetLastError()));
1915 }
1916 
1917 void Semaphore::signal() {
1918   signal(1);
1919 }
1920 
1921 void Semaphore::wait() {
1922   DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
1923   assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed: %d", GetLastError()));
1924 }
1925 
1926 // sun.misc.Signal
1927 // NOTE that this is a workaround for an apparent kernel bug where if
1928 // a signal handler for SIGBREAK is installed then that signal handler
1929 // takes priority over the console control handler for CTRL_CLOSE_EVENT.
1930 // See bug 4416763.
1931 static void (*sigbreakHandler)(int) = NULL;
1932 
1933 static void UserHandler(int sig, void *siginfo, void *context) {
1934   os::signal_notify(sig);
1935   // We need to reinstate the signal handler each time...
1936   os::signal(sig, (void*)UserHandler);
1937 }
1938 
1939 void* os::user_handler() {
1940   return (void*) UserHandler;
1941 }
1942 
1943 void* os::signal(int signal_number, void* handler) {


< prev index next >