Skip to content

Commit

Permalink
Makes Kernel a thin wrapper of a slice
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed May 11, 2024
1 parent 2c2e5dd commit d6d7cbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
17 changes: 7 additions & 10 deletions korbis-1100/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ use korbis::uio::UioSeg;
mod thread;

/// Implementation of [`ps4k::Kernel`] for 11.00.
pub struct Kernel {
elf: &'static [u8],
}
#[derive(Clone, Copy)]
pub struct Kernel(&'static [u8]);

impl korbis::Kernel for Kernel {
type Thread = Thread;

unsafe fn new(base: *const u8) -> Self {
let elf = Self::get_mapped_elf(base);

Self { elf }
Self(Self::get_mapped_elf(base))
}

unsafe fn elf(&self) -> &'static [u8] {
self.elf
unsafe fn elf(self) -> &'static [u8] {
self.0
}

#[offset(0xE63B0)]
unsafe fn kern_openat(
&self,
self,
td: *mut Self::Thread,
fd: c_int,
path: *const c_char,
Expand All @@ -37,5 +34,5 @@ impl korbis::Kernel for Kernel {
) -> c_int;

#[offset(0x416920)]
unsafe fn kern_close(&self, td: *mut Self::Thread, fd: c_int) -> c_int;
unsafe fn kern_close(self, td: *mut Self::Thread, fd: c_int) -> c_int;
}
10 changes: 5 additions & 5 deletions korbis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub mod elf;
pub mod thread;
pub mod uio;

/// Provides information about the PS4 kernel for a specific version.
pub trait Kernel: Send + Sync + 'static {
/// Provides methods to access the PS4 kernel for a specific version.
pub trait Kernel: Copy + Send + Sync + 'static {
type Thread: Thread;

/// # Safety
Expand All @@ -28,13 +28,13 @@ pub trait Kernel: Send + Sync + 'static {
/// # Safety
/// The returned slice can contains `PF_W` programs. That mean the memory covered by this slice
/// can mutate at any time. The whole slice is guarantee to be readable.
unsafe fn elf(&self) -> &'static [u8];
unsafe fn elf(self) -> &'static [u8];

/// # Safety
/// - `td` cannot be null.
/// - `path` cannot be null and must point to a null-terminated string if `seg` is [`UioSeg::Kernel`].
unsafe fn kern_openat(
&self,
self,
td: *mut Self::Thread,
fd: c_int,
path: *const c_char,
Expand All @@ -45,7 +45,7 @@ pub trait Kernel: Send + Sync + 'static {

/// # Safety
/// `td` cannot be null.
unsafe fn kern_close(&self, td: *mut Self::Thread, fd: c_int) -> c_int;
unsafe fn kern_close(self, td: *mut Self::Thread, fd: c_int) -> c_int;

/// # Safety
/// `base` must point to a valid address of the kernel. Behavior is undefined if format of the
Expand Down

0 comments on commit d6d7cbb

Please sign in to comment.