X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/df378195faf69652a5982959e2b3477a504c40f2..ba907729e2486aca40fb7e5d1927d3789938fb68:/src/xbt/memory_map.cpp?ds=sidebyside diff --git a/src/xbt/memory_map.cpp b/src/xbt/memory_map.cpp index 7d2888b250..56349c4d4a 100644 --- a/src/xbt/memory_map.cpp +++ b/src/xbt/memory_map.cpp @@ -21,10 +21,7 @@ #include "memory_map.hpp" extern "C" { - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_memory_map, xbt, - "Logging specific to algorithms for memory_map"); - +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_memory_map, xbt, "Logging specific to algorithms for memory_map"); } namespace simgrid { @@ -37,18 +34,17 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* 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"); - xbt_assert(fp, - "Cannot open %s to investigate the memory map of the process.", path); + xbt_assert(fp, "Cannot open %s to investigate the memory map of the process.", path); free(path); - setbuf(fp, NULL); + setbuf(fp, nullptr); std::vector 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) { @@ -57,14 +53,13 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* 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/fields */ 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 */ @@ -74,7 +69,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* 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) + if (tok == nullptr) xbt_abort(); VmMap memreg; @@ -84,8 +79,8 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) 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); @@ -119,7 +114,6 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) if (lfields[1][4] == 'p') memreg.flags |= MAP_PRIVATE; - else if (lfields[1][4] == 's') memreg.flags |= MAP_SHARED; @@ -131,7 +125,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* 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); @@ -139,8 +133,8 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) 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); @@ -159,8 +153,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) /* Create space for a new map region in the region's array and copy the */ /* parsed stuff from the temporal memreg variable */ - XBT_DEBUG("Found region for %s", - !memreg.pathname.empty() ? memreg.pathname.c_str() : "(null)"); + XBT_DEBUG("Found region for %s", !memreg.pathname.empty() ? memreg.pathname.c_str() : "(null)"); ret.push_back(std::move(memreg)); } @@ -169,8 +162,7 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) std::fclose(fp); return ret; #else - /* On FreeBSD, kinfo_getvmmap() could be used but mmap() support is disabled - anyway. */ + /* On FreeBSD, kinfo_getvmmap() could be used but mmap() support is disabled anyway. */ xbt_die("Could not get memory map from process %lli", (long long int) pid); #endif }