[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 2/3] kernel2: SHM beim Prozessende schliessen
! kernel2: Alle geoeffneten SHM-Bereiche beim Prozessende schliessen
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/kernel2/include/tasks.h | 3 +++
src/kernel2/src/mm/shm.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h
index c8370f4..37d9714 100644
--- a/src/kernel2/include/tasks.h
+++ b/src/kernel2/include/tasks.h
@@ -84,6 +84,9 @@ typedef struct pm_process {
/// Eine Liste von RPC-Backlinks
list_t* rpcs;
+ /// Eine Liste von geoeffneten SHM-Bereichen
+ list_t* shm;
+
/**
* Eine Liste von Eventhandlern, die beim Loeschen des Prozesses
* aufgerufen werden
diff --git a/src/kernel2/src/mm/shm.c b/src/kernel2/src/mm/shm.c
index d05de0e..b067d91 100644
--- a/src/kernel2/src/mm/shm.c
+++ b/src/kernel2/src/mm/shm.c
@@ -51,6 +51,7 @@ struct shm_desc {
};
struct shm_process {
+ struct shm_desc* shm;
pm_process_t* process;
vaddr_t vaddr;
};
@@ -58,6 +59,8 @@ struct shm_process {
static tree_t* shms = NULL;
static uint32_t shm_last_id = 0;
+static void shm_destroy_task(pm_process_t* process, void* prv);
+
/**
* Initialisiert die SHM-Verwaltung
*/
@@ -126,10 +129,17 @@ void* shm_attach(pm_process_t* process, uint32_t id)
}
shm_proc = calloc(1, sizeof(*shm_proc));
+ shm_proc->shm = shm;
shm_proc->process = process;
shm_proc->vaddr = ret;
list_push(shm->processes, shm_proc);
+ if (process->shm == NULL) {
+ process->shm = list_create();
+ pm_register_on_destroy(process, shm_destroy_task, NULL);
+ }
+ list_push(process->shm, shm_proc);
+
return ret;
}
@@ -150,6 +160,15 @@ void shm_detach(pm_process_t* process, uint32_t id)
return;
}
+ // Aus der SHM-Liste des Prozesses austragen
+ for (i = 0; (shm_proc = list_get_element_at(process->shm, i)); i++) {
+ if (shm_proc->shm == shm) {
+ list_remove(process->shm, i);
+ break;
+ }
+ }
+
+ // Aus der Prozessliste des SHM austragen
for (i = 0; (shm_proc = list_get_element_at(shm->processes, i)); i++) {
if (shm_proc->process == process) {
list_remove(shm->processes, i);
@@ -184,3 +203,21 @@ found:
return;
}
+
+/**
+ * Schliesst alle SHM-Bereiche eines Prozesses
+ */
+static void shm_destroy_task(pm_process_t* process, void* prv)
+{
+ struct shm_process* shm_proc;
+
+ if (process->shm == NULL) {
+ return;
+ }
+
+ while ((shm_proc = list_get_element_at(process->shm, 0))) {
+ shm_detach(process, shm_proc->shm->id);
+ }
+
+ list_destroy(process->shm);
+}
--
1.6.0.2