V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
platform-macos.cc
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
3 // found in the LICENSE file.
4 
5 // Platform-specific code for MacOS goes here. For the POSIX-compatible
6 // parts, the implementation is in platform-posix.cc.
7 
8 #include <dlfcn.h>
9 #include <mach/mach_init.h>
10 #include <mach-o/dyld.h>
11 #include <mach-o/getsect.h>
12 #include <sys/mman.h>
13 #include <unistd.h>
14 
15 #include <AvailabilityMacros.h>
16 
17 #include <errno.h>
18 #include <libkern/OSAtomic.h>
19 #include <mach/mach.h>
20 #include <mach/semaphore.h>
21 #include <mach/task.h>
22 #include <mach/vm_statistics.h>
23 #include <pthread.h>
24 #include <semaphore.h>
25 #include <signal.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/resource.h>
30 #include <sys/sysctl.h>
31 #include <sys/time.h>
32 #include <sys/types.h>
33 
34 #include <cmath>
35 
36 #undef MAP_TYPE
37 
38 #include "src/base/macros.h"
39 #include "src/base/platform/platform-posix-time.h"
40 #include "src/base/platform/platform-posix.h"
41 #include "src/base/platform/platform.h"
42 
43 namespace v8 {
44 namespace base {
45 
46 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
47  std::vector<SharedLibraryAddress> result;
48  unsigned int images_count = _dyld_image_count();
49  for (unsigned int i = 0; i < images_count; ++i) {
50  const mach_header* header = _dyld_get_image_header(i);
51  if (header == nullptr) continue;
52 #if V8_HOST_ARCH_X64
53  uint64_t size;
54  char* code_ptr = getsectdatafromheader_64(
55  reinterpret_cast<const mach_header_64*>(header), SEG_TEXT, SECT_TEXT,
56  &size);
57 #else
58  unsigned int size;
59  char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size);
60 #endif
61  if (code_ptr == nullptr) continue;
62  const intptr_t slide = _dyld_get_image_vmaddr_slide(i);
63  const uintptr_t start = reinterpret_cast<uintptr_t>(code_ptr) + slide;
64  result.push_back(SharedLibraryAddress(_dyld_get_image_name(i), start,
65  start + size, slide));
66  }
67  return result;
68 }
69 
70 void OS::SignalCodeMovingGC() {}
71 
72 TimezoneCache* OS::CreateTimezoneCache() {
73  return new PosixDefaultTimezoneCache();
74 }
75 
76 } // namespace base
77 } // namespace v8
Definition: libplatform.h:13