libclod
C library for interacting with NBTs, region files, LOD data and other things.
Loading...
Searching...
No Matches
experiments.old.c
1#include <sched.h>
2#include <stdint.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7
8void *copy_stack(void *dst) {
9 pid_t tid = gettid();
10 char buff[256];
11 snprintf(buff, sizeof(buff), "/proc/self/task/%d/maps", tid);
12 FILE *file = fopen(buff, "r");
13 if (!file) file = fopen("/proc/self/maps", "r");
14 if (!file) return nullptr;
15
16 uintptr_t stack_start = 0, stack_end = 0;
17
18 while (fgets(buff, sizeof(buff), file)) {
19 if (strstr(buff, "[stack]")) {
20 char *end;
21 stack_start = strtoul(buff, &end, 16);
22 stack_end = strtoul(end + 1, &end, 16);
23 break;
24 }
25 }
26
27 fclose(file);
28
29 memcpy(dst, (void*)stack_start, stack_end - stack_start);
30 return (void*)stack_end;
31}
Sized string helpers.
Definition file.c:13