basic memory functions
This commit is contained in:
1 parent
79bc676f49
commit
edc5325a33
23 files changed
+145
-9
No files matched your search
@@ -0,0 +1,37 @@
|
||||
// this code is licenced under Wrathmark licence
|
||||
// © 2026 wullie wulliestudio.com
|
||||
// please see attached licence for full usage and rights
|
||||
|
||||
#include "stdWullie/memory/brk.h"
|
||||
#include "stdWullie/exit.h"
|
||||
#include "LocalHeader.h"
|
||||
|
||||
int brk(void *address){
|
||||
|
||||
long result = syscall1(SYS_brk, (long)address);
|
||||
if((void*)result == address){
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *sbrk(intptr_t incrament){
|
||||
|
||||
// gets the last break point and checks whether we just wanted that or do something else
|
||||
void *prevBrk = (void *)syscall1(SYS_brk, 0);
|
||||
if(incrament == 0){
|
||||
return prevBrk;
|
||||
}
|
||||
|
||||
// something else
|
||||
void *newBrk = (char *)prevBrk + incrament;
|
||||
|
||||
long result = syscall1(SYS_brk, (long)newBrk);
|
||||
|
||||
if((void *)result != newBrk){
|
||||
safeError("FAULT IN ALLOCATING NEW BREAK");
|
||||
}
|
||||
|
||||
// pointer to the start of the new memory
|
||||
return prevBrk;
|
||||
}
|
||||
Reference in new issue
Block a user