Fix another duplicate maps parser.
Change-Id: Icb69f59ffbd0d5de7f727142260fae152d36a904
This commit is contained in:
parent
9e3a249152
commit
15dfd63aba
@ -41,6 +41,8 @@
|
|||||||
#include "BionicDeathTest.h"
|
#include "BionicDeathTest.h"
|
||||||
#include "ScopedSignalHandler.h"
|
#include "ScopedSignalHandler.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
extern "C" pid_t gettid();
|
extern "C" pid_t gettid();
|
||||||
|
|
||||||
TEST(pthread, pthread_key_create) {
|
TEST(pthread, pthread_key_create) {
|
||||||
@ -1158,19 +1160,14 @@ TEST(pthread, pthread_attr_getstack__main_thread) {
|
|||||||
#if defined(__BIONIC__)
|
#if defined(__BIONIC__)
|
||||||
// What does /proc/self/maps' [stack] line say?
|
// What does /proc/self/maps' [stack] line say?
|
||||||
void* maps_stack_hi = NULL;
|
void* maps_stack_hi = NULL;
|
||||||
FILE* fp = fopen("/proc/self/maps", "r");
|
std::vector<map_record> maps;
|
||||||
ASSERT_TRUE(fp != NULL);
|
ASSERT_TRUE(Maps::parse_maps(&maps));
|
||||||
char line[BUFSIZ];
|
for (auto& map : maps) {
|
||||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
if (map.pathname == "[stack]") {
|
||||||
uintptr_t lo, hi;
|
maps_stack_hi = reinterpret_cast<void*>(map.addr_end);
|
||||||
int name_pos;
|
|
||||||
sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d %n", &lo, &hi, &name_pos);
|
|
||||||
if (strcmp(line + name_pos, "[stack]\n") == 0) {
|
|
||||||
maps_stack_hi = reinterpret_cast<void*>(hi);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
// The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
|
// The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
|
||||||
// Remember that the stack grows down (and is mapped in on demand), so the low address of the
|
// Remember that the stack grows down (and is mapped in on demand), so the low address of the
|
||||||
|
@ -38,9 +38,7 @@ struct map_record {
|
|||||||
class Maps {
|
class Maps {
|
||||||
public:
|
public:
|
||||||
static bool parse_maps(std::vector<map_record>* maps) {
|
static bool parse_maps(std::vector<map_record>* maps) {
|
||||||
char path[64];
|
FILE* fp = fopen("/proc/self/maps", "re");
|
||||||
snprintf(path, sizeof(path), "/proc/self/task/%d/maps", getpid());
|
|
||||||
FILE* fp = fopen(path, "re");
|
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -53,11 +51,11 @@ class Maps {
|
|||||||
while (fgets(line, sizeof(line), fp) != nullptr) {
|
while (fgets(line, sizeof(line), fp) != nullptr) {
|
||||||
map_record record;
|
map_record record;
|
||||||
uint32_t dev_major, dev_minor;
|
uint32_t dev_major, dev_minor;
|
||||||
char pathstr[BUFSIZ];
|
int path_offset;
|
||||||
char prot[5]; // sizeof("rwxp")
|
char prot[5]; // sizeof("rwxp")
|
||||||
if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR " %4s %" SCNxPTR " %x:%x %lu %s",
|
if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR " %4s %" SCNxPTR " %x:%x %lu %n",
|
||||||
&record.addr_start, &record.addr_end, prot, &record.offset,
|
&record.addr_start, &record.addr_end, prot, &record.offset,
|
||||||
&dev_major, &dev_minor, &record.inode, pathstr) == 8) {
|
&dev_major, &dev_minor, &record.inode, &path_offset) == 7) {
|
||||||
record.perms = 0;
|
record.perms = 0;
|
||||||
if (prot[0] == 'r') {
|
if (prot[0] == 'r') {
|
||||||
record.perms |= PROT_READ;
|
record.perms |= PROT_READ;
|
||||||
@ -72,7 +70,10 @@ class Maps {
|
|||||||
// TODO: parse shared/private?
|
// TODO: parse shared/private?
|
||||||
|
|
||||||
record.device = makedev(dev_major, dev_minor);
|
record.device = makedev(dev_major, dev_minor);
|
||||||
record.pathname = pathstr;
|
record.pathname = line + path_offset;
|
||||||
|
if (!record.pathname.empty() && record.pathname.back() == '\n') {
|
||||||
|
record.pathname.pop_back();
|
||||||
|
}
|
||||||
maps->push_back(record);
|
maps->push_back(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user