Created
July 14, 2017 17:35
-
-
Save larytet/643d4a2b932b3d133f6dfca4a4ee8b60 to your computer and use it in GitHub Desktop.
Memory allocation in the kernel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void *rvmalloc(unsigned long size) | |
{ | |
void *mem; | |
unsigned long adr; | |
size = PAGE_ALIGN(size); | |
mem = vzalloc(size); //syscalls_trace_buffer;//vmalloc(size); | |
# if (SHM_RESERVE_PAGES > 0) | |
if (mem) { | |
// memset(mem, 0, size); vzalloc() will zero the memory | |
adr = (unsigned long) mem; | |
while (size > 0) { | |
SetPageReserved(vmalloc_to_page((void *)adr)); | |
adr += PAGE_SIZE; | |
size -= PAGE_SIZE; | |
} | |
} | |
# endif | |
return mem; | |
} | |
static void rvfree(void * mem, unsigned long size) | |
{ | |
unsigned long adr; | |
if (mem) { | |
# if (SHM_RESERVE_PAGES > 0) | |
adr = (unsigned long) mem; | |
while ((long) size > 0) { | |
ClearPageReserved(vmalloc_to_page((void *)adr)); | |
adr += PAGE_SIZE; | |
size -= PAGE_SIZE; | |
} | |
#endif | |
vfree(mem); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment