kernel: add header files
This commit is contained in:
65
include/kernel/handle.h
Normal file
65
include/kernel/handle.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef KERNEL_HANDLE_H_
|
||||
#define KERNEL_HANDLE_H_
|
||||
|
||||
#include <kernel/bitmap.h>
|
||||
#include <mango/status.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* subtract 32 bytes to account for the handle bitmap */
|
||||
#define HANDLES_PER_TABLE ((4096 - 32) / sizeof(struct handle))
|
||||
#define REFS_PER_TABLE ((4096 - 64) / sizeof(struct handle_table *))
|
||||
|
||||
typedef uint32_t kern_handle_t;
|
||||
|
||||
typedef uintptr_t handle_flags_t;
|
||||
|
||||
struct task;
|
||||
struct object;
|
||||
struct handle_list;
|
||||
|
||||
struct handle {
|
||||
struct object *h_object;
|
||||
handle_flags_t h_flags;
|
||||
};
|
||||
|
||||
struct handle_table {
|
||||
union {
|
||||
struct {
|
||||
/* bitmap tracks which bits in t_handle_list are
|
||||
* allocated */
|
||||
DECLARE_BITMAP(t_handle_map, HANDLES_PER_TABLE);
|
||||
struct handle t_handle_list[HANDLES_PER_TABLE];
|
||||
} t_handles;
|
||||
|
||||
struct {
|
||||
/* bitmap tracks which sub-tables are fully-allocated */
|
||||
DECLARE_BITMAP(t_subtable_map, REFS_PER_TABLE);
|
||||
struct handle_table *t_subtable_list[REFS_PER_TABLE];
|
||||
} t_subtables;
|
||||
};
|
||||
};
|
||||
|
||||
extern struct handle_table *handle_table_create(void);
|
||||
extern void handle_table_destroy(struct handle_table *tab);
|
||||
|
||||
extern kern_status_t handle_table_alloc_handle(
|
||||
struct handle_table *tab,
|
||||
struct handle **out_slot,
|
||||
kern_handle_t *out_handle);
|
||||
extern kern_status_t handle_table_free_handle(
|
||||
struct handle_table *tab,
|
||||
kern_handle_t handle);
|
||||
extern struct handle *handle_table_get_handle(
|
||||
struct handle_table *tab,
|
||||
kern_handle_t handle);
|
||||
|
||||
extern kern_status_t handle_list_transfer(
|
||||
struct handle_table *dest,
|
||||
struct handle_list *dest_list,
|
||||
size_t dest_list_count,
|
||||
struct handle_table *src,
|
||||
const struct handle_list *src_list,
|
||||
size_t src_list_count);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user