From 48e82a11a3ee34c80f765ab5b195574fdda1e787 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 13 Jul 2016 21:41:30 -0400 Subject: [PATCH] add initial System module --- src/core/System.cc | 31 +++++++++++++++++++++++++++++++ src/core/System.h | 12 ++++++++++++ src/jes.cc | 6 ++++++ 3 files changed, 49 insertions(+) create mode 100644 src/core/System.cc create mode 100644 src/core/System.h diff --git a/src/core/System.cc b/src/core/System.cc new file mode 100644 index 0000000..a4e6660 --- /dev/null +++ b/src/core/System.cc @@ -0,0 +1,31 @@ +#include "System.h" +#include +#include +#include + +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); +} diff --git a/src/core/System.h b/src/core/System.h new file mode 100644 index 0000000..b0727b8 --- /dev/null +++ b/src/core/System.h @@ -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 diff --git a/src/jes.cc b/src/jes.cc index 2160bdc..b8dd61f 100644 --- a/src/jes.cc +++ b/src/jes.cc @@ -2,9 +2,15 @@ #include "Window.h" #include "Runtime.h" #include +#include "System.h" int main(int argc, char * argv[]) { + if (!System::init()) + { + return 1; + } + Runtime::init(argv[0], APPNAME); std::shared_ptr b = std::make_shared();