Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
library.c
Go to the documentation of this file.
1#include "./library.h"
2#include "vfs/dentry.h"
3#include "vfs/vnode.h"
4#include <hal/cpu/paging.h>
6#include <libk/serial.h>
7#include <str.h>
10#include <vfs/vfs.h>
11
12static struct Library* libraries = NULL;
13
14void library_register(const char* path, enum LibraryType type) {
15 // TODO: buka file hanya ketika di load saja
16 dentry_ptr opened_dentry = 0;
17 resolve_dentry((char*) path, 0, &opened_dentry, 0);
18 if (!opened_dentry) {
19 LOG_ERROR("LIBRARY", "failed to open file %s", path);
20 return;
21 }
22
23 uint8_t* file_data = (uint8_t*) (kalloc(opened_dentry->vnode->size));
24 memset(file_data, 0, opened_dentry->vnode->size);
25 ((vops_file_t*) opened_dentry->vnode->ops)
26 ->read(opened_dentry->vnode, file_data,
27 opened_dentry->vnode->size, 0);
28
29 struct Library* lib = (kalloc(sizeof(struct Library)));
30 memset((void*) lib, 0, sizeof(struct Library));
31
32 lib->name = opened_dentry->name->c_str;
33 lib->type = type;
34 lib->entry = (uintptr_t) file_data;
35
36 if (libraries == 0) {
37 libraries = lib;
38 } else {
39 struct Library* current = libraries;
40 while (current->next != 0) {
41 current = current->next;
42 }
43 current->next = lib;
44 }
45
46 LOG_INFO("LIBRARY", "success registerd %s", lib->name);
47}
48
49struct Library* library_load(const char* name) {
50 struct Library* current = libraries;
51 while (current != 0) {
52 if (strncmp(current->name, name, strlen(name)) == 0) {
53 LOG_INFO("LIBRARY", "success load %s", current->name);
54 return current;
55 }
56 current = current->next;
57 }
58 return 0;
59}
60
61// TODO: tambahkan unload
kstring name
Definition dentry.h:5
struct dentry * dentry_ptr
Definition dentry.h:20
int resolve_dentry(char *path, dentry_ptr parent, dentry_ptr *out, uint8_t flag)
Resolves a path to a directory entry (dentry) with configurable start point and strictness.
void * kalloc(size_t size)
void library_register(const char *path, enum LibraryType type)
Definition library.c:14
struct Library * library_load(const char *name)
Definition library.c:49
static struct Library * libraries
Definition library.c:12
LibraryType
Definition library.h:6
#define LOG_ERROR(mod, fmt,...)
Definition serial.h:25
#define LOG_INFO(mod, fmt,...)
Definition serial.h:20
int strncmp(const char *s1, const char *s2, size_t n)
size_t strlen(const char *s)
Definition str.c:105
void memset(void *ptr, int value, size_t num)
char * name
Definition library.h:9
enum LibraryType type
Definition library.h:12
struct Library * next
Definition library.h:13
uintptr_t entry
Definition library.h:11
kstring name
Definition dentry.h:32
struct vnode * vnode
Definition dentry.h:33
char * c_str
Definition string.h:12
void * ops
Definition vnode.h:64
size_t size
Definition vnode.h:63
#define NULL
Definition type.h:76
unsigned long uintptr_t
Definition type.h:73
unsigned char uint8_t
Definition type.h:7
uint8_t type
Definition vnode.h:2
kstring path
Definition voxmo.h:7