Skip to content

Instantly share code, notes, and snippets.

@larytet
Created July 14, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larytet/643d4a2b932b3d133f6dfca4a4ee8b60 to your computer and use it in GitHub Desktop.
Save larytet/643d4a2b932b3d133f6dfca4a4ee8b60 to your computer and use it in GitHub Desktop.
Memory allocation in the kernel
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