Skip to content

Commit 45c5ad7

Browse files
Gabriel Schulhoftargos
Gabriel Schulhof
authored andcommitted
src: refine maps parsing for large pages
Multiple sections may be marked as "r-xp" and with the executable's path. We use the location of the `__nodetext` symbol added by the linker script to ensure that the range we retrieve from the maps file does indeed contain the Node.js text section. Thanks to Suresh Srinivas <[email protected]>! PR-URL: #29973 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent 3e39909 commit 45c5ad7

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/large_pages/node_large_page.cc

+16-14
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ static void PrintSystemError(int error) {
8383
return;
8484
}
8585

86-
inline int64_t hugepage_align_up(int64_t addr) {
86+
inline uintptr_t hugepage_align_up(uintptr_t addr) {
8787
return (((addr) + (hps) - 1) & ~((hps) - 1));
8888
}
8989

90-
inline int64_t hugepage_align_down(int64_t addr) {
90+
inline uintptr_t hugepage_align_down(uintptr_t addr) {
9191
return ((addr) & ~((hps) - 1));
9292
}
9393

@@ -103,7 +103,7 @@ static struct text_region FindNodeTextRegion() {
103103
std::string permission;
104104
std::string dev;
105105
char dash;
106-
int64_t start, end, offset, inode;
106+
uintptr_t start, end, offset, inode;
107107
struct text_region nregion;
108108

109109
nregion.found_text_region = false;
@@ -138,18 +138,20 @@ static struct text_region FindNodeTextRegion() {
138138
std::string pathname;
139139
iss >> pathname;
140140
if (pathname == exename && permission == "r-xp") {
141-
start = reinterpret_cast<uint64_t>(&__nodetext);
142-
char* from = reinterpret_cast<char*>(hugepage_align_up(start));
143-
char* to = reinterpret_cast<char*>(hugepage_align_down(end));
144-
145-
if (from < to) {
146-
size_t size = to - from;
147-
nregion.found_text_region = true;
148-
nregion.from = from;
149-
nregion.to = to;
150-
nregion.total_hugepages = size / hps;
141+
uintptr_t ntext = reinterpret_cast<uintptr_t>(&__nodetext);
142+
if (ntext >= start && ntext < end) {
143+
char* from = reinterpret_cast<char*>(hugepage_align_up(ntext));
144+
char* to = reinterpret_cast<char*>(hugepage_align_down(end));
145+
146+
if (from < to) {
147+
size_t size = to - from;
148+
nregion.found_text_region = true;
149+
nregion.from = from;
150+
nregion.to = to;
151+
nregion.total_hugepages = size / hps;
152+
}
153+
break;
151154
}
152-
break;
153155
}
154156
}
155157
}

0 commit comments

Comments
 (0)