add initial System module

This commit is contained in:
josh committed 2016-07-13 21:41:30 -04:00
1 parent 5bcd55ba97
commit 48e82a11a3
3 files changed
+49

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
#include "System.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
long System::page_size;
bool System::init()
{
System::page_size = sysconf(_SC_PAGESIZE);
if ((System::page_size == 0) ||
(System::page_size > (2 * 1024 * 1024)) ||
((System::page_size & (System::page_size - 1)) != 0))
{
printf("Unsupported page size detected: %ld\n", System::page_size);
return false;
}
return true;
}
void * System::alloc_pages(int num)
{
return mmap(
NULL,
num * System::page_size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0);
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef SYSTEM_H
#define SYSTEM_H
class System
{
public:
static bool init();
static long page_size;
static void * alloc_pages(int num);
};
#endif