A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tesh: actually pick the path to python3 that we have
[simgrid.git]
/
src
/
xbt
/
memory_map.cpp
diff --git
a/src/xbt/memory_map.cpp
b/src/xbt/memory_map.cpp
index
0f7cc0f
..
379a22e
100644
(file)
--- a/
src/xbt/memory_map.cpp
+++ b/
src/xbt/memory_map.cpp
@@
-27,6
+27,12
@@
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_memory_map, xbt, "Logging specific to algori
namespace simgrid {
namespace xbt {
namespace simgrid {
namespace xbt {
+/**
+ * \todo This function contains many cases that do not allow for a
+ * recovery. Currently, xbt_abort() is called but we should
+ * much rather die with the specific reason so that it's easier
+ * to find out what's going on.
+ */
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
{
#ifdef __linux__
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
{
#ifdef __linux__
@@
-34,43
+40,48
@@
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
/* to be returned. */
char* path = bprintf("/proc/%i/maps", (int) pid);
FILE *fp = std::fopen(path, "r");
/* to be returned. */
char* path = bprintf("/proc/%i/maps", (int) pid);
FILE *fp = std::fopen(path, "r");
- if
(fp == NULL)
+ if
(fp == nullptr) {
std::perror("fopen failed");
std::perror("fopen failed");
- xbt_assert(fp, "Cannot open %s to investigate the memory map of the process.", path);
+ xbt_die("Cannot open %s to investigate the memory map of the process.", path);
+ }
free(path);
free(path);
- setbuf(fp,
NULL
);
+ setbuf(fp,
nullptr
);
std::vector<VmMap> ret;
/* Read one line at the time, parse it and add it to the memory map to be returned */
ssize_t read; /* Number of bytes readed */
std::vector<VmMap> ret;
/* Read one line at the time, parse it and add it to the memory map to be returned */
ssize_t read; /* Number of bytes readed */
- char* line =
NULL
;
+ char* line =
nullptr
;
std::size_t n = 0; /* Amount of bytes to read by xbt_getline */
while ((read = xbt_getline(&line, &n, fp)) != -1) {
std::size_t n = 0; /* Amount of bytes to read by xbt_getline */
while ((read = xbt_getline(&line, &n, fp)) != -1) {
+ /**
+ * The lines that we read have this format: (This is just an example)
+ * 00602000-00603000 rw-p 00002000 00:28 1837264 <complete-path-to-file>
+ */
//fprintf(stderr,"%s", line);
/* Wipeout the new line character */
line[read - 1] = '\0';
//fprintf(stderr,"%s", line);
/* Wipeout the new line character */
line[read - 1] = '\0';
- /* Tokenize the line using spaces as delimiters and store each token in lfields array. We expect 5 tokens
/
fields */
+ /* Tokenize the line using spaces as delimiters and store each token in lfields array. We expect 5 tokens
for 6
fields */
char* lfields[6];
lfields[0] = strtok(line, " ");
int i;
char* lfields[6];
lfields[0] = strtok(line, " ");
int i;
- for (i = 1; i < 6 && lfields[i - 1] !=
NULL
; i++) {
- lfields[i] = std::strtok(
NULL
, " ");
+ for (i = 1; i < 6 && lfields[i - 1] !=
nullptr
; i++) {
+ lfields[i] = std::strtok(
nullptr
, " ");
}
/* Check to see if we got the expected amount of columns */
if (i < 6)
}
/* Check to see if we got the expected amount of columns */
if (i < 6)
- xbt_
abort(
);
+ xbt_
die("The memory map apparently only supplied less than 6 columns. Recovery impossible."
);
/* Ok we are good enough to try to get the info we need */
/* First get the start and the end address of the map */
char *tok = std::strtok(lfields[0], "-");
/* Ok we are good enough to try to get the info we need */
/* First get the start and the end address of the map */
char *tok = std::strtok(lfields[0], "-");
- if (tok ==
NULL
)
- xbt_
abort(
);
+ if (tok ==
nullptr
)
+ xbt_
die("Start and end address of the map are not concatenated by a hyphen (-). Recovery impossible."
);
VmMap memreg;
char *endptr;
VmMap memreg;
char *endptr;
@@
-79,8
+90,8
@@
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
if (*endptr != '\0')
xbt_abort();
if (*endptr != '\0')
xbt_abort();
- tok = std::strtok(
NULL
, "-");
- if (tok ==
NULL
)
+ tok = std::strtok(
nullptr
, "-");
+ if (tok ==
nullptr
)
xbt_abort();
memreg.end_addr = std::strtoull(tok, &endptr, 16);
xbt_abort();
memreg.end_addr = std::strtoull(tok, &endptr, 16);
@@
-112,9
+123,9
@@
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
if (memreg.prot == 0)
memreg.prot |= PROT_NONE;
if (memreg.prot == 0)
memreg.prot |= PROT_NONE;
- if (lfields[1][
4
] == 'p')
+ if (lfields[1][
3
] == 'p')
memreg.flags |= MAP_PRIVATE;
memreg.flags |= MAP_PRIVATE;
- else
if (lfields[1][4] == 's')
+ else
memreg.flags |= MAP_SHARED;
/* Get the offset value */
memreg.flags |= MAP_SHARED;
/* Get the offset value */
@@
-125,7
+136,7
@@
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
/* Get the device major:minor bytes */
tok = std::strtok(lfields[3], ":");
/* Get the device major:minor bytes */
tok = std::strtok(lfields[3], ":");
- if (tok ==
NULL
)
+ if (tok ==
nullptr
)
xbt_abort();
memreg.dev_major = (char) strtoul(tok, &endptr, 16);
xbt_abort();
memreg.dev_major = (char) strtoul(tok, &endptr, 16);
@@
-133,8
+144,8
@@
XBT_PRIVATE std::vector<VmMap> get_memory_map(pid_t pid)
if (*endptr != '\0')
xbt_abort();
if (*endptr != '\0')
xbt_abort();
- tok = std::strtok(
NULL
, ":");
- if (tok ==
NULL
)
+ tok = std::strtok(
nullptr
, ":");
+ if (tok ==
nullptr
)
xbt_abort();
memreg.dev_minor = (char) std::strtoul(tok, &endptr, 16);
xbt_abort();
memreg.dev_minor = (char) std::strtoul(tok, &endptr, 16);