diff options
| author | the lemons <citrons@mondecitronne.com> | 2023-02-07 15:15:00 -0600 |
|---|---|---|
| committer | the lemons <citrons@mondecitronne.com> | 2023-02-07 15:15:58 -0600 |
| commit | 285025ee086b7631cb102c20300c8da7f2d9a52e (patch) | |
| tree | 199de44aa15d3147eb15f38a42519b2f3ed91f1f /procfs.c | |
| parent | 2f4f1462488a867dddae15802ba7dff94279fb9f (diff) | |
change behavior of jumping between maps
Diffstat (limited to 'procfs.c')
| -rw-r--r-- | procfs.c | 31 |
1 files changed, 27 insertions, 4 deletions
@@ -4,6 +4,7 @@ #include <stdint.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/mman.h> #include <fcntl.h> #include <unistd.h> @@ -27,12 +28,33 @@ ssize_t procfs_maps(pid_t pid, struct procfs_map **maps) { if (!*maps) return -1; while (1) { void *base, *max; - int matches = fscanf(f, "%p-%p", &base, &max); + char prot_str[4]; + int matches = fscanf(f, "%p-%p %4c", &base, &max, prot_str); if (matches == EOF) goto eof; - if (matches < 2) goto err; + if (matches < 3) goto err; + + int prot = 0; + for (int i = 0; i < 4; i++) { + switch (prot_str[i]) { + case 'r': + prot |= PROT_READ; + break; + case 'w': + prot |= PROT_WRITE; + break; + case 'x': + prot |= PROT_EXEC; + break; + default: + break; + } + } + if (prot == 0) prot = PROT_NONE; + int c; while ((c = getc(f)) != '\n') if (c == EOF) goto eof; + n++; if (n > capacity) { capacity <<= 1; @@ -40,8 +62,9 @@ ssize_t procfs_maps(pid_t pid, struct procfs_map **maps) { if (!r) goto err; *maps = r; } - (*maps)[n - 1].base = (uintptr_t) base; - (*maps)[n - 1].max = (uintptr_t) max; + (*maps)[n - 1] = (struct procfs_map) { + (uintptr_t) base, (uintptr_t) max, prot + }; } eof: if (ferror(f)) goto err; |
