| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Platform specific code for POSIX goes here. This is not a platform on its | 28 // Platform specific code for POSIX goes here. This is not a platform on its |
| 29 // own but contains the parts which are the same across POSIX platforms Linux, | 29 // own but contains the parts which are the same across POSIX platforms Linux, |
| 30 // Mac OS, FreeBSD and OpenBSD. | 30 // Mac OS, FreeBSD and OpenBSD. |
| 31 | 31 |
| 32 #include <unistd.h> | 32 #include <unistd.h> |
| 33 #include <errno.h> | 33 #include <errno.h> |
| 34 #include <time.h> | 34 #include <time.h> |
| 35 | 35 |
| 36 #include <sys/mman.h> |
| 36 #include <sys/socket.h> | 37 #include <sys/socket.h> |
| 37 #include <sys/resource.h> | 38 #include <sys/resource.h> |
| 38 #include <sys/time.h> | 39 #include <sys/time.h> |
| 39 #include <sys/types.h> | 40 #include <sys/types.h> |
| 41 #include <sys/stat.h> |
| 40 | 42 |
| 41 #include <arpa/inet.h> | 43 #include <arpa/inet.h> |
| 42 #include <netinet/in.h> | 44 #include <netinet/in.h> |
| 43 #include <netdb.h> | 45 #include <netdb.h> |
| 44 | 46 |
| 47 #undef MAP_TYPE |
| 48 |
| 45 #if defined(ANDROID) | 49 #if defined(ANDROID) |
| 46 #define LOG_TAG "v8" | 50 #define LOG_TAG "v8" |
| 47 #include <utils/Log.h> // LOG_PRI_VA | 51 #include <utils/Log.h> // LOG_PRI_VA |
| 48 #endif | 52 #endif |
| 49 | 53 |
| 50 #include "v8.h" | 54 #include "v8.h" |
| 51 | 55 |
| 52 #include "platform.h" | 56 #include "platform.h" |
| 53 | 57 |
| 54 namespace v8 { | 58 namespace v8 { |
| 55 namespace internal { | 59 namespace internal { |
| 56 | 60 |
| 57 | 61 |
| 58 // Maximum size of the virtual memory. 0 means there is no artificial | 62 // Maximum size of the virtual memory. 0 means there is no artificial |
| 59 // limit. | 63 // limit. |
| 60 | 64 |
| 61 intptr_t OS::MaxVirtualMemory() { | 65 intptr_t OS::MaxVirtualMemory() { |
| 62 struct rlimit limit; | 66 struct rlimit limit; |
| 63 int result = getrlimit(RLIMIT_DATA, &limit); | 67 int result = getrlimit(RLIMIT_DATA, &limit); |
| 64 if (result != 0) return 0; | 68 if (result != 0) return 0; |
| 65 return limit.rlim_cur; | 69 return limit.rlim_cur; |
| 66 } | 70 } |
| 67 | 71 |
| 68 | 72 |
| 73 // Create guard pages. |
| 74 void OS::Guard(void* address, const size_t size) { |
| 75 mprotect(address, size, PROT_NONE); |
| 76 } |
| 77 |
| 78 |
| 69 // ---------------------------------------------------------------------------- | 79 // ---------------------------------------------------------------------------- |
| 70 // Math functions | 80 // Math functions |
| 71 | 81 |
| 72 double modulo(double x, double y) { | 82 double modulo(double x, double y) { |
| 73 return fmod(x, y); | 83 return fmod(x, y); |
| 74 } | 84 } |
| 75 | 85 |
| 76 | 86 |
| 77 double OS::nan_value() { | 87 double OS::nan_value() { |
| 78 // NAN from math.h is defined in C99 and not in POSIX. | 88 // NAN from math.h is defined in C99 and not in POSIX. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int OS::GetLastError() { | 133 int OS::GetLastError() { |
| 124 return errno; | 134 return errno; |
| 125 } | 135 } |
| 126 | 136 |
| 127 | 137 |
| 128 // ---------------------------------------------------------------------------- | 138 // ---------------------------------------------------------------------------- |
| 129 // POSIX stdio support. | 139 // POSIX stdio support. |
| 130 // | 140 // |
| 131 | 141 |
| 132 FILE* OS::FOpen(const char* path, const char* mode) { | 142 FILE* OS::FOpen(const char* path, const char* mode) { |
| 133 return fopen(path, mode); | 143 FILE* file = fopen(path, mode); |
| 144 if (file == NULL) return NULL; |
| 145 struct stat file_stat; |
| 146 if (fstat(fileno(file), &file_stat) != 0) return NULL; |
| 147 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0); |
| 148 if (is_regular_file) return file; |
| 149 fclose(file); |
| 150 return NULL; |
| 134 } | 151 } |
| 135 | 152 |
| 136 | 153 |
| 137 bool OS::Remove(const char* path) { | 154 bool OS::Remove(const char* path) { |
| 138 return (remove(path) == 0); | 155 return (remove(path) == 0); |
| 139 } | 156 } |
| 140 | 157 |
| 141 | 158 |
| 159 FILE* OS::OpenTemporaryFile() { |
| 160 return tmpfile(); |
| 161 } |
| 162 |
| 163 |
| 142 const char* const OS::LogFileOpenMode = "w"; | 164 const char* const OS::LogFileOpenMode = "w"; |
| 143 | 165 |
| 144 | 166 |
| 145 void OS::Print(const char* format, ...) { | 167 void OS::Print(const char* format, ...) { |
| 146 va_list args; | 168 va_list args; |
| 147 va_start(args, format); | 169 va_start(args, format); |
| 148 VPrint(format, args); | 170 VPrint(format, args); |
| 149 va_end(args); | 171 va_end(args); |
| 150 } | 172 } |
| 151 | 173 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 return ntohl(value); | 449 return ntohl(value); |
| 428 } | 450 } |
| 429 | 451 |
| 430 | 452 |
| 431 Socket* OS::CreateSocket() { | 453 Socket* OS::CreateSocket() { |
| 432 return new POSIXSocket(); | 454 return new POSIXSocket(); |
| 433 } | 455 } |
| 434 | 456 |
| 435 | 457 |
| 436 } } // namespace v8::internal | 458 } } // namespace v8::internal |
| OLD | NEW |