Implement kill_request_handler in spawnd, using domain caps.
[barrelfish] / usr / spawnd / ps.c
index f1e0d1a..50542f7 100644 (file)
 #include <string.h>
 #include <assert.h>
 #include <barrelfish/barrelfish.h>
+#include <collections/hash_table.h>
 #include <vfs/vfs.h>
 
 #include "ps.h"
 
+#define HASH_INDEX_BUCKETS 6151
+static collections_hash_table* domain_table = NULL;
+
 static struct ps_entry *entries[MAX_DOMAINS];
 
 errval_t ps_allocate(struct ps_entry *entry, domainid_t *domainid)
@@ -24,6 +28,7 @@ errval_t ps_allocate(struct ps_entry *entry, domainid_t *domainid)
         if(entries[i] == NULL) {
             entries[i] = entry;
             *domainid = i;
+            entry->domain_id = i;
             return SYS_ERR_OK;
         }
     }
@@ -51,3 +56,48 @@ struct ps_entry *ps_get(domainid_t domain_id)
 
     return entries[domain_id];
 }
+
+errval_t ps_hash_domain(struct ps_entry *entry, struct capref domain_cap)
+{
+    entry->domain_cap = domain_cap;
+
+    if (domain_table == NULL) {
+        collections_hash_create_with_buckets(&domain_table, HASH_INDEX_BUCKETS,
+                                             NULL);
+        if (domain_table == NULL) {
+            return SPAWN_ERR_CREATE_DOMAIN_TABLE;
+        }
+    }
+
+    uint64_t key;
+    errval_t err = domain_cap_hash(entry->domain_cap, &key);
+    if (err_is_fail(err)) {
+        return err;
+    }
+
+    collections_hash_insert(domain_table, key, entry);
+
+    return SYS_ERR_OK;
+}
+
+errval_t ps_release_domain(struct capref domain_cap,
+                           struct ps_entry **ret_entry)
+{
+    assert(ret_entry != NULL);
+
+    uint64_t key;
+    errval_t err = domain_cap_hash(domain_cap, &key);
+    if (err_is_fail(err)) {
+        return err;
+    }
+
+    void *table_entry = collections_hash_find(domain_table, key);
+    if (table_entry == NULL) {
+        return SPAWN_ERR_DOMAIN_TABLE_FIND;
+    }
+    *ret_entry = (struct ps_entry*) table_entry;
+
+    collections_hash_delete(domain_table, key);
+
+    return SYS_ERR_OK;
+}