start moving malloc and friends in

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-11 00:00:00 +00:00
parent 975b15b814
commit d7a24ea200
25 changed files with 222 additions and 26 deletions

22
userland/c/malloc.c Normal file
View File

@@ -0,0 +1,22 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#malloc */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
size_t bytes = sizeof(int) * 2;
/* Allocate 2 ints. */
int *is = malloc(bytes);
/* This can happen for example if we ask for too much memory. */
if (is == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
is[0] = 1;
assert(is[0] == 1);
/* Free the allocated memory. */
free(is);
return EXIT_SUCCESS;
}