diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2019-10-09 23:27:26 +0300 |
---|---|---|
committer | Myles Borins <myles.borins@gmail.com> | 2019-10-23 10:32:52 +0300 |
commit | 3eae67047088bfee66c02f9893f44b61f430be87 (patch) | |
tree | 08636cad0f753497d49e8a0f22fc4ff55bc264f2 /src/large_pages | |
parent | b1b8663a233e3168565ceb618b2c14b6542fa871 (diff) |
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 <suresh.srinivas@intel.com>!
PR-URL: https://github.com/nodejs/node/pull/29973
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/large_pages')
-rw-r--r-- | src/large_pages/node_large_page.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index 220f71fa105..4e2f8fc4410 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -83,11 +83,11 @@ static void PrintSystemError(int error) { return; } -inline int64_t hugepage_align_up(int64_t addr) { +inline uintptr_t hugepage_align_up(uintptr_t addr) { return (((addr) + (hps) - 1) & ~((hps) - 1)); } -inline int64_t hugepage_align_down(int64_t addr) { +inline uintptr_t hugepage_align_down(uintptr_t addr) { return ((addr) & ~((hps) - 1)); } @@ -103,7 +103,7 @@ static struct text_region FindNodeTextRegion() { std::string permission; std::string dev; char dash; - int64_t start, end, offset, inode; + uintptr_t start, end, offset, inode; struct text_region nregion; nregion.found_text_region = false; @@ -138,18 +138,20 @@ static struct text_region FindNodeTextRegion() { std::string pathname; iss >> pathname; if (pathname == exename && permission == "r-xp") { - start = reinterpret_cast<uint64_t>(&__nodetext); - char* from = reinterpret_cast<char*>(hugepage_align_up(start)); - char* to = reinterpret_cast<char*>(hugepage_align_down(end)); - - if (from < to) { - size_t size = to - from; - nregion.found_text_region = true; - nregion.from = from; - nregion.to = to; - nregion.total_hugepages = size / hps; + uintptr_t ntext = reinterpret_cast<uintptr_t>(&__nodetext); + if (ntext >= start && ntext < end) { + char* from = reinterpret_cast<char*>(hugepage_align_up(ntext)); + char* to = reinterpret_cast<char*>(hugepage_align_down(end)); + + if (from < to) { + size_t size = to - from; + nregion.found_text_region = true; + nregion.from = from; + nregion.to = to; + nregion.total_hugepages = size / hps; + } + break; } - break; } } } |