add initial System module
This commit is contained in:
parent
5bcd55ba97
commit
48e82a11a3
31
src/core/System.cc
Normal file
31
src/core/System.cc
Normal 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
src/core/System.h
Normal file
12
src/core/System.h
Normal 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
|
@ -2,9 +2,15 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Runtime.h"
|
#include "Runtime.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "System.h"
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
if (!System::init())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Runtime::init(argv[0], APPNAME);
|
Runtime::init(argv[0], APPNAME);
|
||||||
|
|
||||||
std::shared_ptr<Buffer> b = std::make_shared<Buffer>();
|
std::shared_ptr<Buffer> b = std::make_shared<Buffer>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user