PatchworkOS  28a9544
A non-POSIX operating system.
Loading...
Searching...
No Matches
Shared Memory

Shared Memory. More...

Data Structures

struct  shmem_object_t
 Represents a shared memory object. More...
 

Functions

static void shmem_object_free (shmem_object_t *shmem)
 
static shmem_object_tshmem_object_new (void)
 
static void shmem_vmm_callback (void *private)
 
static void * shmem_object_allocate_pages (shmem_object_t *shmem, uint64_t pageAmount, space_t *space, void *address, pml_flags_t flags)
 
static uint64_t shmem_open (file_t *file)
 
static void shmem_close (file_t *file)
 
static void * shmem_mmap (file_t *file, void *address, uint64_t length, uint64_t *offset, pml_flags_t flags)
 
static uint64_t shmem_init (void)
 
static void shmem_deinit (void)
 

Variables

static dentry_tshmemDir = NULL
 
static dentry_tnewFile = NULL
 
static file_ops_t fileOps
 

Detailed Description

Shared Memory.

Shared memory is exposed in the /dev/shmem directory. Shared memory allows multiple processes to share a section of memory for inter-process communication (IPC).

Creating Shared Memory

Shared memory objects are created using the /dev/shmem/new file. Opening this file using open() will create a new anonymous shared memory object and return a file descriptor to it.

Using Shared Memory

Shared memory objects can be mapped to the current process's address space using the mmap() system call. The first call to mmap() will decide the size of the shared memory object. Subsequent calls to mmap() will map the existing shared memory object.

Function Documentation

◆ shmem_close()

static void shmem_close ( file_t file)
static

Definition at line 157 of file shmem.c.

References DEREF, file, NULL, and dentry_t::private.

◆ shmem_deinit()

static void shmem_deinit ( void  )
static

Definition at line 249 of file shmem.c.

References DEREF, newFile, NULL, and shmemDir.

Referenced by _module_procedure().

◆ shmem_init()

static uint64_t shmem_init ( void  )
static

Definition at line 229 of file shmem.c.

References DEREF, ERR, fileOps, LOG_ERR, newFile, NULL, shmemDir, sysfs_dir_new(), and sysfs_file_new().

Referenced by _module_procedure().

◆ shmem_mmap()

◆ shmem_object_allocate_pages()

static void * shmem_object_allocate_pages ( shmem_object_t shmem,
uint64_t  pageAmount,
space_t space,
void *  address,
pml_flags_t  flags 
)
static

◆ shmem_object_free()

static void shmem_object_free ( shmem_object_t shmem)
static

Definition at line 54 of file shmem.c.

References assert, free(), NULL, shmem_object_t::pageAmount, shmem_object_t::pages, and pmm_free().

Referenced by shmem_object_new().

◆ shmem_object_new()

static shmem_object_t * shmem_object_new ( void  )
static

◆ shmem_open()

static uint64_t shmem_open ( file_t file)
static

Definition at line 145 of file shmem.c.

References ERR, file, NULL, dentry_t::private, and shmem_object_new().

◆ shmem_vmm_callback()

static void shmem_vmm_callback ( void *  private)
static

Definition at line 89 of file shmem.c.

References DEREF, and NULL.

Referenced by shmem_mmap(), and shmem_object_allocate_pages().

Variable Documentation

◆ fileOps

file_ops_t fileOps
static
Initial value:
= {
.open = shmem_open,
.close = shmem_close,
.mmap = shmem_mmap,
}
static void shmem_close(file_t *file)
Definition shmem.c:157
static uint64_t shmem_open(file_t *file)
Definition shmem.c:145
static void * shmem_mmap(file_t *file, void *address, uint64_t length, uint64_t *offset, pml_flags_t flags)
Definition shmem.c:168

Definition at line 223 of file shmem.c.

Referenced by shmem_init().

◆ newFile

dentry_t* newFile = NULL
static

Definition at line 52 of file shmem.c.

Referenced by shmem_deinit(), and shmem_init().

◆ shmemDir

dentry_t* shmemDir = NULL
static

Definition at line 51 of file shmem.c.

Referenced by shmem_deinit(), and shmem_init().