diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-30 20:24:59 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-31 15:18:45 +0100 |
commit | aad76968cd5934ee17f36cd8e817e86ae952b533 (patch) | |
tree | 40eefffb52e8ed3c75747457980630facef783dd | |
parent | 8b710ef000c383f3476245b27bacf034532d9786 (diff) | |
download | busybox-w32-aad76968cd5934ee17f36cd8e817e86ae952b533.tar.gz busybox-w32-aad76968cd5934ee17f36cd8e817e86ae952b533.tar.bz2 busybox-w32-aad76968cd5934ee17f36cd8e817e86ae952b533.zip |
pmap: make 32-bit version work better on 64-bit kernels
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 7 | ||||
-rw-r--r-- | libbb/procps.c | 8 | ||||
-rw-r--r-- | procps/pmap.c | 8 |
3 files changed, 17 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index daa96728b..d2563999a 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1828,7 +1828,12 @@ struct smaprec { | |||
1828 | unsigned long stack; | 1828 | unsigned long stack; |
1829 | unsigned long smap_pss, smap_swap; | 1829 | unsigned long smap_pss, smap_swap; |
1830 | unsigned long smap_size; | 1830 | unsigned long smap_size; |
1831 | unsigned long smap_start; | 1831 | // For mixed 32/64 userspace, 32-bit pmap still needs |
1832 | // 64-bit field here to correctly show 64-bit processes: | ||
1833 | unsigned long long smap_start; | ||
1834 | // (strictly speaking, other fields need to be wider too, | ||
1835 | // but they are in kbytes, not bytes, and they hold sizes, | ||
1836 | // not start addresses, sizes tend to be less than 4 terabytes) | ||
1832 | char smap_mode[5]; | 1837 | char smap_mode[5]; |
1833 | char *smap_name; | 1838 | char *smap_name; |
1834 | }; | 1839 | }; |
diff --git a/libbb/procps.c b/libbb/procps.c index 9d8a921df..af3ad86ff 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -120,11 +120,11 @@ void FAST_FUNC free_procps_scan(procps_status_t* sp) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP | 122 | #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP |
123 | static unsigned long fast_strtoul_16(char **endptr) | 123 | static unsigned long long fast_strtoull_16(char **endptr) |
124 | { | 124 | { |
125 | unsigned char c; | 125 | unsigned char c; |
126 | char *str = *endptr; | 126 | char *str = *endptr; |
127 | unsigned long n = 0; | 127 | unsigned long long n = 0; |
128 | 128 | ||
129 | /* Need to stop on both ' ' and '\n' */ | 129 | /* Need to stop on both ' ' and '\n' */ |
130 | while ((c = *str++) > ' ') { | 130 | while ((c = *str++) > ' ') { |
@@ -238,8 +238,8 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, | |||
238 | 238 | ||
239 | *tp = ' '; | 239 | *tp = ' '; |
240 | tp = buf; | 240 | tp = buf; |
241 | currec.smap_start = fast_strtoul_16(&tp); | 241 | currec.smap_start = fast_strtoull_16(&tp); |
242 | currec.smap_size = (fast_strtoul_16(&tp) - currec.smap_start) >> 10; | 242 | currec.smap_size = (fast_strtoull_16(&tp) - currec.smap_start) >> 10; |
243 | 243 | ||
244 | strncpy(currec.smap_mode, tp, sizeof(currec.smap_mode)-1); | 244 | strncpy(currec.smap_mode, tp, sizeof(currec.smap_mode)-1); |
245 | 245 | ||
diff --git a/procps/pmap.c b/procps/pmap.c index c8fa0d280..9e541c707 100644 --- a/procps/pmap.c +++ b/procps/pmap.c | |||
@@ -37,6 +37,12 @@ | |||
37 | # define DASHES "--------" | 37 | # define DASHES "--------" |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #if ULLONG_MAX == 0xffffffff | ||
41 | # define AFMTLL "8" | ||
42 | #else | ||
43 | # define AFMTLL "16" | ||
44 | #endif | ||
45 | |||
40 | enum { | 46 | enum { |
41 | OPT_x = 1 << 0, | 47 | OPT_x = 1 << 0, |
42 | OPT_q = 1 << 1, | 48 | OPT_q = 1 << 1, |
@@ -46,7 +52,7 @@ static void print_smaprec(struct smaprec *currec, void *data) | |||
46 | { | 52 | { |
47 | unsigned opt = (uintptr_t)data; | 53 | unsigned opt = (uintptr_t)data; |
48 | 54 | ||
49 | printf("%0" AFMT "lx ", currec->smap_start); | 55 | printf("%0" AFMTLL "llx ", currec->smap_start); |
50 | 56 | ||
51 | if (opt & OPT_x) | 57 | if (opt & OPT_x) |
52 | printf("%7lu %7lu %7lu %7lu ", | 58 | printf("%7lu %7lu %7lu %7lu ", |