diff --git a/src/internal.cpp b/src/internal.cpp index d9575d2..2fefc58 100644 --- a/src/internal.cpp +++ b/src/internal.cpp @@ -1,5 +1,27 @@ #include "internal.h" +#include +Impl impl; -Internal internal; +void *getSharedMemory(){ + impl.sharedMemorySize = 8000; + auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644 | IPC_CREAT); + if(id == -1){ + //error + impl.sharedMemorySize = 0; + return nullptr; + } + void *data = shmat(id, nullptr, 0); + if(data == (char*)(-1)){ + //error + impl.sharedMemorySize = 0; + return nullptr; + } + + return data; +} + +int getSharedMemorySize(){ + return impl.sharedMemorySize; +} diff --git a/src/internal.h b/src/internal.h index 65baee5..831ad27 100644 --- a/src/internal.h +++ b/src/internal.h @@ -6,13 +6,14 @@ #include "LayoutVersion.h" #include "GraphicMode.h" #include "Color.h" +#include /** * the Control Registers * @author Julian Hinxlage * @since 0.1.0 */ -struct Registers{ +struct Registers { int layout_version; int trigger_reset; int width_pixels; @@ -34,7 +35,7 @@ struct Registers{ int keyboardBuffer_index_r; }; -struct InterruptEntry{ +struct InterruptEntry { int pid; int signum; }; @@ -42,10 +43,16 @@ struct InterruptEntry{ /** * internal values for the library. */ -struct Internal{ +struct Impl { int sharedMemoryPid; + key_t sharedMemoryKey; + int sharedMemorySize; }; -extern Internal internal; +extern Impl impl; + +void *getSharedMemory(); + +int getSharedMemorySize(); /** * set layout version. diff --git a/src/vkvm.cpp b/src/vkvm.cpp index 45218e4..1b63d02 100644 --- a/src/vkvm.cpp +++ b/src/vkvm.cpp @@ -2,5 +2,7 @@ #include "internal.h" void initialize(int pid) { - internal.sharedMemoryPid = pid; + impl.sharedMemoryPid = pid; + impl.sharedMemoryKey = 892348; + impl.sharedMemorySize = 0; }