Skip to content

Capability/kobject modifications for comments #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions kernel/generic/include/cap/cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
#define KERN_CAP_H_

#include <abi/cap.h>
#include <typedefs.h>
#include <adt/list.h>
#include <adt/hash.h>
#include <adt/hash_table.h>
#include <adt/hash.h>
#include <adt/list.h>
#include <atomic.h>
#include <lib/ra.h>
#include <lib/refcount.h>
#include <synch/mutex.h>
#include <atomic.h>
#include <typedefs.h>

typedef enum {
CAP_STATE_FREE,
Expand All @@ -58,15 +59,10 @@ typedef enum {
KOBJECT_TYPE_MAX
} kobject_type_t;

struct task;

struct call;
struct irq;
struct phone;
struct waitq;
struct kobject;

typedef struct kobject_ops {
void (*destroy)(void *);
void (*destroy)(struct kobject *);
} kobject_ops_t;

extern kobject_ops_t *kobject_ops[];
Expand All @@ -75,24 +71,16 @@ extern kobject_ops_t *kobject_ops[];

/*
* Everything in kobject_t except for the atomic reference count, the capability
* list and its lock is imutable.
* list and its lock is immutable.
*/
typedef struct kobject {
kobject_type_t type;
atomic_size_t refcnt;
atomic_refcount_t refcnt;

/** Mutex protecting caps_list */
mutex_t caps_list_lock;
/** List of published capabilities associated with the kobject */
list_t caps_list;

union {
void *raw;
struct call *call;
struct irq *irq;
struct phone *phone;
struct waitq *waitq;
};
} kobject_t;

/*
Expand Down Expand Up @@ -128,7 +116,8 @@ typedef struct cap_info {
extern void caps_init(void);
extern errno_t caps_task_alloc(struct task *);
extern void caps_task_free(struct task *);
extern void caps_task_init(struct task *);
extern void caps_task_clear(struct task *task);
extern errno_t caps_task_init(struct task *);
extern bool caps_apply_to_kobject_type(struct task *, kobject_type_t,
bool (*)(cap_t *, void *), void *);

Expand All @@ -138,9 +127,7 @@ extern kobject_t *cap_unpublish(struct task *, cap_handle_t, kobject_type_t);
extern void cap_revoke(kobject_t *);
extern void cap_free(struct task *, cap_handle_t);

extern kobject_t *kobject_alloc(unsigned int);
extern void kobject_free(kobject_t *);
extern void kobject_initialize(kobject_t *, kobject_type_t, void *);
extern void kobject_initialize(kobject_t *, kobject_type_t);
extern kobject_t *kobject_get(struct task *, cap_handle_t, kobject_type_t);
extern void kobject_add_ref(kobject_t *);
extern void kobject_put(kobject_t *);
Expand Down
2 changes: 0 additions & 2 deletions kernel/generic/include/ddi/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ typedef struct irq {
IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
extern hash_table_t irq_uspace_hash_table;

extern slab_cache_t *irq_cache;

extern inr_t last_inr;

extern void irq_init(size_t, size_t);
Expand Down
21 changes: 19 additions & 2 deletions kernel/generic/include/ipc/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct phone {
atomic_size_t active_calls;
/** User-defined label */
sysarg_t label;
kobject_t *kobject;
kobject_t kobject;
} phone_t;

typedef struct answerbox {
Expand Down Expand Up @@ -107,7 +107,7 @@ typedef struct answerbox {
} answerbox_t;

typedef struct call {
kobject_t *kobject;
kobject_t kobject;

/**
* Task link.
Expand Down Expand Up @@ -168,11 +168,28 @@ typedef struct call {
} call_t;

extern slab_cache_t *phone_cache;
extern slab_cache_t *irq_cache;

extern answerbox_t *ipc_box_0;

extern kobject_ops_t call_kobject_ops;

static inline phone_t *phone_from_kobject(kobject_t *kobject)
{
if (kobject)
return ((void *) kobject) - offsetof(phone_t, kobject);
else
return NULL;
}

static inline call_t *call_from_kobject(kobject_t *kobject)
{
if (kobject)
return ((void *) kobject) - offsetof(call_t, kobject);
else
return NULL;
}

extern void ipc_init(void);

extern call_t *ipc_call_alloc(void);
Expand Down
14 changes: 14 additions & 0 deletions kernel/generic/include/ipc/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@

extern kobject_ops_t irq_kobject_ops;

typedef struct {
kobject_t kobject;
irq_t irq;
} irq_kobject_t;

static inline irq_t *irq_from_kobject(kobject_t *kobject)
{
if (kobject) {
return &((irq_kobject_t *) kobject)->irq;
} else {
return NULL;
}
}

extern irq_ownership_t ipc_irq_top_half_claim(irq_t *);
extern void ipc_irq_top_half_handler(irq_t *);

Expand Down
2 changes: 0 additions & 2 deletions kernel/generic/include/synch/syswaitq.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ extern kobject_ops_t waitq_kobject_ops;

extern void sys_waitq_init(void);

extern void sys_waitq_task_cleanup(void);

extern sys_errno_t sys_waitq_create(uspace_ptr_cap_waitq_handle_t);
extern sys_errno_t sys_waitq_sleep(cap_waitq_handle_t, uint32_t, unsigned int);
extern sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t);
Expand Down
Loading