Skip to content

Commit

Permalink
Merge branch 'obhq:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Apr 2, 2024
2 parents 9ed2cfe + f6023d4 commit 9c29467
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/kernel/src/rtld/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl RuntimeLinker {

sys.register(591, &ld, Self::sys_dynlib_dlsym);
sys.register(592, &ld, Self::sys_dynlib_get_list);
sys.register(593, &ld, Self::sys_dynlib_get_info);
sys.register(594, &ld, Self::sys_dynlib_load_prx);
sys.register(596, &ld, Self::sys_dynlib_do_copy_relocations);
sys.register(598, &ld, Self::sys_dynlib_get_proc_param);
Expand Down Expand Up @@ -180,6 +181,8 @@ impl RuntimeLinker {
let loaded = bin.list().skip(1).find(|m| m.path() == path);

if let Some(v) = loaded {
*v.ref_count_mut() += 1;

return Ok((v.clone(), bin));
}

Expand Down Expand Up @@ -448,6 +451,10 @@ impl RuntimeLinker {
Ok(SysOut::ZERO)
}

fn sys_dynlib_get_info(self: &Arc<Self>, _td: &VThread, _i: &SysIn) -> Result<SysOut, SysErr> {
todo!()
}

fn sys_dynlib_load_prx(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Not sure what is this. Maybe kernel only flags?
let mut flags: u32 = i.args[1].try_into().unwrap();
Expand Down Expand Up @@ -920,7 +927,7 @@ impl RuntimeLinker {
info.datasize = mem.data_segment().len().try_into().unwrap();
info.unk4 = 3;
info.unk6 = 2;
info.refcount = Arc::strong_count(md).try_into().unwrap();
info.refcount = *md.ref_count();

// Copy module name.
if flags & 2 == 0 || !md.flags().contains(ModuleFlags::UNK1) {
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/src/rtld/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct Module {
file_type: FileType,
programs: Vec<Program>,
symbols: Vec<Symbol>,
ref_count: Gutex<u32>,
}

impl Module {
Expand Down Expand Up @@ -187,6 +188,7 @@ impl Module {
file_type,
programs,
symbols,
ref_count: gg.spawn(1),
};

if let Some(info) = file_info {
Expand Down Expand Up @@ -311,6 +313,14 @@ impl Module {
self.symbols.as_ref()
}

pub fn ref_count(&self) -> GutexReadGuard<'_, u32> {
self.ref_count.read()
}

pub fn ref_count_mut(&self) -> GutexWriteGuard<'_, u32> {
self.ref_count.write()
}

/// # Safety
/// `off` must be a valid offset without base adjustment of a function in the memory of this
/// module.
Expand Down

0 comments on commit 9c29467

Please sign in to comment.