Skip to content

Commit

Permalink
Rename entity functions (#86)
Browse files Browse the repository at this point in the history
Rename entity functions so function name starts with the entity name.
This prevents conflicts and ambiguity with application layer functions.
  • Loading branch information
phaubertin authored Nov 19, 2024
1 parent 790f3f2 commit ab15a68
Show file tree
Hide file tree
Showing 31 changed files with 250 additions and 250 deletions.
20 changes: 10 additions & 10 deletions include/kernel/domain/entities/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ static inline bool descriptor_has_permissions(const descriptor_t *desc, int perm
return (desc->flags & perms) == perms;
}

void clear_descriptor(descriptor_t *desc);
void descriptor_clear(descriptor_t *desc);

int dereference_object_descriptor(
int descriptor_access_object(
descriptor_t *pout,
process_t *process,
int fd);

void unreference_descriptor_object(descriptor_t *desc);
void descriptor_unreference_object(descriptor_t *desc);

int reserve_free_descriptor(process_t *process, int fd);
int descriptor_reserve_unused(process_t *process, int fd);

void free_reserved_descriptor(process_t *process, int fd);
void descriptor_free_reservation(process_t *process, int fd);

void open_descriptor(process_t *process, int fd, const descriptor_t *in);
void descriptor_open(process_t *process, int fd, const descriptor_t *in);

int close_descriptor(process_t *process, int fd);
int descriptor_close(process_t *process, int fd);

ipc_endpoint_t *get_endpoint_from_descriptor(descriptor_t *desc);
ipc_endpoint_t *descriptor_get_endpoint(descriptor_t *desc);

process_t *get_process_from_descriptor(descriptor_t *desc);
process_t *descriptor_get_process(descriptor_t *desc);

thread_t *get_thread_from_descriptor(descriptor_t *desc);
thread_t *descriptor_get_thread(descriptor_t *desc);

#endif
2 changes: 1 addition & 1 deletion include/kernel/domain/entities/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ static inline object_header_t *endpoint_object(ipc_endpoint_t *endpoint) {

void initialize_endpoint_cache(void);

ipc_endpoint_t *construct_endpoint(void);
ipc_endpoint_t *endpoint_new(void);

#endif
12 changes: 6 additions & 6 deletions include/kernel/domain/entities/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ static inline bool object_is_destroyed(object_header_t *object) {
return !!(object->flags & OBJECT_FLAG_DESTROYED);
}

static inline void init_object_header(object_header_t *object, const object_type_t *type) {
static inline void object_init_header(object_header_t *object, const object_type_t *type) {
object->type = type;
object->ref_count = 0;
object->flags = OBJECT_FLAG_NONE;
}

void init_object_cache(slab_cache_t *cache, const object_type_t *type);

void open_object(object_header_t *object, const descriptor_t *desc);
void object_open(object_header_t *object, const descriptor_t *desc);

void close_object(object_header_t *object, const descriptor_t *desc);
void object_close(object_header_t *object, const descriptor_t *desc);

void destroy_object(object_header_t *object);
void object_destroy(object_header_t *object);

void add_ref_to_object(object_header_t *object);
void object_add_ref(object_header_t *object);

void sub_ref_to_object(object_header_t *object);
void object_sub_ref(object_header_t *object);

#endif
10 changes: 5 additions & 5 deletions include/kernel/domain/entities/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ static inline object_header_t *process_object(process_t *process) {

void initialize_process_cache(void);

process_t *construct_process(void);
process_t *get_current_process(void);

void switch_to_process(process_t *process);
process_t *process_new(void);

process_t *get_current_process(void);
void process_switch_to(process_t *process);

void add_running_thread_to_process(process_t *process);
void process_add_running_thread(process_t *process);

void remove_running_thread_from_process(process_t *process);
void process_remove_running_thread(process_t *process);

#endif
22 changes: 11 additions & 11 deletions include/kernel/domain/entities/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ static inline object_header_t *thread_object(thread_t *thread) {
return &thread->header;
}

thread_t *construct_thread(process_t *process);
thread_t *thread_new(process_t *process);

void prepare_thread(thread_t *thread, const thread_params_t *params);
void thread_prepare(thread_t *thread, const thread_params_t *params);

void ready_thread(thread_t *thread);
void thread_ready(thread_t *thread);

void run_first_thread(thread_t *thread);
void thread_run_first(thread_t *thread);

void run_thread(thread_t *thread);
void thread_run(thread_t *thread);

void terminate_current_thread(void);
void thread_terminate_current(void);

void switch_to(thread_t *to);
void thread_switch_to(thread_t *to);

void switch_to_and_block(thread_t *to);
void thread_switch_to_and_block(thread_t *to);

void block_and_unlock(spinlock_t *lock);
void thread_block_current_and_unlock(spinlock_t *lock);

void yield_current_thread(void);
void thread_yield_current(void);

void set_thread_local_storage(thread_t *thread, addr_t addr, size_t size);
void thread_set_local_storage(thread_t *thread, addr_t addr, size_t size);

#endif
10 changes: 5 additions & 5 deletions kernel/application/kmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ void kmain(const char *cmdline) {
initialize_process_cache();

/* create process for user space loader */
process_t *process = construct_process();
process_t *process = process_new();

if(process == NULL) {
panic("Could not create initial process.");
}

switch_to_process(process);
process_switch_to(process);

/* create user space loader main thread */
thread_t *thread = construct_thread(process);
thread_t *thread = thread_new(process);

if(thread == NULL) {
panic("Could not create initial thread.");
Expand All @@ -117,8 +117,8 @@ void kmain(const char *cmdline) {
info("---");

/* Start first thread. */
run_first_thread(thread);
thread_run_first(thread);

/* should never happen */
panic("run_first_thread() returned in kmain()");
panic("thread_run_first() returned in kmain()");
}
8 changes: 4 additions & 4 deletions kernel/application/syscalls/await_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <kernel/machine/thread.h>

static int with_thread(descriptor_t *thread_desc) {
thread_t *thread = get_thread_from_descriptor(thread_desc);
thread_t *thread = descriptor_get_thread(thread_desc);

if(thread == NULL) {
return -JINUE_EBADF;
Expand Down Expand Up @@ -67,23 +67,23 @@ static int with_thread(descriptor_t *thread_desc) {
if(thread->state == THREAD_STATE_ZOMBIE) {
spin_unlock(&thread->await_lock);
} else {
block_and_unlock(&thread->await_lock);
thread_block_current_and_unlock(&thread->await_lock);
}

return 0;
}

int await_thread(int fd) {
descriptor_t thread_desc;
int status = dereference_object_descriptor(&thread_desc, get_current_process(), fd);
int status = descriptor_access_object(&thread_desc, get_current_process(), fd);

if(status < 0) {
return -JINUE_EBADF;
}

status = with_thread(&thread_desc);

unreference_descriptor_object(&thread_desc);
descriptor_unreference_object(&thread_desc);

return status;
}
2 changes: 1 addition & 1 deletion kernel/application/syscalls/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@


int close(int fd) {
return close_descriptor(get_current_process(), fd);
return descriptor_close(get_current_process(), fd);
}
8 changes: 4 additions & 4 deletions kernel/application/syscalls/create_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
*/
int create_endpoint(int fd) {
process_t *process = get_current_process();
int status = reserve_free_descriptor(process, fd);
int status = descriptor_reserve_unused(process, fd);

if(status < 0) {
return status;
}

ipc_endpoint_t *endpoint = construct_endpoint();
ipc_endpoint_t *endpoint = endpoint_new();

if(endpoint == NULL) {
free_reserved_descriptor(process, fd);
descriptor_free_reservation(process, fd);
return -JINUE_EAGAIN;
}

Expand All @@ -65,7 +65,7 @@ int create_endpoint(int fd) {
desc.flags = DESC_FLAG_OWNER | object_type_ipc_endpoint->all_permissions;
desc.cookie = 0;

open_descriptor(process, fd, &desc);
descriptor_open(process, fd, &desc);

return 0;
}
8 changes: 4 additions & 4 deletions kernel/application/syscalls/create_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@

int create_process(int fd) {
process_t *current = get_current_process();
int status = reserve_free_descriptor(current, fd);
int status = descriptor_reserve_unused(current, fd);

if(status < 0) {
return status;
}

process_t *new_process = construct_process();
process_t *new_process = process_new();

if(new_process == NULL) {
free_reserved_descriptor(current, fd);
descriptor_free_reservation(current, fd);
return -JINUE_EAGAIN;
}

Expand All @@ -55,7 +55,7 @@ int create_process(int fd) {
desc.flags = DESC_FLAG_OWNER | object_type_process->all_permissions;
desc.cookie = 0;

open_descriptor(current, fd, &desc);
descriptor_open(current, fd, &desc);

return 0;
}
14 changes: 7 additions & 7 deletions kernel/application/syscalls/create_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


static int with_target_process(process_t *current, int fd, descriptor_t *target_desc) {
process_t *target = get_process_from_descriptor(target_desc);
process_t *target = descriptor_get_process(target_desc);

if(target == NULL) {
return -JINUE_EBADF;
Expand All @@ -48,7 +48,7 @@ static int with_target_process(process_t *current, int fd, descriptor_t *target_
return -JINUE_EPERM;
}

thread_t *thread = construct_thread(target);
thread_t *thread = thread_new(target);

if(thread == NULL) {
return -JINUE_ENOMEM;
Expand All @@ -59,29 +59,29 @@ static int with_target_process(process_t *current, int fd, descriptor_t *target_
desc.flags = DESC_FLAG_OWNER | object_type_thread->all_permissions;
desc.cookie = 0;

open_descriptor(current, fd, &desc);
descriptor_open(current, fd, &desc);

return 0;
}

static int with_descriptor_reserved(process_t *current, int fd, int process_fd) {
descriptor_t target_desc;
int status = dereference_object_descriptor(&target_desc, current, process_fd);
int status = descriptor_access_object(&target_desc, current, process_fd);

if(status < 0) {
return status;
}

status = with_target_process(current, fd, &target_desc);

unreference_descriptor_object(&target_desc);
descriptor_unreference_object(&target_desc);

return status;
}

int create_thread(int fd, int process_fd) {
process_t *current = get_current_process();
int status = reserve_free_descriptor(current, fd);
int status = descriptor_reserve_unused(current, fd);

if(status < 0) {
return -JINUE_EBADF;
Expand All @@ -90,7 +90,7 @@ int create_thread(int fd, int process_fd) {
status = with_descriptor_reserved(current, fd, process_fd);

if(status < 0) {
free_reserved_descriptor(current, fd);
descriptor_free_reservation(current, fd);
}

return status;
Expand Down
10 changes: 5 additions & 5 deletions kernel/application/syscalls/destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int destroy(int fd) {
process_t *process = get_current_process();

descriptor_t desc;
int status = dereference_object_descriptor(&desc, process, fd);
int status = descriptor_access_object(&desc, process, fd);

if(status < 0) {
return status;
Expand All @@ -50,18 +50,18 @@ int destroy(int fd) {

/* TODO support other object types */
if(object->type != object_type_ipc_endpoint) {
unreference_descriptor_object(&desc);
descriptor_unreference_object(&desc);
return -JINUE_EBADF;
}

if(!descriptor_is_owner(&desc)) {
unreference_descriptor_object(&desc);
descriptor_unreference_object(&desc);
return -JINUE_EPERM;
}

destroy_object(object);
object_destroy(object);

unreference_descriptor_object(&desc);
descriptor_unreference_object(&desc);

return 0;
}
Loading

0 comments on commit ab15a68

Please sign in to comment.