From 581d24ca2594ccc1d8aa1cf0804f9abb999689fb Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 17 Sep 2015 02:20:36 -0500 Subject: [PATCH] Cleanup and lang items. Lang items may be removed if we get a libstd. --- Cargo.toml | 3 --- src/lib.rs | 5 +++++ src/raw/console.rs | 2 +- src/raw/gfx.rs | 2 +- src/raw/gpu/gpu.rs | 2 +- src/raw/gpu/gx.rs | 2 +- src/raw/gpu/shader_program.rs | 2 +- src/raw/gpu/shbin.rs | 2 +- src/raw/linear.rs | 2 +- src/raw/os.rs | 2 +- src/raw/sdmc.rs | 2 +- src/raw/services/ac.rs | 2 +- src/raw/services/am.rs | 2 +- src/raw/services/apt.rs | 2 +- src/raw/services/cfgnor.rs | 2 +- src/raw/services/cfgu.rs | 2 +- src/raw/services/gsp.rs | 2 +- src/raw/services/hb.rs | 2 +- src/raw/services/hid.rs | 2 +- src/raw/services/ir.rs | 2 +- src/raw/services/irrst.rs | 2 +- src/raw/services/mic.rs | 2 +- src/raw/services/ns.rs | 2 +- src/raw/services/pm.rs | 2 +- src/raw/services/ptm.rs | 2 +- src/raw/services/soc.rs | 2 +- src/raw/vram.rs | 2 +- src/services/apt.rs | 7 ++++--- 28 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d770f3..da60fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,3 @@ build = "build.rs" [lib] name = "ctru" crate-type = ["rlib"] - -[dependencies.core] -git="https://github.com/hackndev/rust-libcore" diff --git a/src/lib.rs b/src/lib.rs index 38ff61a..8311552 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![feature(no_std)] +#![feature(lang_items)] #![no_std] #![crate_type = "rlib"] #![crate_name = "ctru"] @@ -11,3 +12,7 @@ pub type Handle = u32; pub mod srv; pub mod gfx; pub mod services; + +#[lang = "stack_exhausted"] extern fn stack_exhausted() {} +#[lang = "eh_personality"] extern fn eh_personality() {} +#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } diff --git a/src/raw/console.rs b/src/raw/console.rs index 902aebb..8871c7f 100644 --- a/src/raw/console.rs +++ b/src/raw/console.rs @@ -52,7 +52,7 @@ pub enum debugDevice { CONSOLE = 2, } -#[link(name = "ctru")] + extern "C" { pub fn consoleSetFont(console: *mut PrintConsole, font: *mut ConsoleFont) -> (); pub fn consoleSetWindow(console: *mut PrintConsole, x: i32, y: i32, width: i32, height: i32) -> (); diff --git a/src/raw/gfx.rs b/src/raw/gfx.rs index 7900c7a..4a20028 100644 --- a/src/raw/gfx.rs +++ b/src/raw/gfx.rs @@ -23,7 +23,7 @@ pub enum gfx3dSide_t { GFX_RIGHT = 1 } -#[link(name = "ctru")] + extern "C" { pub static mut gfxTopLeftFramebuffers: [*mut u8; 2usize]; pub static mut gfxTopRightFramebuffers: [*mut u8; 2usize]; diff --git a/src/raw/gpu/gpu.rs b/src/raw/gpu/gpu.rs index 02d776d..24f2f90 100644 --- a/src/raw/gpu/gpu.rs +++ b/src/raw/gpu/gpu.rs @@ -256,7 +256,7 @@ pub enum GPU_SHADER_TYPE { GPU_GEOMETRY_SHADER=0x1 } -#[link(name = "ctru")] + extern "C" { pub fn GPU_Init(gsphandle: *mut Handle) -> (); pub fn GPU_Reset(gxbuf: *mut u32, gpuBuf: *mut u32, gpuBufSize: u32) -> (); diff --git a/src/raw/gpu/gx.rs b/src/raw/gpu/gx.rs index c8dfcd7..d26c9ab 100644 --- a/src/raw/gpu/gx.rs +++ b/src/raw/gpu/gx.rs @@ -62,7 +62,7 @@ pub fn GX_TRANSFER_SCALING(x) { use ctru::Result; -#[link(name = "ctru")] + extern "C" { pub fn GX_RequestDma(gxbuf: *mut u32, src: *mut u32, dst: *mut u32, length: u32) -> Result; pub fn GX_SetCommandList_Last(gxbuf: *mut u32, buf0a: *mut u32, buf0s: u32, flags: u8) -> Result; diff --git a/src/raw/gpu/shader_program.rs b/src/raw/gpu/shader_program.rs index 0b20676..bf373e1 100644 --- a/src/raw/gpu/shader_program.rs +++ b/src/raw/gpu/shader_program.rs @@ -27,7 +27,7 @@ pub struct shaderProgram_s { use ctru::Result; -#[link(name = "ctru")] + extern "C" { pub fn shaderInstanceInit(si: *mut shaderInstance_s, dvle: *mut DVLE_s) -> Result; pub fn shaderInstanceFree(si: *mut shaderInstance_s) -> Result; diff --git a/src/raw/gpu/shbin.rs b/src/raw/gpu/shbin.rs index 736865b..db400d9 100644 --- a/src/raw/gpu/shbin.rs +++ b/src/raw/gpu/shbin.rs @@ -96,7 +96,7 @@ pub struct DVLB_s { use ctru::raw::types::*; -#[link(name = "ctru")] + extern "C" { pub fn DVLB_ParseFile(shbinData: *mut u32, shbinSize: u32) -> *mut DVLB_s; pub fn DVLB_Free(dvlb: *mut DVLB_s) -> (); diff --git a/src/raw/linear.rs b/src/raw/linear.rs index 32afc2c..691baef 100644 --- a/src/raw/linear.rs +++ b/src/raw/linear.rs @@ -1,6 +1,6 @@ use super::c_void; -#[link(name = "ctru")] + extern "C" { pub fn linearAlloc(size: i32) -> *mut c_void; pub fn linearMemAlign(size: i32, alignment: i32) -> *mut c_void; diff --git a/src/raw/os.rs b/src/raw/os.rs index 896b9cb..3ba7022 100644 --- a/src/raw/os.rs +++ b/src/raw/os.rs @@ -4,7 +4,7 @@ pub fn SYSTEM_VERSION(major: i32, minor: i32, revision: i32) { (((major)<<24)|((minor)<<16)|((revision)<<8)); } -#[link(name = "ctru")] + extern "C" { pub fn osConvertVirtToPhys(vaddr: u32) -> u32; pub fn osConvertOldLINEARMemToNew(addr: u32) -> u32; diff --git a/src/raw/sdmc.rs b/src/raw/sdmc.rs index 1dcfe8d..17b2cc8 100644 --- a/src/raw/sdmc.rs +++ b/src/raw/sdmc.rs @@ -1,6 +1,6 @@ use super::super::Result; -#[link(name = "ctru")] + extern "C" { pub fn sdmcInit() -> Result; pub fn sdmcExit() -> Result; diff --git a/src/raw/services/ac.rs b/src/raw/services/ac.rs index 7b1f1ed..0b07ec6 100644 --- a/src/raw/services/ac.rs +++ b/src/raw/services/ac.rs @@ -1,6 +1,6 @@ use ::{Handle, Result}; -#[link(name = "ctru")] + extern "C" { pub fn acInit() -> Result; pub fn acExit() -> Result; diff --git a/src/raw/services/am.rs b/src/raw/services/am.rs index 083588b..69f0e17 100644 --- a/src/raw/services/am.rs +++ b/src/raw/services/am.rs @@ -10,7 +10,7 @@ pub struct TitleList { unknown2: [u8; 6usize] } -#[link(name = "ctru")] + extern "C" { pub fn amInit() -> Result; pub fn amExit() -> Result; diff --git a/src/raw/services/apt.rs b/src/raw/services/apt.rs index b669c9b..180c2dc 100644 --- a/src/raw/services/apt.rs +++ b/src/raw/services/apt.rs @@ -74,7 +74,7 @@ pub struct aptHookCookie { param: *mut c_void, } -#[link(name = "ctru")] + extern "C" { pub static mut aptEvents: [Handle; 3usize]; diff --git a/src/raw/services/cfgnor.rs b/src/raw/services/cfgnor.rs index 28edbde..1993267 100644 --- a/src/raw/services/cfgnor.rs +++ b/src/raw/services/cfgnor.rs @@ -1,6 +1,6 @@ use ::Result; -#[link(name = "ctru")] + extern "C" { pub fn CFGNOR_Initialize(value: u8) -> Result; pub fn CFGNOR_Shutdown() -> Result; diff --git a/src/raw/services/cfgu.rs b/src/raw/services/cfgu.rs index cb0fe2b..6adccf1 100644 --- a/src/raw/services/cfgu.rs +++ b/src/raw/services/cfgu.rs @@ -1,6 +1,6 @@ use ::Result; -#[link(name = "ctru")] + extern "C" { pub fn initCfgu() -> Result; pub fn exitCfgu() -> Result; diff --git a/src/raw/services/gsp.rs b/src/raw/services/gsp.rs index af54e2c..db9f3da 100644 --- a/src/raw/services/gsp.rs +++ b/src/raw/services/gsp.rs @@ -56,7 +56,7 @@ pub enum GSP_Event { use super::super::super::{Result, Handle}; -#[link(name = "ctru")] + extern "C" { pub fn gspInit() -> Result; pub fn gspExit() -> (); diff --git a/src/raw/services/hb.rs b/src/raw/services/hb.rs index 9de1aa8..c2a23a6 100644 --- a/src/raw/services/hb.rs +++ b/src/raw/services/hb.rs @@ -1,7 +1,7 @@ use ::Result; use ::raw::c_void; -#[link(name = "ctru")] + extern "C" { pub fn hbInit() -> Result; pub fn hbExit() -> (); diff --git a/src/raw/services/hid.rs b/src/raw/services/hid.rs index 07f994d..28bc672 100644 --- a/src/raw/services/hid.rs +++ b/src/raw/services/hid.rs @@ -77,7 +77,7 @@ pub enum HID_Event { HIDEVENT_MAX, // used to know how many events there are } -#[link(name = "ctru")] + extern "C" { pub static hidMemHandle: Handle; pub static hidSharedMem: *mut vu32; diff --git a/src/raw/services/ir.rs b/src/raw/services/ir.rs index aa20992..3affb65 100644 --- a/src/raw/services/ir.rs +++ b/src/raw/services/ir.rs @@ -1,6 +1,6 @@ use ::{Result, Handle}; -#[link(name = "ctru")] + extern "C" { pub fn IRU_Initialize(sharedmem_addr: *mut u32, sharedmem_size: u32) -> Result; pub fn IRU_Shutdown() -> Result; diff --git a/src/raw/services/irrst.rs b/src/raw/services/irrst.rs index 8981591..4187260 100644 --- a/src/raw/services/irrst.rs +++ b/src/raw/services/irrst.rs @@ -3,7 +3,7 @@ use ::raw::types::*; use super::hid::circlePosition; -#[link(name = "ctru")] + extern "C" { pub static irrstMemHandle: Handle; pub static irrstSharedMem: *mut vu32; diff --git a/src/raw/services/mic.rs b/src/raw/services/mic.rs index d6e35d8..64e7746 100644 --- a/src/raw/services/mic.rs +++ b/src/raw/services/mic.rs @@ -1,6 +1,6 @@ use ::{Result, Handle}; -#[link(name = "ctru")] + extern "C" { pub fn MIC_Initialize(sharedmem: *mut u32, sharedmem_size: u32, control: u8, recording: u8, unk0: u8, unk1: u8, unk2: u8) -> Result; pub fn MIC_Shutdown() -> Result; diff --git a/src/raw/services/ns.rs b/src/raw/services/ns.rs index f2f1cb1..68a58c2 100644 --- a/src/raw/services/ns.rs +++ b/src/raw/services/ns.rs @@ -1,6 +1,6 @@ use ::Result; -#[link(name = "ctru")] + extern "C" { pub fn nsInit() -> Result; pub fn nsExit() -> Result; diff --git a/src/raw/services/pm.rs b/src/raw/services/pm.rs index 7926fbe..78eb3fd 100644 --- a/src/raw/services/pm.rs +++ b/src/raw/services/pm.rs @@ -1,6 +1,6 @@ use ::Result; -#[link(name = "ctru")] + extern "C" { pub fn pmInit() -> Result; pub fn pmExit() -> Result; diff --git a/src/raw/services/ptm.rs b/src/raw/services/ptm.rs index cc2e2cf..2743648 100644 --- a/src/raw/services/ptm.rs +++ b/src/raw/services/ptm.rs @@ -1,6 +1,6 @@ use ::{Result, Handle}; -#[link(name = "ctru")] + extern "C" { pub fn ptmInit() -> Result; pub fn ptmExit() -> Result; diff --git a/src/raw/services/soc.rs b/src/raw/services/soc.rs index d2df270..aff4f1d 100644 --- a/src/raw/services/soc.rs +++ b/src/raw/services/soc.rs @@ -1,6 +1,6 @@ use ::Result; -#[link(name = "ctru")] + extern "C" { pub fn SOC_Initialize(context_addr: *mut u32, context_size: u32) -> Result; pub fn SOC_Shutdown() -> Result; diff --git a/src/raw/vram.rs b/src/raw/vram.rs index 8d15466..2de9e2f 100644 --- a/src/raw/vram.rs +++ b/src/raw/vram.rs @@ -1,6 +1,6 @@ use super::types::*; -#[link(name = "ctru")] + extern "C" { pub fn vramAlloc(size: isize) -> *mut c_void; pub fn vramMemAlign(size: isize, alignment: isize) -> *mut c_void; diff --git a/src/services/apt.rs b/src/services/apt.rs index a1eee94..bed2ff0 100644 --- a/src/services/apt.rs +++ b/src/services/apt.rs @@ -96,15 +96,16 @@ pub fn return_to_menu() -> () { /// /// # Examples /// -/// ``` +/// ```rust /// main_loop(|| { /// // do things here +/// false /// }); /// ``` -pub fn main_loop(f: F) -> () where F : Fn() -> () { +pub fn main_loop(f: F) -> () where F : Fn() -> bool { unsafe { while apt::aptMainLoop() != 0 { - f(); + if !f() { break; } } } }