12 #include <sys/resource.h> 14 #include <sys/types.h> 15 #include <sys/ucontext.h> 17 #include <sys/fcntl.h> 31 #include "src/base/macros.h" 32 #include "src/base/platform/platform-posix-time.h" 33 #include "src/base/platform/platform-posix.h" 34 #include "src/base/platform/platform.h" 39 TimezoneCache* OS::CreateTimezoneCache() {
40 return new PosixDefaultTimezoneCache();
43 static unsigned StringToLong(
char* buffer) {
44 return static_cast<unsigned>(strtol(buffer,
nullptr, 16));
47 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
48 std::vector<SharedLibraryAddress> result;
49 static const int MAP_LENGTH = 1024;
50 int fd = open(
"/proc/self/maps", O_RDONLY);
51 if (fd < 0)
return result;
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 if (bytes_read < 8)
break;
65 unsigned end = StringToLong(addr_buffer);
66 char buffer[MAP_LENGTH];
70 if (bytes_read >= MAP_LENGTH - 1)
break;
71 bytes_read = read(fd, buffer + bytes_read, 1);
72 if (bytes_read < 1)
break;
73 }
while (buffer[bytes_read] !=
'\n');
74 buffer[bytes_read] = 0;
76 if (buffer[3] !=
'x')
continue;
77 char* start_of_path = index(buffer,
'/');
79 if (start_of_path ==
nullptr)
continue;
80 buffer[bytes_read] = 0;
81 result.push_back(SharedLibraryAddress(start_of_path, start, end));
87 void OS::SignalCodeMovingGC() {}