Skip to content

Commit

Permalink
Merge branch 'main' into regmgr-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Feb 18, 2024
2 parents 08b1c44 + 4d5042c commit 9d6bed8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 105 deletions.
98 changes: 0 additions & 98 deletions .github/workflows/release.yml

This file was deleted.

41 changes: 35 additions & 6 deletions src/kernel/src/regmgr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::ucred::{Privilege, Ucred};
use crate::{info, warn};
use std::fmt::{Display, Formatter};
use std::num::NonZeroI32;
use std::ops::Index;
use std::ptr::read;
use std::sync::Arc;
use thiserror::Error;

Expand Down Expand Up @@ -121,11 +123,15 @@ impl RegMgr {
todo!("regmgr_call with multiplier ^ 0x6b > 12");
}

let x = e ^ SBOX1[i] as i32;
let x = e ^ SBOX1[ReverseIndex(i)] as i32;
let sbox = if x == 0x19 {
&SBOX2
} else {
todo!("regmgr_call with x != 0x19");
if x != 0x72 {
todo!("regmgr_call with x != 0x19 && x != 0x72: {:#x}", x)
} else {
&SBOX1
}
};

// Construct the key.
Expand All @@ -145,8 +151,18 @@ impl RegMgr {
};

if v3 == 1 {
todo!("decode regmgr_call request with v3 = 1");
} else if cred.is_nongame() {
if cred.is_nongame() && entry.unk3 & 0x10 == 0 {
return Err(RegError::V800d0216);
}
if entry.unk3 & 1 == 0 {
return Err(RegError::V800d0214);
}
if (!(entry.unk3 >> 12) & web) != 0 {
return Err(RegError::V800d021f);
}
}

if cred.is_nongame() {
todo!("decode regmgr_call request with non-game cred");
} else if (entry.unk3 & 2) == 0 {
Err(RegError::V800d0214)
Expand Down Expand Up @@ -380,6 +396,7 @@ pub enum RegError {
V800d0207,
V800d0208,
V800d0214,
V800d0216,
V800d0219,
V800d021f,
}
Expand All @@ -393,6 +410,7 @@ impl RegError {
Self::V800d0207 => 0x800d0207u32 as i32,
Self::V800d0208 => 0x800d0208u32 as i32,
Self::V800d0214 => 0x800d0214u32 as i32,
Self::V800d0216 => 0x800d0216u32 as i32,
Self::V800d0219 => 0x800d0219u32 as i32,
Self::V800d021f => 0x800d021fu32 as i32,
}
Expand All @@ -419,14 +437,25 @@ struct RegUnk6 {
unk4: u32,
}

const SBOX1: [u8; 13] = [
0x8c, 0x4c, 0xa4, 0xff, 0x7b, 0xf5, 0xee, 0x63, 0x5a, 0x23, 0x70, 0x9a, 0x03,
const SBOX1: [u8; 16] = [
0x68, 0xe8, 0x98, 0x03, 0x9a, 0x70, 0x23, 0x5a, 0x63, 0xee, 0xf5, 0x7b, 0xff, 0xa4, 0x4c, 0x8c,
];

const SBOX2: [u8; 16] = [
0x14, 0xee, 0xde, 0xe1, 0x80, 0xac, 0xf3, 0x78, 0x47, 0x43, 0xdb, 0x40, 0x93, 0xdd, 0xb1, 0x34,
];

pub struct ReverseIndex(pub usize);

impl<T> Index<ReverseIndex> for [T] {
type Output = T;

fn index(&self, idx: ReverseIndex) -> &T {
let len = self.len();
&self[len - 1 - idx.0]
}
}

const UNK_ENTRIES1: [RegUnk6; 3] = [
RegUnk6 {
key: RegKey::NET_WIFI_FREQ_BAND,
Expand Down
49 changes: 48 additions & 1 deletion src/kernel/src/sysctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ impl Sysctl {
pub const VM_PS4DEV_TRCMEM_TOTAL: i32 = 571;
pub const VM_PS4DEV_TRCMEM_AVAIL: i32 = 572;

pub const VM_BUDGETS: i32 = 313;
pub const VM_BUDGETS_MLOCK_AVAIL: i32 = 314;

pub const HW_PAGESIZE: i32 = 7;

pub fn new(mm: &Arc<MemoryManager>, machdep: &Arc<MachDep>, sys: &mut Syscalls) -> Arc<Self> {
Expand Down Expand Up @@ -439,6 +442,16 @@ impl Sysctl {
todo!()
}

fn budgets_mlock_avail(
&self,
_: &'static Oid,
_: &Arg,
_: usize,
_req: &mut SysctlReq,
) -> Result<(), SysErr> {
todo!()
}

fn machdep_tsc_freq(
&self,
oid: &'static Oid,
Expand Down Expand Up @@ -630,6 +643,8 @@ type Handler = fn(&Sysctl, &'static Oid, &Arg, usize, &mut SysctlReq) -> Result<
// └─── ...
// └─── (2.1.571) VM_PS4DEV_TRCMEM_TOTAL
// └─── (2.1.572) VM_PS4DEV_TRCMEM_AVAIL
// └─── (2.313) VM_BUDGETS
// └─── (2.313.314) VM_BUDGETS_MLOCK_AVAIL
// └─── ...
// └─── (3) VFS
// └─── ...
Expand Down Expand Up @@ -916,7 +931,7 @@ static VM_CHILDREN: OidList = OidList {

static VM_PS4DEV: Oid = Oid {
parent: &VM_CHILDREN,
link: None, // TODO: Change to a proper value.
link: Some(&VM_BUDGETS), // TODO: Change to a proper value.
number: Sysctl::VM_PS4DEV,
kind: Sysctl::CTLFLAG_RD | Sysctl::CTLTYPE_NODE,
arg1: Some(&VM_PS4DEV_CHILDREN),
Expand Down Expand Up @@ -960,6 +975,38 @@ static VM_PS4DEV_TRCMEM_AVAIL: Oid = Oid {
enabled: true,
};

static VM_BUDGETS: Oid = Oid {
parent: &VM_CHILDREN,
link: None, // TODO: Change to a proper value.
number: Sysctl::VM_BUDGETS,
kind: Sysctl::CTLFLAG_RW | Sysctl::CTLTYPE_NODE,
arg1: Some(&VM_BUDGETS_CHILDREN),
arg2: 0,
name: "budgets",
handler: None,
fmt: "N",
descr: "VM budgets",
enabled: true,
};

static VM_BUDGETS_CHILDREN: OidList = OidList {
first: Some(&VM_BUDGETS_MLOCK_AVAIL),
};

static VM_BUDGETS_MLOCK_AVAIL: Oid = Oid {
parent: &VM_BUDGETS_CHILDREN,
link: None,
number: Sysctl::VM_BUDGETS_MLOCK_AVAIL,
kind: Sysctl::CTLFLAG_RD | Sysctl::CTLTYPE_ULONG,
arg1: None,
arg2: 0,
name: "mlock_avail",
handler: Some(Sysctl::budgets_mlock_avail),
fmt: "L",
descr: "Available MLOCK budget",
enabled: true,
};

static HW: Oid = Oid {
parent: &CHILDREN,
link: Some(&MACHDEP),
Expand Down

0 comments on commit 9d6bed8

Please sign in to comment.