+ 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,13 +6,14 @@
#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
* @author Julian Hinxlage * @author Julian Hinxlage
* @since 0.1.0 * @since 0.1.0
*/ */
struct Registers{ struct Registers {
int layout_version; int layout_version;
int trigger_reset; int trigger_reset;
int width_pixels; int width_pixels;
@ -34,7 +35,7 @@ struct Registers{
int keyboardBuffer_index_r; int keyboardBuffer_index_r;
}; };
struct InterruptEntry{ struct InterruptEntry {
int pid; int pid;
int signum; int signum;
}; };
@ -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;
} }