+ getSharedMemory

This commit is contained in:
Julian Hinxlage 2019-11-04 23:17:15 +01:00
parent bc28f2819b
commit 3d8bf74fbf
3 changed files with 37 additions and 6 deletions

View File

@ -1,5 +1,27 @@
#include "internal.h" #include "internal.h"
#include <sys/shm.h>
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;
}

View File

@ -6,6 +6,7 @@
#include "LayoutVersion.h" #include "LayoutVersion.h"
#include "GraphicMode.h" #include "GraphicMode.h"
#include "Color.h" #include "Color.h"
#include <sys/types.h>
/** /**
* the Control Registers * the Control Registers
@ -42,10 +43,16 @@ struct InterruptEntry{
/** /**
* internal values for the library. * internal values for the library.
*/ */
struct Internal{ struct Impl {
int sharedMemoryPid; int sharedMemoryPid;
key_t sharedMemoryKey;
int sharedMemorySize;
}; };
extern Internal internal; extern Impl impl;
void *getSharedMemory();
int getSharedMemorySize();
/** /**
* set layout version. * set layout version.

View File

@ -2,5 +2,7 @@
#include "internal.h" #include "internal.h"
void initialize(int pid) { void initialize(int pid) {
internal.sharedMemoryPid = pid; impl.sharedMemoryPid = pid;
impl.sharedMemoryKey = 892348;
impl.sharedMemorySize = 0;
} }