8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 05ef4bd commit 2501982Copy full SHA for 2501982
common.gypi
@@ -38,7 +38,7 @@
38
39
# Reset this number to 0 on major V8 upgrades.
40
# Increment by one for each non-official patch applied to deps/v8.
41
- 'v8_embedder_string': '-node.26',
+ 'v8_embedder_string': '-node.27',
42
43
##### V8 defaults for Node.js #####
44
deps/v8/src/base/platform/platform-freebsd.cc
@@ -13,10 +13,12 @@
13
#include <sys/time.h>
14
#include <sys/types.h>
15
#include <sys/ucontext.h>
16
+#include <sys/user.h>
17
18
#include <sys/fcntl.h> // open
19
#include <sys/mman.h> // mmap & munmap
20
#include <sys/stat.h> // open
21
+#include <sys/sysctl.h>
22
#include <unistd.h> // getpagesize
23
// If you don't have execinfo.h then you need devel/libexecinfo from ports.
24
#include <errno.h>
@@ -46,41 +48,47 @@ static unsigned StringToLong(char* buffer) {
46
48
47
49
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
50
std::vector<SharedLibraryAddress> result;
- static const int MAP_LENGTH = 1024;
- int fd = open("/proc/self/maps", O_RDONLY);
51
- if (fd < 0) return result;
52
- while (true) {
53
- char addr_buffer[11];
54
- addr_buffer[0] = '0';
55
- addr_buffer[1] = 'x';
56
- addr_buffer[10] = 0;
57
- ssize_t bytes_read = read(fd, addr_buffer + 2, 8);
58
- if (bytes_read < 8) break;
59
- unsigned start = StringToLong(addr_buffer);
60
- bytes_read = read(fd, addr_buffer + 2, 1);
61
- if (bytes_read < 1) break;
62
- if (addr_buffer[2] != '-') break;
63
- bytes_read = read(fd, addr_buffer + 2, 8);
64
65
- unsigned end = StringToLong(addr_buffer);
66
- char buffer[MAP_LENGTH];
67
- bytes_read = -1;
68
- do {
69
- bytes_read++;
70
- if (bytes_read >= MAP_LENGTH - 1) break;
71
- bytes_read = read(fd, buffer + bytes_read, 1);
72
73
- } while (buffer[bytes_read] != '\n');
74
- buffer[bytes_read] = 0;
75
- // Ignore mappings that are not executable.
76
- if (buffer[3] != 'x') continue;
77
- char* start_of_path = index(buffer, '/');
78
- // There may be no filename in this line. Skip to next.
79
- if (start_of_path == nullptr) continue;
80
81
- result.push_back(SharedLibraryAddress(start_of_path, start, end));
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid()};
+ size_t miblen = sizeof(mib) / sizeof(mib[0]);
+ size_t buffer_size;
+ if (sysctl(mib, miblen, nullptr, &buffer_size, nullptr, 0) == 0) {
+ // Overallocate the buffer by 1/3 to account for concurrent
+ // kinfo_vmentry change. 1/3 is an arbitrary constant that
+ // works in practice.
+ buffer_size = buffer_size * 4 / 3;
+ std::vector<char> buffer(buffer_size);
+ int ret = sysctl(mib, miblen, buffer.data(), &buffer_size, nullptr, 0);
+
+ if (ret == 0 || (ret == -1 && errno == ENOMEM)) {
+ char* start = buffer.data();
+ char* end = start + buffer_size;
+ while (start < end) {
+ struct kinfo_vmentry* map =
+ reinterpret_cast<struct kinfo_vmentry*>(start);
+ const size_t ssize = map->kve_structsize;
+ char* path = map->kve_path;
+ CHECK_NE(0, ssize);
+ if ((map->kve_protection & KVME_PROT_READ) != 0 &&
+ (map->kve_protection & KVME_PROT_EXEC) != 0 && path[0] != '\0') {
+ char* sep = strrchr(path, '/');
+ std::string lib_name;
+ if (sep != nullptr) {
+ lib_name = std::string(++sep);
+ } else {
+ lib_name = std::string(path);
82
+ }
83
+ result.push_back(SharedLibraryAddress(
84
+ lib_name, reinterpret_cast<uintptr_t>(map->kve_start),
85
+ reinterpret_cast<uintptr_t>(map->kve_end)));
86
87
88
+ start += ssize;
89
90
91
}
- close(fd);
92
return result;
93
94