OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This module contains the platform-specific code. This make the rest of the | 5 // This module contains the platform-specific code. This make the rest of the |
6 // code less dependent on operating system, compilers and runtime libraries. | 6 // code less dependent on operating system, compilers and runtime libraries. |
7 // This module does specifically not deal with differences between different | 7 // This module does specifically not deal with differences between different |
8 // processor architecture. | 8 // processor architecture. |
9 // The platform classes have the same definition for all platforms. The | 9 // The platform classes have the same definition for all platforms. The |
10 // implementation for a particular platform is put in platform_<os>.cc. | 10 // implementation for a particular platform is put in platform_<os>.cc. |
11 // The build system then uses the implementation for the target platform. | 11 // The build system then uses the implementation for the target platform. |
12 // | 12 // |
13 // This design has been chosen because it is simple and fast. Alternatively, | 13 // This design has been chosen because it is simple and fast. Alternatively, |
14 // the platform dependent classes could have been implemented using abstract | 14 // the platform dependent classes could have been implemented using abstract |
15 // superclasses with virtual methods and having specializations for each | 15 // superclasses with virtual methods and having specializations for each |
16 // platform. This design was rejected because it was more complicated and | 16 // platform. This design was rejected because it was more complicated and |
17 // slower. It would require factory methods for selecting the right | 17 // slower. It would require factory methods for selecting the right |
18 // implementation and the overhead of virtual methods for performance | 18 // implementation and the overhead of virtual methods for performance |
19 // sensitive like mutex locking/unlocking. | 19 // sensitive like mutex locking/unlocking. |
20 | 20 |
21 #ifndef V8_BASE_PLATFORM_PLATFORM_H_ | 21 #ifndef V8_BASE_PLATFORM_PLATFORM_H_ |
22 #define V8_BASE_PLATFORM_PLATFORM_H_ | 22 #define V8_BASE_PLATFORM_PLATFORM_H_ |
23 | 23 |
24 #include <cstdarg> | 24 #include <cstdarg> |
25 #include <string> | 25 #include <string> |
26 #include <vector> | 26 #include <vector> |
27 | 27 |
28 #include "src/base/build_config.h" | 28 #include "src/base/build_config.h" |
29 #include "src/base/compiler-specific.h" | |
30 #include "src/base/platform/mutex.h" | 29 #include "src/base/platform/mutex.h" |
31 #include "src/base/platform/semaphore.h" | 30 #include "src/base/platform/semaphore.h" |
32 | 31 |
33 #if V8_OS_QNX | 32 #if V8_OS_QNX |
34 #include "src/base/qnx-math.h" | 33 #include "src/base/qnx-math.h" |
35 #endif | 34 #endif |
36 | 35 |
37 namespace v8 { | 36 namespace v8 { |
38 namespace base { | 37 namespace base { |
39 | 38 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 147 |
149 // Opens a temporary file, the file is auto removed on close. | 148 // Opens a temporary file, the file is auto removed on close. |
150 static FILE* OpenTemporaryFile(); | 149 static FILE* OpenTemporaryFile(); |
151 | 150 |
152 // Log file open mode is platform-dependent due to line ends issues. | 151 // Log file open mode is platform-dependent due to line ends issues. |
153 static const char* const LogFileOpenMode; | 152 static const char* const LogFileOpenMode; |
154 | 153 |
155 // Print output to console. This is mostly used for debugging output. | 154 // Print output to console. This is mostly used for debugging output. |
156 // On platforms that has standard terminal output, the output | 155 // On platforms that has standard terminal output, the output |
157 // should go to stdout. | 156 // should go to stdout. |
158 static PRINTF_FORMAT(1, 2) void Print(const char* format, ...); | 157 static void Print(const char* format, ...); |
159 static PRINTF_FORMAT(1, 0) void VPrint(const char* format, va_list args); | 158 static void VPrint(const char* format, va_list args); |
160 | 159 |
161 // Print output to a file. This is mostly used for debugging output. | 160 // Print output to a file. This is mostly used for debugging output. |
162 static PRINTF_FORMAT(2, 3) void FPrint(FILE* out, const char* format, ...); | 161 static void FPrint(FILE* out, const char* format, ...); |
163 static PRINTF_FORMAT(2, 0) void VFPrint(FILE* out, const char* format, | 162 static void VFPrint(FILE* out, const char* format, va_list args); |
164 va_list args); | |
165 | 163 |
166 // Print error output to console. This is mostly used for error message | 164 // Print error output to console. This is mostly used for error message |
167 // output. On platforms that has standard terminal output, the output | 165 // output. On platforms that has standard terminal output, the output |
168 // should go to stderr. | 166 // should go to stderr. |
169 static PRINTF_FORMAT(1, 2) void PrintError(const char* format, ...); | 167 static void PrintError(const char* format, ...); |
170 static PRINTF_FORMAT(1, 0) void VPrintError(const char* format, va_list args); | 168 static void VPrintError(const char* format, va_list args); |
171 | 169 |
172 // Allocate/Free memory used by JS heap. Pages are readable/writable, but | 170 // Allocate/Free memory used by JS heap. Pages are readable/writable, but |
173 // they are not guaranteed to be executable unless 'executable' is true. | 171 // they are not guaranteed to be executable unless 'executable' is true. |
174 // Returns the address of allocated memory, or NULL if failed. | 172 // Returns the address of allocated memory, or NULL if failed. |
175 static void* Allocate(const size_t requested, | 173 static void* Allocate(const size_t requested, |
176 size_t* allocated, | 174 size_t* allocated, |
177 bool is_executable); | 175 bool is_executable); |
178 static void Free(void* address, const size_t size); | 176 static void Free(void* address, const size_t size); |
179 | 177 |
180 // This is the granularity at which the ProtectCode(...) call can set page | 178 // This is the granularity at which the ProtectCode(...) call can set page |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 virtual void* memory() const = 0; | 215 virtual void* memory() const = 0; |
218 virtual size_t size() const = 0; | 216 virtual size_t size() const = 0; |
219 | 217 |
220 static MemoryMappedFile* open(const char* name); | 218 static MemoryMappedFile* open(const char* name); |
221 static MemoryMappedFile* create(const char* name, size_t size, | 219 static MemoryMappedFile* create(const char* name, size_t size, |
222 void* initial); | 220 void* initial); |
223 }; | 221 }; |
224 | 222 |
225 // Safe formatting print. Ensures that str is always null-terminated. | 223 // Safe formatting print. Ensures that str is always null-terminated. |
226 // Returns the number of chars written, or -1 if output was truncated. | 224 // Returns the number of chars written, or -1 if output was truncated. |
227 static PRINTF_FORMAT(3, 4) int SNPrintF(char* str, int length, | 225 static int SNPrintF(char* str, int length, const char* format, ...); |
228 const char* format, ...); | 226 static int VSNPrintF(char* str, |
229 static PRINTF_FORMAT(3, 0) int VSNPrintF(char* str, int length, | 227 int length, |
230 const char* format, va_list args); | 228 const char* format, |
| 229 va_list args); |
231 | 230 |
232 static char* StrChr(char* str, int c); | 231 static char* StrChr(char* str, int c); |
233 static void StrNCpy(char* dest, int length, const char* src, size_t n); | 232 static void StrNCpy(char* dest, int length, const char* src, size_t n); |
234 | 233 |
235 // Support for the profiler. Can do nothing, in which case ticks | 234 // Support for the profiler. Can do nothing, in which case ticks |
236 // occuring in shared libraries will not be properly accounted for. | 235 // occuring in shared libraries will not be properly accounted for. |
237 struct SharedLibraryAddress { | 236 struct SharedLibraryAddress { |
238 SharedLibraryAddress( | 237 SharedLibraryAddress( |
239 const std::string& library_path, uintptr_t start, uintptr_t end) | 238 const std::string& library_path, uintptr_t start, uintptr_t end) |
240 : library_path(library_path), start(start), end(end) {} | 239 : library_path(library_path), start(start), end(end) {} |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 int stack_size_; | 481 int stack_size_; |
483 Semaphore* start_semaphore_; | 482 Semaphore* start_semaphore_; |
484 | 483 |
485 DISALLOW_COPY_AND_ASSIGN(Thread); | 484 DISALLOW_COPY_AND_ASSIGN(Thread); |
486 }; | 485 }; |
487 | 486 |
488 } // namespace base | 487 } // namespace base |
489 } // namespace v8 | 488 } // namespace v8 |
490 | 489 |
491 #endif // V8_BASE_PLATFORM_PLATFORM_H_ | 490 #endif // V8_BASE_PLATFORM_PLATFORM_H_ |
OLD | NEW |