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
>
5
#include <
libk/executable/elf.h
>
6
#include <
libk/serial.h
>
7
#include <
str.h
>
8
#include <
memory/memory_utils.h
>
9
#include <
memory/phys_base_allocator.h
>
10
#include <
vfs/vfs.h
>
11
12
static
struct
Library
*
libraries
=
NULL
;
13
14
void
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
49
struct
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
dentry.h
name
kstring name
Definition
dentry.h:5
dentry_ptr
struct dentry * dentry_ptr
Definition
dentry.h:20
resolve_dentry
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.
elf.h
kalloc
void * kalloc(size_t size)
library_register
void library_register(const char *path, enum LibraryType type)
Definition
library.c:14
library_load
struct Library * library_load(const char *name)
Definition
library.c:49
libraries
static struct Library * libraries
Definition
library.c:12
library.h
LibraryType
LibraryType
Definition
library.h:6
memory_utils.h
paging.h
phys_base_allocator.h
serial.h
LOG_ERROR
#define LOG_ERROR(mod, fmt,...)
Definition
serial.h:25
LOG_INFO
#define LOG_INFO(mod, fmt,...)
Definition
serial.h:20
str.h
strncmp
int strncmp(const char *s1, const char *s2, size_t n)
strlen
size_t strlen(const char *s)
Definition
str.c:105
memset
void memset(void *ptr, int value, size_t num)
Library
Definition
library.h:8
Library::name
char * name
Definition
library.h:9
Library::type
enum LibraryType type
Definition
library.h:12
Library::next
struct Library * next
Definition
library.h:13
Library::entry
uintptr_t entry
Definition
library.h:11
dentry::name
kstring name
Definition
dentry.h:32
dentry::vnode
struct vnode * vnode
Definition
dentry.h:33
kstring::c_str
char * c_str
Definition
string.h:12
vnode::ops
void * ops
Definition
vnode.h:64
vnode::size
size_t size
Definition
vnode.h:63
vops_file_t
Definition
vnode.h:28
NULL
#define NULL
Definition
type.h:76
uintptr_t
unsigned long uintptr_t
Definition
type.h:73
uint8_t
unsigned char uint8_t
Definition
type.h:7
vfs.h
vnode.h
type
uint8_t type
Definition
vnode.h:2
path
kstring path
Definition
voxmo.h:7
kernel
sys
library.c
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2