Skip to content

Prxgen: static alignment >32 bytes causes unloadable prx to be generated #191

@sajattack

Description

@sajattack

https://github.com/overdrivenpotato/rust-psp/blob/master/cargo-psp/src/bin/prxgen.rs

#![no_std]
#![no_main]

use psp;

psp::module!("minrepro", 1, 1);

#[repr(align(32))]
struct Align32<T>(T);

#[repr(align(64))]
struct Align64<T>(T);

#[repr(align(128))]
struct Align128<T>(T);

static MESSAGE1: Align32<&str> = Align32("hello world"); // this is fine
static MESSAGE2: Align64<&str> = Align64("hello world"); // this is *NOT* fine
static MESSAGE3: Align128<&str> = Align128("hello world"); // this is *ALSO NOT* fine

fn psp_main() {
    psp::dprintln!("{}", MESSAGE2.0);
}
paul@Frame-Fedora:~/projects/psp/ratatui/min-repro$ /usr/local/pspdev/bin/pspsh
host0:/> ./target/mipsel-sony-psp/release/min-repro.prx
Exception - Bus error (data)
Thread ID - 0x00CB8A29
Th Name   - SceKernelModmgrWorker
Module ID - 0x002B6149
Mod Name  - sceLoaderCore
EPC       - 0x8801E2FC
Cause     - 0x1000001C
BadVAddr  - 0x679B6CB1
Status    - 0x20088603
Address   - 0x000072FC
zr:0x00000000 at:0x00007F01 v0:0x80020000 v1:0x00000001
a0:0x00008378 a1:0x882FAAF0 a2:0x0000006D a3:0x00000000
t0:0x00000000 t1:0x88016A18 t2:0x0000006D t3:0x00008388
t4:0x00032EF2 t5:0x0000010E t6:0x00000001 t7:0x08810E00
s0:0x00000000 s1:0x8821313C s2:0x00000000 s3:0x0880D8B4
s4:0x00000000 s5:0x0880D8B0 s6:0x00000002 s7:0x882FAD90
t8:0x0000CE00 t9:0x00034D00 k0:0x00000000 k1:0x00000000
gp:0x8806BD90 sp:0x882FAAE0 fp:0x00000001 ra:0x8801D9B4
0x8801E2FC: 0x84830006 '....' - lh         $v1, 6($a0)

This error log traces back to here

https://github.com/uofw/uofw/blob/7ca6ba13966a38667fa7c5c30a428ccd248186cf/src/kd/loadcore/module.c#L563

a0 is 8378, which is not a valid pointer. Also 8378 is the address of .lib.ent but it should probably be the address to .rodata.sceKernelModuleInfo

Image

Maybe something to do with relocs or how the section headers are built into the prx.

Discovered by #190 and added a workaround to patch out the alignment for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions