Test alloc on several page

master
Mathieu Maret 1 month ago
parent edcac85b35
commit 509a1fd992
  1. 2
      core/uaddrspace.c
  2. 24
      userspace/main_user.c

@ -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;
}

@ -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;
}

Loading…
Cancel
Save