aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/user')
-rw-r--r--src/kernel/user/ipc.c78
-rw-r--r--src/kernel/user/nullfs.c4
-rw-r--r--src/kernel/user/pager.c6
-rw-r--r--src/kernel/user/process.c2
4 files changed, 86 insertions, 4 deletions
diff --git a/src/kernel/user/ipc.c b/src/kernel/user/ipc.c
index a8362ea..e565082 100644
--- a/src/kernel/user/ipc.c
+++ b/src/kernel/user/ipc.c
@@ -227,6 +227,84 @@ void channel_dispose(fs_node_t *n) {
free(c);
}
+// ---- ------ ------
+// ---- Shared memory
+// ---- ------ ------
+
+bool shm_open(fs_node_ptr n, int mode);
+void shm_close(fs_handle_t *h);
+bool shm_stat(fs_node_ptr n, stat_t *st);
+void shm_dispose(fs_node_t *n);
+
+fs_node_ops_t shm_ops = {
+ .open = shm_open,
+ .read = fs_read_from_pager,
+ .write = fs_write_to_pager,
+ .readdir = 0,
+ .poll = 0,
+ .close = shm_close,
+ .stat = shm_stat,
+ .ioctl = 0,
+ .walk = 0,
+ .delete = 0,
+ .move = 0,
+ .create = 0,
+ .dispose = shm_dispose,
+};
+
+fs_handle_t* make_shm(size_t size) {
+ fs_node_t *n = 0;
+ fs_handle_t *h = 0;
+
+ n = (fs_node_t*)malloc(sizeof(fs_node_t));
+ if (n == 0) goto error;
+ memset(n, 0, sizeof(fs_node_t));
+
+ h = (fs_handle_t*)malloc(sizeof(fs_handle_t));
+ if (h == 0) goto error;
+
+ n->pager = new_swap_pager(size, false);
+ if (n->pager == 0) goto error;
+
+ n->refs = 1;
+ n->lock = MUTEX_UNLOCKED;
+ n->ops = &shm_ops;
+ n->data = 0;
+
+ h->fs = 0;
+ h->node = n;
+ h->refs = 1;
+ h->mode = FM_READ | FM_WRITE | FM_MMAP;
+
+ return h;
+
+error:
+ if (n && n->pager) delete_pager(n->pager);
+ if (n) free(n);
+ if (h) free(h);
+ return 0;
+}
+
+bool shm_open(fs_node_ptr n, int mode) {
+ int ok_modes = FM_READ | FM_WRITE | FM_MMAP;
+ if (mode & ~ok_modes) return false;
+
+ return true;
+}
+
+void shm_close(fs_handle_t *h) {
+ // nothing to do
+}
+
+bool shm_stat(fs_node_ptr n, stat_t *st) {
+ // TODO
+ return false;
+}
+
+void shm_dispose(fs_node_t *n) {
+ delete_pager(n->pager);
+}
+
// ---- ------
// ---- Tokens
// ---- ------
diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c
index d4f345f..636d7fa 100644
--- a/src/kernel/user/nullfs.c
+++ b/src/kernel/user/nullfs.c
@@ -204,7 +204,7 @@ bool nullfs_add_ram_file(fs_t *fs, const char* name, const char* data, size_t in
nullfs_file_t *f = (nullfs_file_t*)malloc(sizeof(nullfs_file_t));
if (f == 0) return false;
- p = new_swap_pager(init_sz);
+ p = new_swap_pager(init_sz, true);
if (p == 0) goto error;
f->ok_modes = ok_modes & (FM_MMAP | FM_TRUNC | FM_READ | FM_WRITE);
@@ -339,7 +339,7 @@ bool nullfs_d_create(fs_node_ptr n, const char* file, int type) {
nullfs_file_t *f = (nullfs_file_t*)malloc(sizeof(nullfs_file_t));
if (f == 0) goto f_error;
- p = new_swap_pager(0);
+ p = new_swap_pager(0, true);
if (p == 0) goto f_error;
f->ok_modes = FM_READ | FM_WRITE | FM_TRUNC | FM_APPEND;
diff --git a/src/kernel/user/pager.c b/src/kernel/user/pager.c
index 79f293b..b9233b0 100644
--- a/src/kernel/user/pager.c
+++ b/src/kernel/user/pager.c
@@ -26,7 +26,7 @@ pager_ops_t swap_pager_ops = {
.resize = swap_pager_resize,
};
-pager_t *new_swap_pager(size_t size) {
+pager_t *new_swap_pager(size_t size, bool allow_resize) {
pager_t *p = (pager_t*)malloc(sizeof(pager_t));
if (p == 0) return 0;
@@ -38,6 +38,8 @@ pager_t *new_swap_pager(size_t size) {
p->lock = MUTEX_UNLOCKED;
p->maps = 0;
+ p->swap_pager.allow_resize = allow_resize;
+
return p;
error:
@@ -86,6 +88,8 @@ void swap_page_release(pager_t *p, size_t offset, size_t len) {
}
bool swap_pager_resize(pager_t *p, size_t new_size) {
+ if (!p->swap_pager.allow_resize) return false;
+
// later : remove unused pages in swap file
return true;
diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c
index 4d79327..85530ca 100644
--- a/src/kernel/user/process.c
+++ b/src/kernel/user/process.c
@@ -500,7 +500,7 @@ bool mmap(process_t *proc, void* addr, size_t size, int mode) {
r->size = size;
r->own_pager = true;
- r->pager = new_swap_pager(size);
+ r->pager = new_swap_pager(size, false);
if (r->pager == 0) goto error;
r->offset = 0;