46 #include "prims/jvm_misc.hpp"
47 #include "runtime/arguments.hpp"
48 #include "runtime/atomic.inline.hpp"
49 #include "runtime/extendedPC.hpp"
50 #include "runtime/globals.hpp"
51 #include "runtime/interfaceSupport.hpp"
52 #include "runtime/java.hpp"
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>
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) {
|
46 #include "prims/jvm_misc.hpp"
47 #include "runtime/arguments.hpp"
48 #include "runtime/atomic.inline.hpp"
49 #include "runtime/extendedPC.hpp"
50 #include "runtime/globals.hpp"
51 #include "runtime/interfaceSupport.hpp"
52 #include "runtime/java.hpp"
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 "semaphore_windows.hpp"
67 #include "services/attachListener.hpp"
68 #include "services/memTracker.hpp"
69 #include "services/runtimeService.hpp"
70 #include "utilities/decoder.hpp"
71 #include "utilities/defaultStream.hpp"
72 #include "utilities/events.hpp"
73 #include "utilities/growableArray.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>
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 WindowsSemaphore::WindowsSemaphore(uint value) {
1900 _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL);
1901
1902 guarantee(_semaphore != NULL, err_msg("CreateSemaphore failed with error code: %lu", GetLastError()));
1903 }
1904
1905 WindowsSemaphore::~WindowsSemaphore() {
1906 ::CloseHandle(_semaphore);
1907 }
1908
1909 void WindowsSemaphore::signal(uint count) {
1910 if (count > 0) {
1911 BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL);
1912
1913 assert(ret != 0, err_msg("ReleaseSemaphore failed with error code: %lu", GetLastError()));
1914 }
1915 }
1916
1917 void WindowsSemaphore::wait() {
1918 DWORD ret = ::WaitForSingleObject(_semaphore, INFINITE);
1919 assert(ret != WAIT_FAILED, err_msg("WaitForSingleObject failed with error code: %lu", GetLastError()));
1920 assert(ret == WAIT_OBJECT_0, err_msg("WaitForSingleObject failed with return value: %lu", ret));
1921 }
1922
1923 // sun.misc.Signal
1924 // NOTE that this is a workaround for an apparent kernel bug where if
1925 // a signal handler for SIGBREAK is installed then that signal handler
1926 // takes priority over the console control handler for CTRL_CLOSE_EVENT.
1927 // See bug 4416763.
1928 static void (*sigbreakHandler)(int) = NULL;
1929
1930 static void UserHandler(int sig, void *siginfo, void *context) {
1931 os::signal_notify(sig);
1932 // We need to reinstate the signal handler each time...
1933 os::signal(sig, (void*)UserHandler);
1934 }
1935
1936 void* os::user_handler() {
1937 return (void*) UserHandler;
1938 }
1939
1940 void* os::signal(int signal_number, void* handler) {
|