Remove building with NOCRYPTO option
[minix.git] / minix / usr.bin / trace / mem.c
blobe0b67270b8e535cd654577af4be54c6a47fa9586
2 #include "inc.h"
4 /*
5 * Retrieve 'len' bytes from the memory of the traced process 'pid' at address
6 * 'addr' and put the result in the buffer pointed to by 'ptr'. Return 0 on
7 * success, or otherwise -1 with errno set appropriately.
8 */
9 int
10 mem_get_data(pid_t pid, vir_bytes addr, void * ptr, size_t len)
12 struct ptrace_range pr;
14 if (len == 0) return 0;
16 pr.pr_space = TS_DATA;
17 pr.pr_addr = addr;
18 pr.pr_size = len;
19 pr.pr_ptr = ptr;
21 return ptrace(T_GETRANGE, pid, &pr, 0);
25 * Retrieve 'len' bytes from the kernel structure memory of the traced process
26 * 'pid' at offset 'addr' and put the result in the buffer pointed to by 'ptr'.
27 * Return 0 on success, or otherwise -1 with errno set appropriately.
29 int
30 mem_get_user(pid_t pid, vir_bytes addr, void * ptr, size_t len)
32 long data;
33 char *p;
34 size_t off, chunk;
36 if (len == 0) return 0;
38 /* Align access to address. */
39 off = addr & (sizeof(data) - 1);
40 addr -= off;
42 p = ptr;
44 while (len > 0) {
45 errno = 0;
46 data = ptrace(T_GETUSER, pid, (void *)addr, 0);
47 if (errno != 0) return -1;
49 chunk = sizeof(data) - off;
50 if (chunk > len)
51 chunk = len;
53 memcpy(p, (char *)&data + off, chunk);
54 p += chunk;
55 addr += chunk;
56 len -= chunk;
57 off = 0;
60 return 0;