[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 5/7] kernel2: syscall_shm_size



+ kernel2: Ein Syscall, um herauszufinden, wie groß ein SHM-Puffer
  überhaupt ist (wäre eventuell ganz geschickt bevor man ihn benutzt)

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/include/syscallno.h                  |  1 +
 src/kernel2/include/syscall.h            |  3 +++
 src/kernel2/src/syscall.c                |  1 +
 src/kernel2/src/syscalls/shm.c           |  5 +++++
 src/modules/lib/syscalls/shared_memory.c | 16 ++++++++++++++++
 5 files changed, 26 insertions(+)

diff --git a/src/include/syscallno.h b/src/include/syscallno.h
index d4794f5..4ab0e72 100644
--- a/src/include/syscallno.h
+++ b/src/include/syscallno.h
@@ -41,6 +41,7 @@
 #define SYSCALL_SHM_CREATE 63
 #define SYSCALL_SHM_ATTACH 64
 #define SYSCALL_SHM_DETACH 65
+#define SYSCALL_SHM_SIZE 67
 
 #define SYSCALL_PM_CREATE_PROCESS 3
 #define SYSCALL_PM_INIT_PAGE 13
diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h
index e2b9148..ef60996 100644
--- a/src/kernel2/include/syscall.h
+++ b/src/kernel2/include/syscall.h
@@ -178,6 +178,9 @@ void* syscall_shm_attach(uint32_t id);
 /// Shared Memory schliessen
 void syscall_shm_detach(uint32_t id);
 
+/// Größe eines Shared Memory zurückgeben
+int32_t syscall_shm_size(uint32_t id);
+
 /// Einen Timer anlegen
 void syscall_add_timer(uint32_t timer_id, uint32_t usec);
 
diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c
index 0cee76b..2102bc2 100644
--- a/src/kernel2/src/syscall.c
+++ b/src/kernel2/src/syscall.c
@@ -108,6 +108,7 @@ void syscall_init()
     syscall_register(SYSCALL_SHM_CREATE, &syscall_shm_create, 1);
     syscall_register(SYSCALL_SHM_ATTACH, &syscall_shm_attach, 1);
     syscall_register(SYSCALL_SHM_DETACH, &syscall_shm_detach, 1);
+    syscall_register(SYSCALL_SHM_SIZE, &syscall_shm_size, 1);
 
 #if CONFIG_ARCH == ARCH_I386
     syscall_register(SYSCALL_VM86, &syscall_vm86_old, 2);
diff --git a/src/kernel2/src/syscalls/shm.c b/src/kernel2/src/syscalls/shm.c
index 0892622..c86cf46 100644
--- a/src/kernel2/src/syscalls/shm.c
+++ b/src/kernel2/src/syscalls/shm.c
@@ -70,3 +70,8 @@ void syscall_shm_detach(uint32_t id)
     shm_detach(current_process, id);
 }
 
+/// Größe eines Shared Memory zurückgeben
+int32_t syscall_shm_size(uint32_t id)
+{
+    return shm_size(id);
+}
diff --git a/src/modules/lib/syscalls/shared_memory.c b/src/modules/lib/syscalls/shared_memory.c
index dcf99f4..6c1609e 100644
--- a/src/modules/lib/syscalls/shared_memory.c
+++ b/src/modules/lib/syscalls/shared_memory.c
@@ -14,6 +14,7 @@ uint32_t create_shared_memory(uint32_t size)
 
     return id;
 }
+
 void *open_shared_memory(uint32_t id)
 {
     vaddr_t addr;
@@ -27,6 +28,21 @@ void *open_shared_memory(uint32_t id)
 
     return addr;
 }
+
+ssize_t shared_memory_size(uint32_t id)
+{
+    int32_t size;
+
+    asm(
+        "pushl %2;"
+        "mov %1, %%eax;"
+        "int $0x30;"
+        "add $0x4, %%esp;"
+    : "=a" (size) : "i" (SYSCALL_SHM_SIZE), "r" (id));
+
+    return size;
+}
+
 void close_shared_memory(uint32_t id)
 {
     asm(
-- 
2.1.4