| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 return NULL; | 733 return NULL; |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 | 736 |
| 737 | 737 |
| 738 bool OS::Remove(const char* path) { | 738 bool OS::Remove(const char* path) { |
| 739 return (DeleteFileA(path) != 0); | 739 return (DeleteFileA(path) != 0); |
| 740 } | 740 } |
| 741 | 741 |
| 742 | 742 |
| 743 FILE* OS::OpenTemporaryFile() { |
| 744 // tmpfile_s tries to use the root dir, don't use it. |
| 745 char tempPathBuffer[MAX_PATH]; |
| 746 DWORD path_result = 0; |
| 747 path_result = GetTempPathA(MAX_PATH, tempPathBuffer); |
| 748 if (path_result > MAX_PATH || path_result == 0) return NULL; |
| 749 UINT name_result = 0; |
| 750 char tempNameBuffer[MAX_PATH]; |
| 751 name_result = GetTempFileNameA(tempPathBuffer, "", 0, tempNameBuffer); |
| 752 if (name_result == 0) return NULL; |
| 753 FILE* result = FOpen(tempNameBuffer, "w+"); // Same mode as tmpfile uses. |
| 754 if (result != NULL) { |
| 755 Remove(tempNameBuffer); // Delete on close. |
| 756 } |
| 757 return result; |
| 758 } |
| 759 |
| 760 |
| 743 // Open log file in binary mode to avoid /n -> /r/n conversion. | 761 // Open log file in binary mode to avoid /n -> /r/n conversion. |
| 744 const char* const OS::LogFileOpenMode = "wb"; | 762 const char* const OS::LogFileOpenMode = "wb"; |
| 745 | 763 |
| 746 | 764 |
| 747 // Print (debug) message to console. | 765 // Print (debug) message to console. |
| 748 void OS::Print(const char* format, ...) { | 766 void OS::Print(const char* format, ...) { |
| 749 va_list args; | 767 va_list args; |
| 750 va_start(args, format); | 768 va_start(args, format); |
| 751 VPrint(format, args); | 769 VPrint(format, args); |
| 752 va_end(args); | 770 va_end(args); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 } | 950 } |
| 933 | 951 |
| 934 | 952 |
| 935 void OS::Free(void* address, const size_t size) { | 953 void OS::Free(void* address, const size_t size) { |
| 936 // TODO(1240712): VirtualFree has a return value which is ignored here. | 954 // TODO(1240712): VirtualFree has a return value which is ignored here. |
| 937 VirtualFree(address, 0, MEM_RELEASE); | 955 VirtualFree(address, 0, MEM_RELEASE); |
| 938 USE(size); | 956 USE(size); |
| 939 } | 957 } |
| 940 | 958 |
| 941 | 959 |
| 942 #ifdef ENABLE_HEAP_PROTECTION | 960 void OS::Guard(void* address, const size_t size) { |
| 943 | 961 DWORD oldprotect; |
| 944 void OS::Protect(void* address, size_t size) { | 962 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); |
| 945 // TODO(1240712): VirtualProtect has a return value which is ignored here. | |
| 946 DWORD old_protect; | |
| 947 VirtualProtect(address, size, PAGE_READONLY, &old_protect); | |
| 948 } | 963 } |
| 949 | 964 |
| 950 | 965 |
| 951 void OS::Unprotect(void* address, size_t size, bool is_executable) { | |
| 952 // TODO(1240712): VirtualProtect has a return value which is ignored here. | |
| 953 DWORD new_protect = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | |
| 954 DWORD old_protect; | |
| 955 VirtualProtect(address, size, new_protect, &old_protect); | |
| 956 } | |
| 957 | |
| 958 #endif | |
| 959 | |
| 960 | |
| 961 void OS::Sleep(int milliseconds) { | 966 void OS::Sleep(int milliseconds) { |
| 962 ::Sleep(milliseconds); | 967 ::Sleep(milliseconds); |
| 963 } | 968 } |
| 964 | 969 |
| 965 | 970 |
| 966 void OS::Abort() { | 971 void OS::Abort() { |
| 967 if (!IsDebuggerPresent()) { | 972 if (!IsDebuggerPresent()) { |
| 968 #ifdef _MSC_VER | 973 #ifdef _MSC_VER |
| 969 // Make the MSVCRT do a silent abort. | 974 // Make the MSVCRT do a silent abort. |
| 970 _set_abort_behavior(0, _WRITE_ABORT_MSG); | 975 _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 uint32_t Socket::NToH(uint32_t value) { | 1881 uint32_t Socket::NToH(uint32_t value) { |
| 1877 return ntohl(value); | 1882 return ntohl(value); |
| 1878 } | 1883 } |
| 1879 | 1884 |
| 1880 | 1885 |
| 1881 Socket* OS::CreateSocket() { | 1886 Socket* OS::CreateSocket() { |
| 1882 return new Win32Socket(); | 1887 return new Win32Socket(); |
| 1883 } | 1888 } |
| 1884 | 1889 |
| 1885 | 1890 |
| 1886 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 1887 | |
| 1888 // ---------------------------------------------------------------------------- | 1891 // ---------------------------------------------------------------------------- |
| 1889 // Win32 profiler support. | 1892 // Win32 profiler support. |
| 1890 | 1893 |
| 1891 class Sampler::PlatformData : public Malloced { | 1894 class Sampler::PlatformData : public Malloced { |
| 1892 public: | 1895 public: |
| 1893 // Get a handle to the calling thread. This is the thread that we are | 1896 // Get a handle to the calling thread. This is the thread that we are |
| 1894 // going to profile. We need to make a copy of the handle because we are | 1897 // going to profile. We need to make a copy of the handle because we are |
| 1895 // going to use it in the sampler thread. Using GetThreadHandle() will | 1898 // going to use it in the sampler thread. Using GetThreadHandle() will |
| 1896 // not work in this case. We're using OpenThread because DuplicateHandle | 1899 // not work in this case. We're using OpenThread because DuplicateHandle |
| 1897 // for some reason doesn't work in Chrome's sandbox. | 1900 // for some reason doesn't work in Chrome's sandbox. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2052 SamplerThread::AddActiveSampler(this); | 2055 SamplerThread::AddActiveSampler(this); |
| 2053 } | 2056 } |
| 2054 | 2057 |
| 2055 | 2058 |
| 2056 void Sampler::Stop() { | 2059 void Sampler::Stop() { |
| 2057 ASSERT(IsActive()); | 2060 ASSERT(IsActive()); |
| 2058 SamplerThread::RemoveActiveSampler(this); | 2061 SamplerThread::RemoveActiveSampler(this); |
| 2059 SetActive(false); | 2062 SetActive(false); |
| 2060 } | 2063 } |
| 2061 | 2064 |
| 2062 #endif // ENABLE_LOGGING_AND_PROFILING | |
| 2063 | 2065 |
| 2064 } } // namespace v8::internal | 2066 } } // namespace v8::internal |
| OLD | NEW |