diff options
Diffstat (limited to 'procfs.c')
| -rw-r--r-- | procfs.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/procfs.c b/procfs.c new file mode 100644 index 0000000..63aef3a --- /dev/null +++ b/procfs.c @@ -0,0 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stddef.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "procfs.h" + +int procfs_open(pid_t pid) { + char path[2048]; + sprintf(path, "/proc/%d/mem", pid); + return open(path, O_RDWR); +} + +int read_page(int fd, uintptr_t index, uint8_t *data) { + if (lseek(fd, index * PAGE_SIZE, SEEK_SET) == -1) + return -1; + size_t n = 0; + while (n < PAGE_SIZE) { + ssize_t result = read(fd, data + n, PAGE_SIZE - n); + if (result == -1) return -1; + n += result; + } + return 0; +} |
