1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 00:46:34 +00:00

Move template to stdlib

This commit is contained in:
jam1garner 2020-04-12 19:34:43 -04:00
parent 271142d766
commit 100d7126c7
31 changed files with 38 additions and 21219 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
**/target
**/*.py
**/*.pyc
Cargo.lock

View file

@ -1,5 +1,5 @@
[package]
name = "no_std_test"
name = "skyline-rs-template"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
@ -8,6 +8,13 @@ edition = "2018"
crate-type = ["cdylib"]
[dependencies]
skyline = { path = "./skyline" }
skyline_smash = { path = "./skyline_smash" }
skyline = { git = "https://github.com/ultimate-research/skyline-rs.git" }
skyline_smash = { git = "https://github.com/ultimate-research/skyline-smash.git" }
[profile.dev]
opt-level = 0 # Use slightly better optimizations.
debug = 2
panic = "abort"
[profile.release]
panic = "abort"

View file

@ -1,2 +1,22 @@
[target.aarch64-skyline-switch.dependencies]
alloc = {}
[package]
rust-src = "../rust-std-skyline/src"
[dependencies.core]
path = "../rust-std-skyline/src/libcore"
#git = "https://github.com/jam1garner/rust-std-skyline-squashed.git"
stage = 0
[dependencies.alloc]
path = "../rust-std-skyline/src/liballoc"
#git = "https://github.com/jam1garner/rust-std-skyline-squashed.git"
stage = 0
[dependencies.std]
path = "../rust-std-skyline/src/libstd"
#git = "https://github.com/jam1garner/rust-std-skyline-squashed.git"
stage = 1
#[patch.crates-io]
#rustc-std-workspace-core = { git = 'https://github.com/jam1garner/rust-std-skyline-squashed.git', branch = 'master' }
#rustc-std-workspace-alloc = { git = 'https://github.com/jam1garner/rust-std-skyline-squashed.git', branch = 'master' }
#rustc-std-workspace-std = { git = 'https://github.com/jam1garner/rust-std-skyline-squashed.git', branch = 'master' }

View file

@ -21,7 +21,7 @@
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"os": "switch",
"panic-strategy": "unwind",
"panic-strategy": "abort",
"position-independent-executables": true,
"pre-link-args": {
"ld.lld": [

View file

@ -1 +1 @@
nightly
nightly-2020-04-10

91
skyline/Cargo.lock generated
View file

@ -1,91 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "build_const"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "crc"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nnsdk"
version = "0.1.0"
dependencies = [
"skyline_libc 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "skyline"
version = "0.0.1"
dependencies = [
"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nnsdk 0.1.0",
"skyline_libc 0.1.0",
"skyline_macro 0.1.0",
]
[[package]]
name = "skyline_libc"
version = "0.1.0"
[[package]]
name = "skyline_macro"
version = "0.1.0"
dependencies = [
"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
"checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"

View file

@ -1,12 +0,0 @@
[package]
name = "skyline"
version = "0.0.1"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
skyline_macro = { path = "./skyline_macro" }
nnsdk = { path = "./nnsdk" }
skyline_libc = { path = "./skyline_libc" }

View file

@ -1,12 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "nnsdk"
version = "0.1.0"
dependencies = [
"skyline_libc",
]
[[package]]
name = "skyline_libc"
version = "0.1.0"

View file

@ -1,10 +0,0 @@
[package]
name = "nnsdk"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
skyline_libc = { path = "../skyline_libc" }

View file

@ -1,29 +0,0 @@
use super::*;
impl TimeSpan {
pub fn nano(nanoseconds: u64) -> Self {
TimeSpan {
nanoseconds
}
}
pub fn milli(milliseconds: u64) -> Self {
TimeSpan {
nanoseconds: milliseconds * 1000000
}
}
pub fn secs(seconds: u64) -> Self {
TimeSpan {
nanoseconds: seconds * 1000000000u64
}
}
pub fn minutes(minutes: u64) -> Self {
TimeSpan::secs(minutes * 60)
}
pub fn hours(hours: u64) -> Self {
TimeSpan::minutes(hours * 60)
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,5 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "skyline_libc"
version = "0.1.0"

View file

@ -1,9 +0,0 @@
[package]
name = "skyline_libc"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View file

@ -1,313 +0,0 @@
#![no_std]
//! Public exports of libc functions
#![allow(non_camel_case_types)]
pub use core::ffi::c_void;
pub type c_char = u8;
pub type time_t = i32;
pub type wchar_t = u16;
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_float = f32;
pub type c_double = f64;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type intmax_t = i64;
pub type uintmax_t = u64;
pub type size_t = usize;
pub type ptrdiff_t = isize;
pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type ssize_t = isize;
pub type pid_t = i32;
pub type uid_t = u32;
pub type gid_t = u32;
pub type in_addr_t = u32;
pub type in_port_t = u16;
pub type mode_t = c_uint;
pub type off_t = i64;
#[repr(C)]
pub struct sem_t { // Unverified
__size: [c_char; 16],
}
pub type pthread_key_t = c_uint;
#[repr(C)]
pub struct tm {
pub tm_sec: c_int,
pub tm_min: c_int,
pub tm_hour: c_int,
pub tm_mday: c_int,
pub tm_mon: c_int,
pub tm_year: c_int,
pub tm_wday: c_int,
pub tm_yday: c_int,
pub tm_isdst: c_int,
}
#[allow(non_snake_case, non_upper_case_globals, dead_code)]
pub mod FileOpenMode {
pub const Write: *const u8 = "w\0".as_bytes().as_ptr();
pub const Read: *const u8 = "r\0".as_bytes().as_ptr();
pub const Append: *const u8 = "a\0".as_bytes().as_ptr();
pub const ReadUpdate: *const u8 = "r+\0".as_bytes().as_ptr();
pub const WriteUpdate: *const u8 = "w+\0".as_bytes().as_ptr();
pub const AppendUpdate: *const u8 = "a+\0".as_bytes().as_ptr();
}
#[derive(Debug, Clone, Copy)]
pub enum FILE {}
#[derive(Debug, Clone, Copy)]
pub enum DIR {}
extern "C" {
pub fn malloc(size: size_t) -> *const c_void;
pub fn free(ptr: *const c_void);
pub fn calloc(num: size_t, size: size_t) -> *const c_void;
pub fn realloc(ptr: *const c_void, size: size_t) -> *const c_void;
// fn aligned_alloc(align: usize, size: usize) -> *const c_void;
}
extern "C" {
pub fn isalnum(c: c_int) -> c_int;
pub fn isalpha(c: c_int) -> c_int;
pub fn iscntrl(c: c_int) -> c_int;
pub fn isdigit(c: c_int) -> c_int;
pub fn isgraph(c: c_int) -> c_int;
pub fn islower(c: c_int) -> c_int;
pub fn isprint(c: c_int) -> c_int;
pub fn ispunct(c: c_int) -> c_int;
pub fn isspace(c: c_int) -> c_int;
pub fn isupper(c: c_int) -> c_int;
pub fn isxdigit(c: c_int) -> c_int;
pub fn isblank(c: c_int) -> c_int;
pub fn tolower(c: c_int) -> c_int;
pub fn toupper(c: c_int) -> c_int;
pub fn qsort(
base: *mut c_void,
num: size_t,
size: size_t,
compar: Option<
unsafe extern "C" fn(*const c_void, *const c_void) -> c_int,
>,
);
pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
pub fn fflush(file: *mut FILE) -> c_int;
pub fn fclose(file: *mut FILE) -> c_int;
pub fn remove(filename: *const c_char) -> c_int;
pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
pub fn setvbuf(
stream: *mut FILE,
buffer: *mut c_char,
mode: c_int,
size: size_t,
) -> c_int;
pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
pub fn getchar() -> c_int;
pub fn putchar(c: c_int) -> c_int;
pub fn fgetc(stream: *mut FILE) -> c_int;
pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
pub fn puts(s: *const c_char) -> c_int;
pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
pub fn fwrite(
ptr: *const c_void,
size: size_t,
nobj: size_t,
stream: *mut FILE,
) -> size_t;
pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
pub fn ftell(stream: *mut FILE) -> c_long;
pub fn rewind(stream: *mut FILE);
pub fn perror(s: *const c_char);
pub fn atoi(s: *const c_char) -> c_int;
pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
pub fn strtol(
s: *const c_char,
endp: *mut *mut c_char,
base: c_int,
) -> c_long;
pub fn abort() -> !;
pub fn exit(status: c_int) -> !;
pub fn atexit(cb: extern "C" fn()) -> c_int;
pub fn getenv(s: *const c_char) -> *mut c_char;
pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
pub fn strncpy(
dst: *mut c_char,
src: *const c_char,
n: size_t,
) -> *mut c_char;
pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
pub fn strncat(
s: *mut c_char,
ct: *const c_char,
n: size_t,
) -> *mut c_char;
pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
pub fn strdup(cs: *const c_char) -> *mut c_char;
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
pub fn strncasecmp(
s1: *const c_char,
s2: *const c_char,
n: size_t,
) -> c_int;
pub fn strlen(cs: *const c_char) -> size_t;
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
pub fn strerror(n: c_int) -> *mut c_char;
pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
pub fn wcslen(buf: *const wchar_t) -> size_t;
pub fn wcstombs(
dest: *mut c_char,
src: *const wchar_t,
n: size_t,
) -> size_t;
pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
pub fn memcpy(
dest: *mut c_void,
src: *const c_void,
n: size_t,
) -> *mut c_void;
pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
pub fn fprintf(
stream: *mut FILE,
format: *const c_char,
...
) -> c_int;
pub fn printf(format: *const c_char, ...) -> c_int;
pub fn snprintf(
s: *mut c_char,
n: size_t,
format: *const c_char,
...
) -> c_int;
pub fn sprintf(s: *mut c_char, format: *const c_char, ...) -> c_int;
pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
pub fn access(path: *const c_char, amode: c_int) -> c_int;
pub fn chdir(dir: *const c_char) -> c_int;
pub fn close(fd: c_int) -> c_int;
pub fn getpid() -> pid_t;
pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
pub fn posix_memalign(
memptr: *mut *mut c_void,
align: size_t,
size: size_t,
) -> c_int;
pub fn rmdir(path: *const c_char) -> c_int;
pub fn sleep(secs: c_uint) -> c_uint;
pub fn read(fd: c_int, buf: *mut c_void, count: size_t)
-> ssize_t;
pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
pub fn unlink(c: *const c_char) -> c_int;
pub fn write(
fd: c_int,
buf: *const c_void,
count: size_t,
) -> ssize_t;
pub fn pwrite(
fd: c_int,
buf: *const c_void,
count: size_t,
offset: off_t,
) -> ssize_t;
pub fn setenv(
name: *const c_char,
val: *const c_char,
overwrite: c_int,
) -> c_int;
pub fn unsetenv(name: *const c_char) -> c_int;
pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
pub fn sched_yield() -> c_int;
pub fn pthread_setspecific(
key: pthread_key_t,
value: *const c_void,
) -> c_int;
pub fn mktime(tm: *mut tm) -> time_t;
pub fn time(time: *mut time_t) -> time_t;
pub fn gmtime(time_p: *const time_t) -> *mut tm;
pub fn localtime(time_p: *const time_t) -> *mut tm;
pub fn difftime(time1: time_t, time0: time_t) -> c_double;
pub fn putenv(string: *mut c_char) -> c_int;
pub fn setlocale(
category: c_int,
locale: *const c_char,
) -> *mut c_char;
pub fn sem_wait(sem: *mut sem_t) -> c_int;
pub fn sem_trywait(sem: *mut sem_t) -> c_int;
pub fn sem_post(sem: *mut sem_t) -> c_int;
pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
pub fn getline(
lineptr: *mut *mut c_char,
n: *mut size_t,
stream: *mut FILE,
) -> ssize_t;
pub fn fdopendir(fd: c_int) -> *mut DIR;
}
pub fn fwrite_slice<T: Sized>(slice: &[T], stream: *mut FILE) -> size_t {
unsafe {
fwrite(
slice.as_ptr() as _,
core::mem::size_of::<T>(),
slice.len(),
stream
)
}
}

View file

@ -1,52 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "proc-macro2"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "skyline_macro"
version = "0.1.0"
dependencies = [
"lazy_static",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"

View file

@ -1,16 +0,0 @@
[package]
name = "skyline_macro"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
[lib]
proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
syn = { version = "1", features = ["full", "extra-traits"] }
quote = "1"
proc-macro2 = "1"
lazy_static = "1.4"

View file

@ -1,39 +0,0 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
pub struct Attrs {
name: String,
}
impl Parse for Attrs {
fn parse(input: ParseStream) -> syn::Result<Self> {
let meta: syn::MetaNameValue = match input.parse() {
Ok(x) => x,
Err(_) => return Ok(Attrs { name: "skyline_rust_plugin".into() })
};
if meta.path.get_ident().unwrap().to_string() == "name" {
match meta.lit {
syn::Lit::Str(string) => {
Ok(Attrs {
name: string.value()
})
}
_ => panic!("Invalid literal, must be a string")
}
} else {
panic!("Attributes other than 'name' not allowed");
}
}
}
impl ToTokens for Attrs {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let name = &self.name[..];
quote::quote!(
::skyline::set_module_name!(#name);
).to_tokens(tokens);
}
}

View file

@ -1,127 +0,0 @@
use quote::{ToTokens, quote};
use proc_macro::TokenStream;
use syn::{parse_macro_input, token, Ident, AttrStyle, Lit, spanned::Spanned};
use proc_macro2::{Span, TokenStream as TokenStream2};
mod attributes;
fn new_attr(attr_name: &str) -> syn::Attribute {
syn::Attribute {
pound_token: token::Pound { spans: [Span::call_site()] },
style: AttrStyle::Outer,
bracket_token: token::Bracket { span: Span::call_site() },
path: Ident::new(attr_name, Span::call_site()).into(),
tokens: TokenStream2::new()
}
}
#[proc_macro_attribute]
pub fn main(attrs: TokenStream, item: TokenStream) -> TokenStream {
let mut main_function = parse_macro_input!(item as syn::ItemFn);
let attr_code = parse_macro_input!(attrs as attributes::Attrs);
main_function.attrs.push(
new_attr("no_mangle")
);
main_function.sig.ident = Ident::new("main", Span::call_site());
let mut output = TokenStream2::new();
quote!(
#attr_code
use skyline::prelude::*;
::skyline::setup!();
).to_tokens(&mut output);
main_function.to_tokens(&mut output);
output.into()
}
#[proc_macro_attribute]
pub fn hook(_: TokenStream, input: TokenStream) -> TokenStream {
let mut mod_fn = parse_macro_input!(input as syn::ItemFn);
let mut output = TokenStream2::new();
// #[no_mangle]
mod_fn.attrs.push(
new_attr("no_mangle")
);
// extern "C"
mod_fn.sig.abi = Some(syn::Abi {
extern_token: syn::token::Extern { span: Span::call_site() },
name: Some(syn::LitStr::new("C", Span::call_site()))
});
mod_fn.to_tokens(&mut output);
let mod_fn = mod_fn.sig.ident;
let _info = quote::format_ident!(
"{}_skyline_internal_hook_info",
mod_fn
);
let _hook = quote::format_ident!(
"{}_skyline_internal_hook",
mod_fn
);
quote!(
/*#[allow(non_upper_case_globals)]
static #info: ::skyline::hooks::HookInfo = ::skyline::hooks::HookInfo {
name: None,
fn_name: stringify!(#mod_fn),
offset: None,
symbol: None,
inline: false
};
#[allow(non_upper_case_globals)]
#[link_section = ".rodata.hooks"]
static #hook: ::skyline::hooks::Hook = ::skyline::hooks::Hook{
ptr: #mod_fn as *const (),
info: &#info
};*/
).to_tokens(&mut output);
output.into()
}
fn lit_to_bytes(lit: &Lit) -> Option<Vec<u8>> {
match lit {
Lit::Str(lit_str) => {
Some(lit_str.value().into_bytes())
}
Lit::ByteStr(lit_str) => {
Some(lit_str.value())
}
_ => {
None
}
}
}
#[proc_macro]
pub fn to_null_term_bytes(input: TokenStream) -> TokenStream {
let expr = parse_macro_input!(input as Lit);
match lit_to_bytes(&expr) {
Some(mut bytes) => {
bytes.push(0);
let bytes = syn::LitByteStr::new(&bytes, expr.span());
TokenStream::from(quote! {
(#bytes)
})
}
None => {
let span = expr.span();
TokenStream::from(quote::quote_spanned!{span =>
compile_error!("Invalid literal");
})
}
}
}

View file

@ -1,65 +0,0 @@
#[lang = "eh_personality"]
extern fn eh_personality() {}
#[macro_export] macro_rules! install_panic_handler {
($module_name:expr) => {
#[panic_handler]
fn panic(panic_info: &core::panic::PanicInfo) -> ! {
$crate::println!("{} panicked: {}", $module_name, panic_info);
loop {
unsafe {
$crate::nn::os::SleepThread(
$crate::nn::TimeSpan::milli(100)
)
}
}
}
};
}
global_asm!(include_str!("mod0.s"));
#[no_mangle] pub unsafe extern "C" fn __custom_init() {}
#[no_mangle] pub extern "C" fn __custom_fini() {}
#[macro_export] macro_rules! set_module_name {
($lit:literal) => {
::skyline::install_panic_handler!($lit);
const __SKYLINE_INTERNAL_MODULE_LEN: usize = $lit.len() + 1;
#[link_section = ".rodata.module_name"]
pub static __MODULE_NAME: ::skyline::build::ModuleName<__SKYLINE_INTERNAL_MODULE_LEN> =
::skyline::build::ModuleName::new(
::skyline::skyline_macro::to_null_term_bytes!($lit)
);
};
}
#[repr(packed)]
#[allow(unused_variables)]
pub struct ModuleName<const LEN: usize> {
pub unk: u32,
pub name_length: u32,
pub name: [u8; LEN],
}
impl<const LEN: usize> ModuleName<LEN> {
pub const fn new(bytes: &[u8; LEN]) -> Self {
Self {
unk: 0,
name_length: LEN as u32 - 1,
name: *bytes,
}
}
}
/// one-time setup for skyline
#[doc(hidden)]
#[macro_export] macro_rules! setup {
() => {
#[global_allocator]
pub static ALLOCATOR: $crate::extern_alloc::Allocator = $crate::extern_alloc::Allocator;
};
}

View file

@ -1,31 +0,0 @@
use core::alloc::{GlobalAlloc, Layout};
use crate::libc;
pub struct Allocator;
unsafe impl GlobalAlloc for Allocator {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
libc::malloc(layout.size()) as *mut u8
}
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
libc::calloc(layout.size(), 1) as *mut u8
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
libc::free(ptr as *mut libc::c_void)
}
#[inline]
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 {
libc::realloc(ptr as *mut libc::c_void, new_size) as *mut u8
}
}
#[alloc_error_handler]
fn _alloc_error(_layout: Layout) -> ! {
panic!("Allocation error");
}

View file

@ -1,63 +0,0 @@
use crate::alloc::string::String;
pub struct HookInfo {
/// Name of the function being used as the override
pub fn_name: &'static str,
/// User-given name of what the hook represents
pub name: Option<String>,
/// Offset of where to install the hook
pub offset: Option<u64>,
/// Symbol of where to install the hook
pub symbol: Option<String>,
/// Whether or not this is an inline hook
pub inline: bool
}
/// Type for representing a hook for this plugin
pub struct Hook {
/// Pointer to the overloading function
pub ptr: *const (),
/// Info needed to identify and install this hook
pub info: &'static HookInfo,
}
unsafe impl Sync for Hook {
}
impl Hook {
pub fn install(&self) {
todo!()
}
}
#[allow(improper_ctypes)]
extern "C" {
static __hook_array_start: Hook;
static __hook_array_end: Hook;
}
/// Iterate over the loaded hooks for this plugin
pub fn iter_hooks() -> impl Iterator<Item = &'static Hook> {
let hook_start = unsafe {&__hook_array_start as *const Hook};
let hook_end = unsafe {&__hook_array_end as *const Hook};
let hook_count = ((hook_start as usize) - (hook_end as usize)) / core::mem::size_of::<Hook>();
crate::println!("hook_count: {}", hook_count);
crate::println!("hook_start: {:?}", hook_start);
crate::println!("hook_end: {:?}", hook_start);
unsafe {
core::slice::from_raw_parts(
hook_start,
hook_count
)
}.iter()
}

View file

@ -1,47 +0,0 @@
#![no_std]
#![allow(incomplete_features)]
#![feature(alloc_error_handler, lang_items, start, global_asm, const_generics, impl_trait_in_bindings, proc_macro_hygiene, alloc_prelude, panic_info_message)]
/// The rust core allocation and collections library
pub extern crate alloc;
#[doc(hidden)]
pub use skyline_macro;
/// Types and functions for working with hooking
pub mod hooks;
pub mod logging;
#[doc(hidden)]
pub mod extern_alloc;
#[doc(hidden)]
pub mod build;
// nnsdk API bindings
pub mod nn;
#[doc(inline)]
pub use {
skyline_libc as libc,
skyline_macro::{main, hook},
hooks::iter_hooks,
};
/// Helper to convert a str to a *const u8 (to be replaced)
pub fn c_str(string: &str) -> *const u8 {
string.as_bytes().as_ptr()
}
/// A set of items that will likely be useful to import anyway
///
/// Designed to be used as such:
/// ```
/// use skyline::prelude::*;
/// ```
pub mod prelude {
pub use crate::println;
pub use alloc::format;
pub use alloc::vec;
pub use crate::alloc::prelude::v1::*;
}

View file

@ -1,24 +0,0 @@
extern "C" {
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
}
pub fn log(message: &str) {
unsafe {
skyline_tcp_send_raw(message.as_bytes().as_ptr(), message.as_bytes().len() as _);
}
}
/// Prints to the standard output, with a newline.
#[macro_export] macro_rules! println {
() => {
$crate::log();
};
($($arg:tt)*) => {
{
use $crate::alloc::format;
$crate::logging::log(&format!(
$($arg)*
));
}
};
}

View file

@ -1,24 +0,0 @@
.section .nro_header
.global __nro_header_start
.word 0
.word _mod_header
.word 0
.word 0
.section .rodata.mod0
.global _mod_header
_mod_header:
.ascii "MOD0"
.word __dynamic_start - _mod_header
.word __bss_start - _mod_header
.word __bss_end - _mod_header
.word __eh_frame_hdr_start - _mod_header
.word __eh_frame_hdr_end - _mod_header
.word __nx_module_runtime - _mod_header // runtime-generated module object offset
.global IS_NRO
IS_NRO:
.word 1
.section .bss.module_runtime
.space 0xD0

View file

@ -1,2 +0,0 @@
pub use nnsdk::root::nn::*;
pub use nnsdk::extensions::*;

View file

@ -1,12 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "skyline_libc"
version = "0.1.0"
[[package]]
name = "skyline_smash"
version = "0.1.0"
dependencies = [
"skyline_libc",
]

View file

@ -1,13 +0,0 @@
[package]
name = "skyline_smash"
version = "0.1.0"
authors = ["jam1garner <jam1.mcleod@hotmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "smash"
[dependencies]
skyline_libc = { path = "../skyline/skyline_libc" }

File diff suppressed because it is too large Load diff

View file

@ -1,66 +0,0 @@
/// const crc32 implementation by leo60288
macro_rules! reflect {
($bits:expr, $value:expr) => {{
let mut reflection = 0;
let mut value = $value;
let mut i = 0;
while i < $bits {
if (value & 0x01) == 1 {
reflection |= 1 << (($bits - 1) - i)
}
value >>= 1;
i += 1;
}
reflection
}};
}
const fn make_table(poly: u32) -> [u32; 256] {
let mut table = [0; 256];
let top_bit = 1 << 31;
let mut byte;
let mut i = 0;
while i <= 255 {
byte = reflect!(8, i);
let mut value = byte << 24;
let mut j = 0;
while j < 8 {
if (value & top_bit) != 0 {
value = (value << 1) ^ poly
} else {
value <<= 1
}
j += 1;
}
value = reflect!(32, value);
table[i as usize] = value;
i += 1;
}
table
}
const IEEE_TABLE: [u32; 256] = make_table(0x04C11DB7);
pub const fn crc32(bytes: &[u8]) -> u32 {
let mut value = !0u32;
let mut i = 0;
while i < bytes.len() {
value = (value >> 8) ^ (IEEE_TABLE[((value ^ (bytes[i] as u32)) & 0xFF) as usize]);
i += 1;
}
!value
}

View file

@ -1,18 +0,0 @@
#![no_std]
#![feature(const_if_match, const_loop)]
pub mod crc32;
#[doc(hidden)]
pub mod cpp;
#[doc(inline)]
pub use cpp::root::*;
// Find the hash40 of a given string
pub const fn hash40(string: &str) -> u64 {
let bytes = string.as_bytes();
((bytes.len() as u64) << 32) + crc32::crc32(bytes) as u64
}

View file

@ -1,4 +1,3 @@
#![no_std]
#![feature(proc_macro_hygiene)]
use skyline::nn::account::{self, Uid, GetLastOpenedUser, GetNickname, Nickname};
@ -6,7 +5,7 @@ use smash::hash40;
#[skyline::main(name = "module_name_test")]
pub fn main() {
println!("Hello from Skyline Rust Plugin!\n");
println!("Hello from Skyline Rust Plugin!");
for i in 0..3 {
println!("{}", i);
@ -16,6 +15,8 @@ pub fn main() {
println!("Last nickname: {}", nickname);
println!("Contents of file: {:?}", std::fs::read_to_string("sd:/test.txt"));
println!("Compile-time hash40 of 'accel_x': {:010X}", hash40("accel_x"));
let string = "accel_x";