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)
{
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) {
return -1;
}

View File

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