diff options
| author | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
|---|---|---|
| committer | Galen Sagarin <gps5307@rit.edu> | 2025-04-29 14:18:40 -0400 |
| commit | ae2cdd83ba4a0cae161db0b29031d5591005fa34 (patch) | |
| tree | 82fbdfcbb1fe4e3b5e232db195c8c331d69489fd /user/heap.c | |
| parent | Started writing fat.c (diff) | |
| parent | fs header changes (diff) | |
| download | comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.gz comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.tar.bz2 comus-ae2cdd83ba4a0cae161db0b29031d5591005fa34.zip | |
Merge branch 'main' of https://github.com/kenshineto/kern into fat32
Merging main into here
Diffstat (limited to '')
| -rw-r--r-- | user/heap.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/user/heap.c b/user/heap.c new file mode 100644 index 0000000..ffa107b --- /dev/null +++ b/user/heap.c @@ -0,0 +1,46 @@ + +#include <unistd.h> +#include <string.h> +#include <stdio.h> + +#define PAGE_SIZE 4096 + +int main(void) +{ + void *start, *brk; + + start = sbrk(0); + printf("heap start: %p\n", start); + + // test extending + if (sbrk(PAGE_SIZE) == NULL) { + fprintf(stderr, "failed to extend break\n"); + return 1; + } + + brk = sbrk(0); + printf("new break: %p\n", brk); + + // test reextending + if (sbrk(PAGE_SIZE) == NULL) { + fprintf(stderr, "failed to extend break\n"); + return 1; + } + + brk = sbrk(0); + printf("new new break: %p\n", brk); + + // test shrinking + if (sbrk(-PAGE_SIZE) == NULL) { + fprintf(stderr, "failed to shrink break\n"); + return 1; + } + + brk = sbrk(0); + printf("new new new break: %p\n", brk); + + // test write + memset(start, 1, PAGE_SIZE); + + return 0; +} |