2026-02-19 19:13:44 +00:00
|
|
|
#ifndef KERNEL_HANDLE_H_
|
|
|
|
|
#define KERNEL_HANDLE_H_
|
|
|
|
|
|
|
|
|
|
#include <kernel/bitmap.h>
|
|
|
|
|
#include <mango/status.h>
|
2026-03-01 19:10:01 +00:00
|
|
|
#include <mango/types.h>
|
2026-02-19 19:13:44 +00:00
|
|
|
#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;
|
2026-03-01 19:10:01 +00:00
|
|
|
struct vm_region;
|
2026-02-19 19:13:44 +00:00
|
|
|
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);
|
|
|
|
|
|
2026-03-01 19:10:01 +00:00
|
|
|
extern kern_status_t handle_table_transfer(
|
|
|
|
|
struct vm_region *dst_region,
|
|
|
|
|
struct handle_table *dst,
|
|
|
|
|
kern_msg_handle_t *dst_handles,
|
|
|
|
|
size_t dst_handles_max,
|
|
|
|
|
struct vm_region *src_region,
|
|
|
|
|
struct handle_table *src,
|
|
|
|
|
kern_msg_handle_t *src_handles,
|
|
|
|
|
size_t src_handles_count);
|
|
|
|
|
|
2026-02-19 19:13:44 +00:00
|
|
|
#endif
|