Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements sys_dynlib_get_info #672

Merged
merged 58 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fce95f5
initial
Feb 18, 2024
b9bef9a
initial implementation of sys_dynlib_get_info
Feb 18, 2024
17f024f
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 18, 2024
199cbca
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 18, 2024
10ab7fd
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 21, 2024
de5cf92
fix syscall number
Feb 21, 2024
57775a9
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 21, 2024
5836df8
fingerprint
Feb 23, 2024
ea4747b
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 23, 2024
1055b86
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 23, 2024
2c8b500
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
226a9d3
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
c917df4
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
7e60c96
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
0354b03
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
9c2bfaf
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
9ed862b
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
95085f1
segment info
Feb 24, 2024
ca212b3
nfnrg
Feb 24, 2024
61129a3
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 24, 2024
e1c17b7
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 25, 2024
3a7a763
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 25, 2024
717c44c
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 25, 2024
dbb583a
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 26, 2024
7bfe362
Merge branch 'main' into sys-593
SuchAFuriousDeath Feb 28, 2024
ce4d1a5
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 2, 2024
2fad6bb
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 2, 2024
285aee1
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 3, 2024
aa0864b
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 9, 2024
417eaf9
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 9, 2024
ce34009
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 10, 2024
3605992
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 16, 2024
fc413fc
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 17, 2024
86517a9
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 19, 2024
f5a8611
fix
Mar 19, 2024
881f22c
add syscall back
Mar 19, 2024
ef1675b
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 21, 2024
8d6be5d
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 23, 2024
617b04f
Merge branch 'main' into sys-593
SuchAFuriousDeath Mar 31, 2024
d7ea35e
Merge branch 'main' into sys-593
SuchAFuriousDeath Apr 1, 2024
cc27bb6
Merge branch 'main' into sys-593
SuchAFuriousDeath Apr 2, 2024
0ee03e9
fix
SuchAFuriousDeath Apr 2, 2024
6a974e7
comment
SuchAFuriousDeath Apr 2, 2024
d37ae51
fix + log
SuchAFuriousDeath Apr 2, 2024
2560c55
Finalize
SuchAFuriousDeath Apr 2, 2024
0577b4d
Implement get proc type info checks
SuchAFuriousDeath Apr 4, 2024
0b96ac3
remove copy and clone from privilege
SuchAFuriousDeath Apr 4, 2024
529865e
add unused
SuchAFuriousDeath Apr 4, 2024
6de4dd7
checks fix
SuchAFuriousDeath Apr 5, 2024
d43495a
blockpool_open
SuchAFuriousDeath Apr 5, 2024
712c4e6
rename dmem10 ioctl
SuchAFuriousDeath Apr 5, 2024
b38a825
improve log
SuchAFuriousDeath Apr 5, 2024
97ae9b5
revert back to todo
SuchAFuriousDeath Apr 5, 2024
514eac5
add comment
SuchAFuriousDeath Apr 5, 2024
ecc8606
remove unused
SuchAFuriousDeath Apr 5, 2024
ba86702
rename flags
SuchAFuriousDeath Apr 5, 2024
9813b46
fix flags
SuchAFuriousDeath Apr 5, 2024
904f975
fix main
SuchAFuriousDeath Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/elf/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl FileInfo {
let id = LE::read_u16(&data[6..]);

// Lookup name.
let name = match self.read_str(name.try_into().unwrap()) {
let name = match self.read_str(name as usize) {
Ok(v) => v.to_owned(),
Err(e) => return Err(ReadModuleError::InvalidNameOffset(name, e)),
};
Expand All @@ -301,6 +301,15 @@ impl FileInfo {
Ok(LibraryInfo::new(id, name, LibraryFlags::empty()))
}

pub fn read_fingerprint(&self, offset: usize) -> [u8; 20] {
let offset = offset + self.dynoff;

let mut fingerprint = [0u8; 20];
fingerprint.copy_from_slice(&self.data[offset..(offset + 20)]);

fingerprint
}

pub fn read_str(&self, offset: usize) -> Result<&str, StringTableError> {
// Get raw string.
let tab = &self.data[self.strtab..(self.strtab + self.strsz)];
Expand All @@ -316,7 +325,9 @@ impl FileInfo {
};

// Get Rust string.
std::str::from_utf8(raw).map_err(|_| StringTableError::NotUtf8)
let string = std::str::from_utf8(raw)?;

Ok(string)
}
}

Expand Down Expand Up @@ -419,3 +430,9 @@ pub enum StringTableError {
#[error("the offset is not a UTF-8 string")]
NotUtf8,
}

impl From<std::str::Utf8Error> for StringTableError {
fn from(_: std::str::Utf8Error) -> Self {
Self::NotUtf8
}
}
4 changes: 4 additions & 0 deletions src/elf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ impl<I: Read + Seek> Elf<I> {
self.programs.as_slice()
}

pub fn relro(&self) -> Option<usize> {
self.relro
}

pub fn dynamic(&self) -> Option<usize> {
self.dynamic
}
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/src/budget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ pub enum ProcType {
MiniApp,
System, // TODO: Verify this.
}

impl Into<u32> for ProcType {
fn into(self) -> u32 {
match self {
ProcType::BigApp => 0,
ProcType::MiniApp => 1,
ProcType::System => 2,
}
}
}
13 changes: 3 additions & 10 deletions src/kernel/src/dev/dmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,10 @@ impl TryInto<DmemContainer> for i32 {
}
}

impl TryInto<DmemContainer> for usize {
type Error = SysErr;

fn try_into(self) -> Result<DmemContainer, Self::Error> {
(self as i32).try_into()
}
}

impl DeviceDriver for Dmem {
fn ioctl(
&self,
dev: &Arc<CharacterDevice>,
_: &Arc<CharacterDevice>,
cmd: IoCmd,
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
Expand All @@ -76,7 +68,8 @@ impl DeviceDriver for Dmem {
}

match cmd {
IoCmd::DMEM10(size) => *size = self.total_size,
// TODO: properly implement this
IoCmd::DMEMTOTAL(size) => *size = self.total_size,
IoCmd::DMEMGETPRT(_prt) => todo!(),
IoCmd::DMEMGETAVAIL(_avail) => todo!(),
IoCmd::DMEMALLOC(_alloc) => todo!(),
Expand Down
6 changes: 6 additions & 0 deletions src/kernel/src/dmem/blockpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use std::sync::Arc;
#[derive(Debug)]
pub struct BlockPool {}

impl BlockPool {
pub fn new() -> Arc<Self> {
Arc::new(Self {})
}
}

impl FileBackend for BlockPool {
#[allow(unused_variables)] // TODO: remove when implementing
fn ioctl(
Expand Down
32 changes: 18 additions & 14 deletions src/kernel/src/dmem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use thiserror::Error;

use crate::dev::{Dmem, DmemContainer};
use crate::errno::EINVAL;
use crate::fs::{make_dev, CharacterDevice, DriverFlags, Fs, MakeDevError, MakeDevFlags, Mode};
use crate::fs::{
make_dev, CharacterDevice, DriverFlags, Fs, MakeDevError, MakeDevFlags, Mode, VFile, VFileType,
};
use crate::info;
use crate::process::{VProc, VThread};
use crate::process::VThread;
use crate::syscalls::{SysErr, SysIn, SysOut, Syscalls};
use crate::ucred::{Gid, Privilege, Uid};
use crate::ucred::{Gid, Uid};
use std::ops::Index;
use std::sync::Arc;
use thiserror::Error;

pub use self::blockpool::*;

Expand Down Expand Up @@ -112,24 +113,31 @@ impl DmemManager {
fn sys_dmem_container(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let dmem_id: i32 = i.args[0].try_into().unwrap();

let mut dmem_container = td.proc().dmem_container_mut();
let old_dmem_container = *dmem_container;
let dmem_container = td.proc().dmem_container_mut();
let current_container = *dmem_container;

if dmem_id != -1 {
todo!()
}

Ok(old_dmem_container.into())
Ok(current_container.into())
}

fn sys_blockpool_open(self: &Arc<Self>, _td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_open(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let flags: u32 = i.args[0].try_into().unwrap();

if flags & 0xffafffff != 0 {
return Err(SysErr::Raw(EINVAL));
}

todo!("sys_blockpool_open on new FS")
let bp = BlockPool::new();

let fd = td
.proc()
.files()
.alloc(Arc::new(VFile::new(VFileType::Blockpool(bp))));

Ok(fd.into())
}

fn sys_blockpool_map(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
Expand Down Expand Up @@ -158,10 +166,6 @@ impl DmemManager {
fn sys_blockpool_move(self: &Arc<Self>, _: &VThread, _i: &SysIn) -> Result<SysOut, SysErr> {
todo!()
}

fn get_dmem_device<'a>(self: &'a Arc<Self>, dmem: DmemContainer) -> &'a DmemDevice {
self.index(dmem)
}
}

impl Index<DmemContainer> for DmemManager {
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct VFile {
}

impl VFile {
pub(super) fn new(ty: VFileType) -> Self {
pub fn new(ty: VFileType) -> Self {
let gg = GutexGroup::new();

Self {
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/fs/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ commands! {
DIPSWCHECK2(&mut i32) = 0x40048806,

/// Get total size?
DMEM10(&mut usize) = 0x4008800a,
DMEMTOTAL(&mut usize) = 0x4008800a,
/// Get PRT aperture
DMEMGETPRT(&mut PrtAperture) = 0xC018800C,
/// Get available memory size
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl Fs {
// Our IoCmd contains both the command and the argument (if there is one).
let cmd = IoCmd::try_from_raw_parts(i.args[1].into(), i.args[2].into())?;

info!("Executing ioctl({cmd:?}) on file descriptor {fd}.");
info!("Executing ioctl {cmd:?} on file descriptor {fd}.");

self.ioctl(fd, cmd, td)?;

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn run() -> Result<(), KernelError> {
.load(path, flags, false, true, &main)
.map_err(|e| KernelError::FailedToLoadLibkernel(e.into()))?;

libkernel.flags_mut().remove(ModuleFlags::UNK2);
libkernel.flags_mut().remove(ModuleFlags::IS_NEW);
libkernel.print(info!());

ld.set_kernel(libkernel);
Expand All @@ -448,7 +448,7 @@ fn run() -> Result<(), KernelError> {
.load(path, flags, false, true, &main)
.map_err(|e| KernelError::FailedToLoadLibSceLibcInternal(e.into()))?;

libc.flags_mut().remove(ModuleFlags::UNK2);
libc.flags_mut().remove(ModuleFlags::IS_NEW);
libc.print(info!());

drop(libc);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl VProc {

ProcTypeInfo {
len: size_of::<ProcTypeInfo>(),
ty: self.budget_ptype as u32,
ty: self.budget_ptype.into(),
flags,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/regmgr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl RegMgr {
// Lookup the entry.
let key = RegKey::new(key);
let entry = self.lookup(key).ok_or(RegError::NotFound(key))?;
let web = if cred.is_webcore_process() || cred.is_diskplayerui_process() {
let web = if cred.is_libkernel_web() || cred.is_webprocess_webapp_or_webmas() {
1
} else {
0
Expand Down
12 changes: 8 additions & 4 deletions src/kernel/src/rtld/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Memory {
base: usize,
text: usize,
data: usize,
relro: Option<usize>,
obcode: usize,
obcode_sealed: Gutex<usize>,
obdata: usize,
Expand Down Expand Up @@ -61,10 +62,8 @@ impl Memory {
}
}
ProgramType::PT_SCE_RELRO => {
if relro.is_some() {
if relro.replace(segments.len()).is_some() {
return Err(MapError::MultipleRelroProgram);
} else {
relro = Some(segments.len());
}
}
_ => continue,
Expand Down Expand Up @@ -132,7 +131,7 @@ impl Memory {
len += segment.len;
segments.push(segment);

// Create workspace for our data. We cannot mix this the code because the executable-space
// Create workspace for our data. We cannot mix this with the code because the executable-space
// protection on some system don't allow execution on writable page.
let obdata = segments.len();
let segment = MemorySegment {
Expand Down Expand Up @@ -180,6 +179,7 @@ impl Memory {
base,
text,
data,
relro,
obcode,
obcode_sealed: gg.spawn(0),
obdata,
Expand Down Expand Up @@ -212,6 +212,10 @@ impl Memory {
&self.segments[self.data]
}

pub fn relro_segment(&self) -> Option<&MemorySegment> {
self.relro.as_ref().map(|i| &self.segments[*i])
}

/// # Safety
/// Some part of the returned slice may not readable.
pub unsafe fn as_bytes(&self) -> &[u8] {
Expand Down
Loading