mmap anonymous: configurable size

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-11 00:00:03 +00:00
parent b1767533af
commit 915b04a76e
5 changed files with 46 additions and 12 deletions

18
userland/c/malloc_max.c Normal file
View File

@@ -0,0 +1,18 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#malloc-maximum-size */
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *ptr = NULL;
size_t size = 1;
while (1) {
printf("0x%zx\n", size);
ptr = realloc(ptr, size);
if (ptr == NULL) {
break;
} else {
size <<= 1;
}
}
}