summaryrefslogtreecommitdiff
path: root/procfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'procfs.c')
-rw-r--r--procfs.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/procfs.c b/procfs.c
index e3bfb2c..2558f03 100644
--- a/procfs.c
+++ b/procfs.c
@@ -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;