Test alloc on several page

This commit is contained in:
Mathieu Maret 2022-09-03 23:41:33 +02:00
parent edcac85b35
commit 509a1fd992
2 changed files with 16 additions and 10 deletions

View File

@ -113,7 +113,7 @@ uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop)
int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr) int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr)
{ {
pr_devel("Checking %p inside %p and %p", addr, as->heapStart, as->heapStart +as->heapSize); pr_devel("Checking %p inside %p and %p\n", addr, as->heapStart, as->heapStart +as->heapSize);
if (addr < as->heapStart || addr >= as->heapStart + as->heapSize) { if (addr < as->heapStart || addr >= as->heapStart + as->heapSize) {
return -1; return -1;
} }

View File

@ -1,4 +1,5 @@
#include "libc.h" #include "libc.h"
#include "stdarg.h"
int func_yolo() int func_yolo()
{ {
@ -26,19 +27,24 @@ int func_suicide()
} }
void *initialHeap = 0; void *initialHeap = 0;
int func_alloc(){ int func_alloc()
{
if (initialHeap == 0) { if (initialHeap == 0) {
initialHeap = brk(0); initialHeap = brk(0);
} }
printf("Testing allocation\n");
int allocSize = 4096 * 2;
void *currentHeap = brk(0); void *currentHeap = brk(0);
if (currentHeap - initialHeap < 4096){ if (currentHeap - initialHeap < allocSize) {
brk(initialHeap + 4096); brk(initialHeap + allocSize);
} }
int *allocatedData = (int *)initialHeap; int *allocatedData = (int *)initialHeap;
for(unsigned int i = 0 ; i < 4096/sizeof(int); i++){ for (unsigned int i = 0; i < allocSize / sizeof(int); i++) {
allocatedData[i] = i; allocatedData[i] = i;
} }
printf("Success\n");
return 0; return 0;
} }