diff options
| author | the lemons <citrons@mondecitronne.com> | 2023-02-05 19:06:16 -0600 |
|---|---|---|
| committer | the lemons <citrons@mondecitronne.com> | 2023-02-05 19:06:16 -0600 |
| commit | 3af50b956b8887b64c3c29b30a0008be866b24c4 (patch) | |
| tree | af2a6f736505585192f852342ae988a297024133 /procfs.c | |
initial commit
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; +} |
