Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 8e33c21

Browse files
committed
Prefer /proc/<pid>/task/<pid>/maps over /proc/<pid>/maps on Linux.
This resolves jemalloc#227.
1 parent f1f2b45 commit 8e33c21

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/prof.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,21 +1338,40 @@ prof_dump_gctx(bool propagate_err, prof_gctx_t *gctx, const prof_bt_t *bt,
13381338
return (ret);
13391339
}
13401340

1341+
JEMALLOC_ATTR(format(printf, 1, 2))
1342+
static int
1343+
prof_open_maps(const char *format, ...)
1344+
{
1345+
int mfd;
1346+
va_list ap;
1347+
char filename[PATH_MAX + 1];
1348+
1349+
va_start(ap, format);
1350+
malloc_vsnprintf(filename, sizeof(filename), format, ap);
1351+
va_end(ap);
1352+
mfd = open(filename, O_RDONLY);
1353+
1354+
return (mfd);
1355+
}
1356+
13411357
static bool
13421358
prof_dump_maps(bool propagate_err)
13431359
{
13441360
bool ret;
13451361
int mfd;
1346-
char filename[PATH_MAX + 1];
13471362

13481363
cassert(config_prof);
13491364
#ifdef __FreeBSD__
1350-
malloc_snprintf(filename, sizeof(filename), "/proc/curproc/map");
1365+
mfd = prof_open_maps("/proc/curproc/map");
13511366
#else
1352-
malloc_snprintf(filename, sizeof(filename), "/proc/%d/maps",
1353-
(int)getpid());
1367+
{
1368+
int pid = getpid();
1369+
1370+
mfd = prof_open_maps("/proc/%d/task/%d/maps", pid, pid);
1371+
if (mfd == -1)
1372+
mfd = prof_open_maps("/proc/%d/maps", pid);
1373+
}
13541374
#endif
1355-
mfd = open(filename, O_RDONLY);
13561375
if (mfd != -1) {
13571376
ssize_t nread;
13581377

0 commit comments

Comments
 (0)