I'm trying to implement ownmalloc()
by calling original malloc()
only once at beginning of the code.
Using this memory returned by original malloc()
, each ownmalloc()
call from user program uses this memory for allocation.
There are 2 lists maintained allocated and unallocated.
ownfree()
function removes the allocated memory and adds back to unallocated blocks, orders them and makes the contiguous address blocks as a single block
I have two questions:
How can I stop user from using unauthorized memory at run time, e.g. user asked 10 blocks and using 13 blocks to write the data.
ownmalloc()
calls a function(say x) which in turn calls originalmalloc()
and takes block of memory which will be used byownmalloc()
multiple times. How can I make sure thatownmalloc()
calls this functionx()
only once (during the first call) and at later calls, function call tox()
shouldn't be done.
I tried it with this approach, but its not working in c
typedef struct mem{
int sz;
struct mem *next;
}node;
node *block;
static bool init=false;
void* x(){
//call to original malloc
}
void* ownmalloc(size){
if(!init){
block=x();
init=true;
}
}
Whenever I try to make call to this ownmalloc()
x()
function is being called every time. How do I make it call only once?