├── .gitignore ├── .travis.yml ├── AUTHORS.md ├── README.md ├── ctr-std ├── Cargo.toml ├── README.md └── src │ ├── alloc.rs │ ├── ascii.rs │ ├── build.rs │ ├── collections │ ├── hash │ │ ├── bench.rs │ │ ├── map.rs │ │ ├── mod.rs │ │ ├── set.rs │ │ └── table.rs │ └── mod.rs │ ├── env.rs │ ├── error.rs │ ├── f32.rs │ ├── f64.rs │ ├── ffi │ ├── c_str.rs │ ├── mod.rs │ └── os_str.rs │ ├── fs.rs │ ├── future.rs │ ├── io │ ├── buffered.rs │ ├── cursor.rs │ ├── error.rs │ ├── impls.rs │ ├── lazy.rs │ ├── mod.rs │ ├── prelude.rs │ ├── stdio.rs │ └── util.rs │ ├── keyword_docs.rs │ ├── lib.rs │ ├── macros.rs │ ├── memchr.rs │ ├── net │ ├── addr.rs │ ├── ip.rs │ ├── mod.rs │ ├── parser.rs │ ├── tcp.rs │ ├── test.rs │ └── udp.rs │ ├── num.rs │ ├── os │ ├── android │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── bitrig │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── dragonfly │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── emscripten │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── freebsd │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── fuchsia │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── haiku │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── hermit │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── horizon │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── ios │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── linux │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── macos │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── mod.rs │ ├── netbsd │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── openbsd │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── raw │ │ ├── char.md │ │ ├── double.md │ │ ├── float.md │ │ ├── int.md │ │ ├── long.md │ │ ├── longlong.md │ │ ├── mod.rs │ │ ├── schar.md │ │ ├── short.md │ │ ├── uchar.md │ │ ├── uint.md │ │ ├── ulong.md │ │ ├── ulonglong.md │ │ └── ushort.md │ └── solaris │ │ ├── fs.rs │ │ ├── mod.rs │ │ └── raw.rs │ ├── panic.rs │ ├── panicking.rs │ ├── path.rs │ ├── prelude │ ├── mod.rs │ └── v1.rs │ ├── primitive_docs.rs │ ├── process.rs │ ├── rt.rs │ ├── sync │ ├── barrier.rs │ ├── condvar.rs │ ├── mod.rs │ ├── mpsc │ │ ├── blocking.rs │ │ ├── cache_aligned.rs │ │ ├── mod.rs │ │ ├── mpsc_queue.rs │ │ ├── oneshot.rs │ │ ├── select.rs │ │ ├── shared.rs │ │ ├── spsc_queue.rs │ │ ├── stream.rs │ │ └── sync.rs │ ├── mutex.rs │ ├── once.rs │ └── rwlock.rs │ ├── sys │ ├── cloudabi │ │ ├── abi │ │ │ ├── bitflags.rs │ │ │ ├── cloudabi.rs │ │ │ └── mod.rs │ │ ├── args.rs │ │ ├── backtrace.rs │ │ ├── condvar.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── os.rs │ │ ├── rwlock.rs │ │ ├── shims │ │ │ ├── args.rs │ │ │ ├── env.rs │ │ │ ├── fs.rs │ │ │ ├── mod.rs │ │ │ ├── net.rs │ │ │ ├── os.rs │ │ │ ├── pipe.rs │ │ │ └── process.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── thread.rs │ │ └── time.rs │ ├── horizon │ │ ├── android.rs │ │ ├── args.rs │ │ ├── backtrace │ │ │ ├── mod.rs │ │ │ ├── printing │ │ │ │ ├── dladdr.rs │ │ │ │ └── mod.rs │ │ │ └── tracing │ │ │ │ ├── backtrace_fn.rs │ │ │ │ ├── gcc_s.rs │ │ │ │ └── mod.rs │ │ ├── cmath.rs │ │ ├── condvar.rs │ │ ├── env.rs │ │ ├── ext │ │ │ ├── ffi.rs │ │ │ ├── fs.rs │ │ │ ├── io.rs │ │ │ ├── mod.rs │ │ │ └── raw.rs │ │ ├── fast_thread_local.rs │ │ ├── fd.rs │ │ ├── fs.rs │ │ ├── l4re.rs │ │ ├── memchr.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── net.rs │ │ ├── os.rs │ │ ├── os_str.rs │ │ ├── path.rs │ │ ├── pipe.rs │ │ ├── process.rs │ │ ├── rand.rs │ │ ├── rwlock.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── thread.rs │ │ ├── thread_local.rs │ │ ├── time.rs │ │ └── weak.rs │ ├── mod.rs │ ├── redox │ │ ├── args.rs │ │ ├── backtrace │ │ │ ├── mod.rs │ │ │ ├── printing.rs │ │ │ └── tracing.rs │ │ ├── cmath.rs │ │ ├── condvar.rs │ │ ├── env.rs │ │ ├── ext │ │ │ ├── ffi.rs │ │ │ ├── fs.rs │ │ │ ├── io.rs │ │ │ ├── mod.rs │ │ │ ├── net.rs │ │ │ ├── process.rs │ │ │ └── thread.rs │ │ ├── fast_thread_local.rs │ │ ├── fd.rs │ │ ├── fs.rs │ │ ├── memchr.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── net │ │ │ ├── dns │ │ │ │ ├── answer.rs │ │ │ │ ├── mod.rs │ │ │ │ └── query.rs │ │ │ ├── mod.rs │ │ │ ├── netc.rs │ │ │ ├── tcp.rs │ │ │ └── udp.rs │ │ ├── os.rs │ │ ├── os_str.rs │ │ ├── path.rs │ │ ├── pipe.rs │ │ ├── process.rs │ │ ├── rand.rs │ │ ├── rwlock.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── syscall │ │ │ ├── arch │ │ │ │ ├── arm.rs │ │ │ │ ├── x86.rs │ │ │ │ └── x86_64.rs │ │ │ ├── call.rs │ │ │ ├── data.rs │ │ │ ├── error.rs │ │ │ ├── flag.rs │ │ │ ├── mod.rs │ │ │ └── number.rs │ │ ├── thread.rs │ │ ├── thread_local.rs │ │ └── time.rs │ ├── unix │ │ ├── android.rs │ │ ├── args.rs │ │ ├── backtrace │ │ │ ├── mod.rs │ │ │ ├── printing │ │ │ │ ├── dladdr.rs │ │ │ │ └── mod.rs │ │ │ └── tracing │ │ │ │ ├── backtrace_fn.rs │ │ │ │ ├── gcc_s.rs │ │ │ │ └── mod.rs │ │ ├── cmath.rs │ │ ├── condvar.rs │ │ ├── env.rs │ │ ├── ext │ │ │ ├── ffi.rs │ │ │ ├── fs.rs │ │ │ ├── io.rs │ │ │ ├── mod.rs │ │ │ ├── net.rs │ │ │ ├── process.rs │ │ │ ├── raw.rs │ │ │ └── thread.rs │ │ ├── fast_thread_local.rs │ │ ├── fd.rs │ │ ├── fs.rs │ │ ├── l4re.rs │ │ ├── memchr.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── net.rs │ │ ├── os.rs │ │ ├── os_str.rs │ │ ├── path.rs │ │ ├── pipe.rs │ │ ├── process │ │ │ ├── mod.rs │ │ │ ├── process_common.rs │ │ │ ├── process_fuchsia.rs │ │ │ ├── process_unix.rs │ │ │ └── zircon.rs │ │ ├── rand.rs │ │ ├── rwlock.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── thread.rs │ │ ├── thread_local.rs │ │ ├── time.rs │ │ └── weak.rs │ ├── wasm │ │ ├── args.rs │ │ ├── backtrace.rs │ │ ├── cmath.rs │ │ ├── condvar.rs │ │ ├── env.rs │ │ ├── fs.rs │ │ ├── memchr.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── net.rs │ │ ├── os.rs │ │ ├── os_str.rs │ │ ├── path.rs │ │ ├── pipe.rs │ │ ├── process.rs │ │ ├── rwlock.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── thread.rs │ │ ├── thread_local.rs │ │ └── time.rs │ └── windows │ │ ├── args.rs │ │ ├── backtrace │ │ ├── backtrace_gnu.rs │ │ ├── mod.rs │ │ └── printing │ │ │ ├── mod.rs │ │ │ └── msvc.rs │ │ ├── c.rs │ │ ├── cmath.rs │ │ ├── compat.rs │ │ ├── condvar.rs │ │ ├── dynamic_lib.rs │ │ ├── env.rs │ │ ├── ext │ │ ├── ffi.rs │ │ ├── fs.rs │ │ ├── io.rs │ │ ├── mod.rs │ │ ├── process.rs │ │ ├── raw.rs │ │ └── thread.rs │ │ ├── fast_thread_local.rs │ │ ├── fs.rs │ │ ├── handle.rs │ │ ├── memchr.rs │ │ ├── mod.rs │ │ ├── mutex.rs │ │ ├── net.rs │ │ ├── os.rs │ │ ├── os_str.rs │ │ ├── path.rs │ │ ├── pipe.rs │ │ ├── process.rs │ │ ├── rand.rs │ │ ├── rwlock.rs │ │ ├── stack_overflow.rs │ │ ├── stdio.rs │ │ ├── thread.rs │ │ ├── thread_local.rs │ │ └── time.rs │ ├── sys_common │ ├── at_exit_imp.rs │ ├── backtrace.rs │ ├── bytestring.rs │ ├── condvar.rs │ ├── gnu │ │ ├── libbacktrace.rs │ │ └── mod.rs │ ├── io.rs │ ├── mod.rs │ ├── mutex.rs │ ├── net.rs │ ├── poison.rs │ ├── process.rs │ ├── remutex.rs │ ├── rwlock.rs │ ├── thread.rs │ ├── thread_info.rs │ ├── thread_local.rs │ ├── util.rs │ └── wtf8.rs │ ├── tests │ └── env.rs │ ├── thread │ ├── local.rs │ └── mod.rs │ └── time.rs ├── ctru-rs ├── Cargo.toml ├── README.md └── src │ ├── applets │ ├── mod.rs │ └── swkbd.rs │ ├── console.rs │ ├── error.rs │ ├── gfx.rs │ ├── lib.rs │ ├── sdmc.rs │ ├── services │ ├── apt.rs │ ├── fs.rs │ ├── gspgpu.rs │ ├── hid.rs │ ├── mod.rs │ ├── soc.rs │ └── sslc.rs │ ├── srv.rs │ └── thread.rs ├── ctru-sys ├── Cargo.toml ├── bindgen.sh ├── build.rs └── src │ ├── bindings.rs │ └── lib.rs └── examples ├── .cargo └── config ├── 3ds.json ├── Cargo.toml ├── Xargo.toml └── src └── bin ├── buttons.rs ├── hello-both-screens.rs ├── hello-world.rs └── software-keyboard.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | 3 | rust: 4 | - nightly-2018-08-18 5 | 6 | install: 7 | - set -eo pipefail 8 | - pushd /tmp 9 | 10 | # Install DevkitARM 11 | - export DEVKITPRO="/opt/devkitpro" 12 | - export DEVKITARM="$DEVKITPRO/devkitARM" 13 | - export PATH="$PATH:$DEVKITARM/bin" 14 | - wget https://github.com/devkitPro/pacman/releases/download/v1.0.0/devkitpro-pacman.deb 15 | - sudo dpkg -i devkitpro-pacman.deb 16 | - sudo dkp-pacman -S --noconfirm devkitARM libctru 17 | 18 | # Install Xargo 19 | - cargo install xargo 20 | 21 | # Install Rust source 22 | - rustup component add rust-src 23 | - popd 24 | 25 | script: 26 | - cd examples 27 | - export CC_3ds="arm-none-eabi-gcc" 28 | - export TARGET_CFLAGS="-mfloat-abi=hard -march=armv6k" 29 | - RUST_TARGET_PATH=$(pwd) xargo build --release 30 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Authors 2 | 3 | * [Eidolon](https://github.com/HybridEidolon) 4 | * [FenrirWolf](https://github.com/FenrirWolf) 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | This repository has been deprecated in favour of the new `ctru-rs` version of the Rust3DS toolchain. For more information about the new tools and libraries, check [ctru-rs](https://github.com/rust3ds/ctru-rs). 3 | 4 | # ctru-rs 5 | 6 | A Rust wrapper library for smealum's [ctrulib](https://github.com/smealum/ctrulib). 7 | 8 | See the [3DS project template](https://github.com/rust3ds/rust3ds-template) for instructions on how to use this library. 9 | 10 | ## Structure 11 | 12 | This repository is organized as follows: 13 | * `ctru-rs`: Safe, idiomatic wrapper around `ctru-sys`. 14 | * `ctru-sys`: Low-level, unsafe bindings to ctrulib 15 | * `ctr-std`: A partial implementation of the Rust standard library for the 3DS. 16 | 17 | ## License 18 | 19 | Copyright (C) Rust 3DS Project authors, 2015-2016 20 | 21 | See AUTHORS.md. 22 | 23 | As with the original ctrulib, this library is licensed under zlib. This 24 | applies to every file in the tree, unless otherwise noted. 25 | 26 | This software is provided 'as-is', without any express or implied 27 | warranty. In no event will the authors be held liable for any 28 | damages arising from the use of this software. 29 | 30 | Permission is granted to anyone to use this software for any 31 | purpose, including commercial applications, and to alter it and 32 | redistribute it freely, subject to the following restrictions: 33 | 34 | 1. The origin of this software must not be misrepresented; you 35 | must not claim that you wrote the original software. If you use 36 | this software in a product, an acknowledgment in the product 37 | documentation would be appreciated but is not required. 38 | 2. Altered source versions must be plainly marked as such, and 39 | must not be misrepresented as being the original software. 40 | 3. This notice may not be removed or altered from any source 41 | distribution. 42 | 43 | Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses. 44 | 45 | See [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE), [LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT), and [COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) for details. 46 | 47 | -------------------------------------------------------------------------------- /ctr-std/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "std" 3 | version = "0.0.0" 4 | license = "MIT/Apache 2.0" 5 | 6 | [dependencies.alloc_system] 7 | git = "https://github.com/rust3ds/alloc_system3ds" 8 | 9 | [dependencies.ctru-sys] 10 | path = "../ctru-sys" 11 | default-features = false 12 | features = ["stdbuild"] 13 | -------------------------------------------------------------------------------- /ctr-std/README.md: -------------------------------------------------------------------------------- 1 | A work-in-progress port of the Rust Standard Library for the Nintendo 3DS, based on [ctrulib](https://github.com/smealum/ctrulib/) and the [devkitARM](http://devkitPro.org) toolchain. 2 | 3 | ## Structure 4 | 5 | This library aims to mimick the Rust standard library's public interface as closely as possible, exposing functionality that is common between the 3DS and other platforms. System-specific functionality such as control input, save file management, GPU features, and so forth are implemented in `ctru-rs`. 6 | 7 | ## Working modules 8 | 9 | * `any` 10 | * `ascii` 11 | * `borrow` 12 | * `boxed` 13 | * `cell` 14 | * `char` 15 | * `clone` 16 | * `cmp` 17 | * `collections` 18 | * `convert` 19 | * `default` 20 | * `error` 21 | * `f32` 22 | * `f64` 23 | * `ffi` 24 | * `fmt` 25 | * `fs` Both `sdmc:/` and `romfs:/` paths are supported in standard file operations 26 | * `hash` 27 | * `i8` 28 | * `i16` 29 | * `i32` 30 | * `i64` 31 | * `io` 32 | * `isize` 33 | * `iter` 34 | * `marker` 35 | * `mem` 36 | * `num` 37 | * `ops` 38 | * `option` 39 | * `panic` 40 | * `path` 41 | * `prelude` 42 | * `ptr` 43 | * `rc` 44 | * `result` 45 | * `slice` 46 | * `str` 47 | * `string` 48 | * `sync` 49 | * `time` 50 | * `thread` Threads are able to be spawned, but without the ability to pin to a specific core or set thread priority 51 | * `u8` 52 | * `u16` 53 | * `u32` 54 | * `u64` 55 | * `usize` 56 | * `vec` 57 | * `heap` 58 | * `i128` 59 | * `intrinsics` 60 | * `raw` 61 | * `u128` 62 | 63 | # Partially working modules 64 | * `net` Anything not involving IPv6 should work after initializing the `Soc` service in `ctru-rs` 65 | * `os` The modules in here should work, but they aren't well-tested 66 | 67 | # Non-working modules 68 | * `env` argc/argv can be implemented but have not been yet 69 | * `process` Unable to be implemented due to platform incompatibilities 70 | -------------------------------------------------------------------------------- /ctr-std/src/collections/hash/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Unordered containers, implemented as hash-tables 12 | 13 | mod bench; 14 | mod table; 15 | pub mod map; 16 | pub mod set; 17 | 18 | trait Recover { 19 | type Key; 20 | 21 | fn get(&self, key: &Q) -> Option<&Self::Key>; 22 | fn take(&mut self, key: &Q) -> Option; 23 | fn replace(&mut self, key: Self::Key) -> Option; 24 | } 25 | -------------------------------------------------------------------------------- /ctr-std/src/io/lazy.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::Cell; 12 | use ptr; 13 | use sync::Arc; 14 | use sys_common; 15 | use sys_common::mutex::Mutex; 16 | 17 | pub struct Lazy { 18 | // We never call `lock.init()`, so it is UB to attempt to acquire this mutex reentrantly! 19 | lock: Mutex, 20 | ptr: Cell<*mut Arc>, 21 | init: fn() -> Arc, 22 | } 23 | 24 | #[inline] 25 | const fn done() -> *mut Arc { 1_usize as *mut _ } 26 | 27 | unsafe impl Sync for Lazy {} 28 | 29 | impl Lazy { 30 | /// Safety: `init` must not call `get` on the variable that is being 31 | /// initialized. 32 | pub const unsafe fn new(init: fn() -> Arc) -> Lazy { 33 | Lazy { 34 | lock: Mutex::new(), 35 | ptr: Cell::new(ptr::null_mut()), 36 | init, 37 | } 38 | } 39 | 40 | pub fn get(&'static self) -> Option> { 41 | unsafe { 42 | let _guard = self.lock.lock(); 43 | let ptr = self.ptr.get(); 44 | if ptr.is_null() { 45 | Some(self.init()) 46 | } else if ptr == done() { 47 | None 48 | } else { 49 | Some((*ptr).clone()) 50 | } 51 | } 52 | } 53 | 54 | // Must only be called with `lock` held 55 | unsafe fn init(&'static self) -> Arc { 56 | // If we successfully register an at exit handler, then we cache the 57 | // `Arc` allocation in our own internal box (it will get deallocated by 58 | // the at exit handler). Otherwise we just return the freshly allocated 59 | // `Arc`. 60 | let registered = sys_common::at_exit(move || { 61 | let ptr = { 62 | let _guard = self.lock.lock(); 63 | self.ptr.replace(done()) 64 | }; 65 | drop(Box::from_raw(ptr)) 66 | }); 67 | // This could reentrantly call `init` again, which is a problem 68 | // because our `lock` allows reentrancy! 69 | // That's why `new` is unsafe and requires the caller to ensure no reentrancy happens. 70 | let ret = (self.init)(); 71 | if registered.is_ok() { 72 | self.ptr.set(Box::into_raw(Box::new(ret.clone()))); 73 | } 74 | ret 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ctr-std/src/io/prelude.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! The I/O Prelude 12 | //! 13 | //! The purpose of this module is to alleviate imports of many common I/O traits 14 | //! by adding a glob import to the top of I/O heavy modules: 15 | //! 16 | //! ``` 17 | //! # #![allow(unused_imports)] 18 | //! use std::io::prelude::*; 19 | //! ``` 20 | 21 | #![stable(feature = "rust1", since = "1.0.0")] 22 | 23 | #[stable(feature = "rust1", since = "1.0.0")] 24 | pub use super::{Read, Write, BufRead, Seek}; 25 | -------------------------------------------------------------------------------- /ctr-std/src/keyword_docs.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #[doc(keyword = "fn")] 12 | // 13 | /// The `fn` keyword. 14 | /// 15 | /// The `fn` keyword is used to declare a function. 16 | /// 17 | /// Example: 18 | /// 19 | /// ```rust 20 | /// fn some_function() { 21 | /// // code goes in here 22 | /// } 23 | /// ``` 24 | /// 25 | /// For more information about functions, take a look at the [Rust Book][book]. 26 | /// 27 | /// [book]: https://doc.rust-lang.org/book/second-edition/ch03-03-how-functions-work.html 28 | mod fn_keyword { } 29 | 30 | #[doc(keyword = "let")] 31 | // 32 | /// The `let` keyword. 33 | /// 34 | /// The `let` keyword is used to declare a variable. 35 | /// 36 | /// Example: 37 | /// 38 | /// ```rust 39 | /// # #![allow(unused_assignments)] 40 | /// let x = 3; // We create a variable named `x` with the value `3`. 41 | /// ``` 42 | /// 43 | /// By default, all variables are **not** mutable. If you want a mutable variable, 44 | /// you'll have to use the `mut` keyword. 45 | /// 46 | /// Example: 47 | /// 48 | /// ```rust 49 | /// # #![allow(unused_assignments)] 50 | /// let mut x = 3; // We create a mutable variable named `x` with the value `3`. 51 | /// 52 | /// x += 4; // `x` is now equal to `7`. 53 | /// ``` 54 | /// 55 | /// For more information about the `let` keyword, take a look at the [Rust Book][book]. 56 | /// 57 | /// [book]: https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html 58 | mod let_keyword { } 59 | -------------------------------------------------------------------------------- /ctr-std/src/net/test.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(warnings)] // not used on emscripten 12 | 13 | use env; 14 | use net::{SocketAddr, SocketAddrV4, SocketAddrV6, Ipv4Addr, Ipv6Addr, ToSocketAddrs}; 15 | use sync::atomic::{AtomicUsize, Ordering}; 16 | 17 | static PORT: AtomicUsize = AtomicUsize::new(0); 18 | 19 | pub fn next_test_ip4() -> SocketAddr { 20 | let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port(); 21 | SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port)) 22 | } 23 | 24 | pub fn next_test_ip6() -> SocketAddr { 25 | let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port(); 26 | SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 27 | port, 0, 0)) 28 | } 29 | 30 | pub fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr { 31 | SocketAddr::V4(SocketAddrV4::new(a, p)) 32 | } 33 | 34 | pub fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr { 35 | SocketAddr::V6(SocketAddrV6::new(a, p, 0, 0)) 36 | } 37 | 38 | pub fn tsa(a: A) -> Result, String> { 39 | match a.to_socket_addrs() { 40 | Ok(a) => Ok(a.collect()), 41 | Err(e) => Err(e.to_string()), 42 | } 43 | } 44 | 45 | // The bots run multiple builds at the same time, and these builds 46 | // all want to use ports. This function figures out which workspace 47 | // it is running in and assigns a port range based on it. 48 | fn base_port() -> u16 { 49 | let cwd = env::current_dir().unwrap(); 50 | let dirs = ["32-opt", "32-nopt", 51 | "musl-64-opt", "cross-opt", 52 | "64-opt", "64-nopt", "64-opt-vg", "64-debug-opt", 53 | "all-opt", "snap3", "dist"]; 54 | dirs.iter().enumerate().find(|&(_, dir)| { 55 | cwd.to_str().unwrap().contains(dir) 56 | }).map(|p| p.0).unwrap_or(0) as u16 * 1000 + 19600 57 | } 58 | -------------------------------------------------------------------------------- /ctr-std/src/os/android/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Android-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/bitrig/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Bitrig-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/dragonfly/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Dragonfly-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/emscripten/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Linux-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/freebsd/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! FreeBSD-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/fuchsia/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Fuchsia-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/haiku/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Haiku-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/hermit/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! HermitCore-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/hermit/raw.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! HermitCore-specific raw type definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | #![rustc_deprecated(since = "1.8.0", 15 | reason = "these type aliases are no longer supported by \ 16 | the standard library, the `libc` crate on \ 17 | crates.io should be used instead for the correct \ 18 | definitions")] 19 | #![allow(deprecated)] 20 | #![allow(missing_debug_implementations)] 21 | 22 | #[stable(feature = "pthread_t", since = "1.8.0")] 23 | pub use libc::pthread_t; 24 | 25 | #[doc(inline)] 26 | #[stable(feature = "raw_ext", since = "1.1.0")] 27 | pub use libc::{dev_t, mode_t, off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t}; 28 | -------------------------------------------------------------------------------- /ctr-std/src/os/horizon/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Linux-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/ios/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! iOS-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/linux/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Linux-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/macos/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! macOS-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! OS-specific functionality. 12 | 13 | #![stable(feature = "os", since = "1.0.0")] 14 | #![allow(missing_docs, bad_style, missing_debug_implementations)] 15 | 16 | cfg_if! { 17 | if #[cfg(dox)] { 18 | 19 | // When documenting libstd we want to show unix/windows/linux modules as 20 | // these are the "main modules" that are used across platforms. This 21 | // should help show platform-specific functionality in a hopefully 22 | // cross-platform way in the documentation 23 | 24 | #[stable(feature = "rust1", since = "1.0.0")] 25 | pub use sys::unix_ext as unix; 26 | 27 | #[stable(feature = "rust1", since = "1.0.0")] 28 | pub use sys::windows_ext as windows; 29 | 30 | #[doc(cfg(target_os = "linux"))] 31 | pub mod linux; 32 | 33 | } else { 34 | 35 | // If we're not documenting libstd then we just expose everything as we 36 | // otherwise would. 37 | 38 | #[cfg(target_os = "android")] pub mod android; 39 | #[cfg(target_os = "bitrig")] pub mod bitrig; 40 | #[cfg(target_os = "dragonfly")] pub mod dragonfly; 41 | #[cfg(target_os = "freebsd")] pub mod freebsd; 42 | #[cfg(target_os = "haiku")] pub mod haiku; 43 | #[cfg(target_os = "ios")] pub mod ios; 44 | #[cfg(target_os = "macos")] pub mod macos; 45 | #[cfg(target_os = "netbsd")] pub mod netbsd; 46 | #[cfg(target_os = "openbsd")] pub mod openbsd; 47 | #[cfg(target_os = "solaris")] pub mod solaris; 48 | #[cfg(target_os = "emscripten")] pub mod emscripten; 49 | #[cfg(target_os = "fuchsia")] pub mod fuchsia; 50 | #[cfg(target_os = "hermit")] pub mod hermit; 51 | #[cfg(target_os = "horizon")] pub mod horizon; 52 | 53 | #[cfg(any(target_os = "redox", unix))] 54 | #[stable(feature = "rust1", since = "1.0.0")] 55 | pub use sys::ext as unix; 56 | 57 | #[cfg(windows)] 58 | #[stable(feature = "rust1", since = "1.0.0")] 59 | pub use sys::ext as windows; 60 | 61 | #[cfg(any(target_os = "linux", target_os = "l4re"))] 62 | pub mod linux; 63 | 64 | } 65 | } 66 | 67 | pub mod raw; 68 | -------------------------------------------------------------------------------- /ctr-std/src/os/netbsd/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! OpenBSD-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/openbsd/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! OpenBSD-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/char.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `char` type. 2 | 3 | [C's `char` type] is completely unlike [Rust's `char` type]; while Rust's type represents a unicode scalar value, C's `char` type is just an ordinary integer. This type will always be either [`i8`] or [`u8`], as the type is defined as being one byte long. 4 | 5 | C chars are most commonly used to make C strings. Unlike Rust, where the length of a string is included alongside the string, C strings mark the end of a string with the character `'\0'`. See [`CStr`] for more information. 6 | 7 | [C's `char` type]: https://en.wikipedia.org/wiki/C_data_types#Basic_types 8 | [Rust's `char` type]: ../../primitive.char.html 9 | [`CStr`]: ../../ffi/struct.CStr.html 10 | [`i8`]: ../../primitive.i8.html 11 | [`u8`]: ../../primitive.u8.html 12 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/double.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `double` type. 2 | 3 | This type will almost always be [`f64`], which is guaranteed to be an [IEEE-754 double-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number with at least the precision of a [`float`], and it may be `f32` or something entirely different from the IEEE-754 standard. 4 | 5 | [IEEE-754 double-precision float]: https://en.wikipedia.org/wiki/IEEE_754 6 | [`float`]: type.c_float.html 7 | [`f64`]: ../../primitive.f64.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/float.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `float` type. 2 | 3 | This type will almost always be [`f32`], which is guaranteed to be an [IEEE-754 single-precision float] in Rust. That said, the standard technically only guarantees that it be a floating-point number, and it may have less precision than `f32` or not follow the IEEE-754 standard at all. 4 | 5 | [IEEE-754 single-precision float]: https://en.wikipedia.org/wiki/IEEE_754 6 | [`f32`]: ../../primitive.f32.html 7 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/int.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `signed int` (`int`) type. 2 | 3 | This type will almost always be [`i32`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer that is at least the size of a [`short`]; some systems define it as an [`i16`], for example. 4 | 5 | [`short`]: type.c_short.html 6 | [`i32`]: ../../primitive.i32.html 7 | [`i16`]: ../../primitive.i16.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/long.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `signed long` (`long`) type. 2 | 3 | This type will always be [`i32`] or [`i64`]. Most notably, many Linux-based systems assume an `i64`, but Windows assumes `i32`. The C standard technically only requires that this type be a signed integer that is at least 32 bits and at least the size of an [`int`], although in practice, no system would have a `long` that is neither an `i32` nor `i64`. 4 | 5 | [`int`]: type.c_int.html 6 | [`i32`]: ../../primitive.i32.html 7 | [`i64`]: ../../primitive.i64.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/longlong.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `signed long long` (`long long`) type. 2 | 3 | This type will almost always be [`i64`], but may differ on some systems. The C standard technically only requires that this type be a signed integer that is at least 64 bits and at least the size of a [`long`], although in practice, no system would have a `long long` that is not an `i64`, as most systems do not have a standardised [`i128`] type. 4 | 5 | [`long`]: type.c_int.html 6 | [`i64`]: ../../primitive.i64.html 7 | [`i128`]: ../../primitive.i128.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/schar.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `signed char` type. 2 | 3 | This type will always be [`i8`], but is included for completeness. It is defined as being a signed integer the same size as a C [`char`]. 4 | 5 | [`char`]: type.c_char.html 6 | [`i8`]: ../../primitive.i8.html 7 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/short.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `signed short` (`short`) type. 2 | 3 | This type will almost always be [`i16`], but may differ on some esoteric systems. The C standard technically only requires that this type be a signed integer with at least 16 bits; some systems may define it as `i32`, for example. 4 | 5 | [`char`]: type.c_char.html 6 | [`i16`]: ../../primitive.i16.html 7 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/uchar.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `unsigned char` type. 2 | 3 | This type will always be [`u8`], but is included for completeness. It is defined as being an unsigned integer the same size as a C [`char`]. 4 | 5 | [`char`]: type.c_char.html 6 | [`u8`]: ../../primitive.u8.html 7 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/uint.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `unsigned int` type. 2 | 3 | This type will almost always be [`u32`], but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as an [`int`]; some systems define it as a [`u16`], for example. 4 | 5 | [`int`]: type.c_int.html 6 | [`u32`]: ../../primitive.u32.html 7 | [`u16`]: ../../primitive.u16.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/ulong.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `unsigned long` type. 2 | 3 | This type will always be [`u32`] or [`u64`]. Most notably, many Linux-based systems assume an `u64`, but Windows assumes `u32`. The C standard technically only requires that this type be an unsigned integer with the size of a [`long`], although in practice, no system would have a `ulong` that is neither a `u32` nor `u64`. 4 | 5 | [`long`]: type.c_long.html 6 | [`u32`]: ../../primitive.u32.html 7 | [`u64`]: ../../primitive.u64.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/ulonglong.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `unsigned long long` type. 2 | 3 | This type will almost always be [`u64`], but may differ on some systems. The C standard technically only requires that this type be an unsigned integer with the size of a [`long long`], although in practice, no system would have a `long long` that is not a `u64`, as most systems do not have a standardised [`u128`] type. 4 | 5 | [`long long`]: type.c_longlong.html 6 | [`u64`]: ../../primitive.u64.html 7 | [`u128`]: ../../primitive.u128.html 8 | -------------------------------------------------------------------------------- /ctr-std/src/os/raw/ushort.md: -------------------------------------------------------------------------------- 1 | Equivalent to C's `unsigned short` type. 2 | 3 | This type will almost always be [`u16`], but may differ on some esoteric systems. The C standard technically only requires that this type be an unsigned integer with the same size as a [`short`]. 4 | 5 | [`short`]: type.c_short.html 6 | [`u16`]: ../../primitive.u16.html 7 | -------------------------------------------------------------------------------- /ctr-std/src/os/solaris/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Solaris-specific definitions 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | pub mod raw; 16 | pub mod fs; 17 | -------------------------------------------------------------------------------- /ctr-std/src/sync/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Useful synchronization primitives. 12 | //! 13 | //! This module contains useful safe and unsafe synchronization primitives. 14 | //! Most of the primitives in this module do not provide any sort of locking 15 | //! and/or blocking at all, but rather provide the necessary tools to build 16 | //! other types of concurrent primitives. 17 | 18 | #![stable(feature = "rust1", since = "1.0.0")] 19 | 20 | #[stable(feature = "rust1", since = "1.0.0")] 21 | pub use alloc_crate::sync::{Arc, Weak}; 22 | #[stable(feature = "rust1", since = "1.0.0")] 23 | pub use core::sync::atomic; 24 | 25 | #[stable(feature = "rust1", since = "1.0.0")] 26 | pub use self::barrier::{Barrier, BarrierWaitResult}; 27 | #[stable(feature = "rust1", since = "1.0.0")] 28 | pub use self::condvar::{Condvar, WaitTimeoutResult}; 29 | #[stable(feature = "rust1", since = "1.0.0")] 30 | pub use self::mutex::{Mutex, MutexGuard}; 31 | #[stable(feature = "rust1", since = "1.0.0")] 32 | pub use self::once::{Once, OnceState, ONCE_INIT}; 33 | #[stable(feature = "rust1", since = "1.0.0")] 34 | pub use sys_common::poison::{PoisonError, TryLockError, TryLockResult, LockResult}; 35 | #[stable(feature = "rust1", since = "1.0.0")] 36 | pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; 37 | 38 | pub mod mpsc; 39 | 40 | mod barrier; 41 | mod condvar; 42 | mod mutex; 43 | mod once; 44 | mod rwlock; 45 | -------------------------------------------------------------------------------- /ctr-std/src/sync/mpsc/blocking.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Generic support for building blocking abstractions. 12 | 13 | use thread::{self, Thread}; 14 | use sync::atomic::{AtomicBool, Ordering}; 15 | use sync::Arc; 16 | use mem; 17 | use time::Instant; 18 | 19 | struct Inner { 20 | thread: Thread, 21 | woken: AtomicBool, 22 | } 23 | 24 | unsafe impl Send for Inner {} 25 | unsafe impl Sync for Inner {} 26 | 27 | #[derive(Clone)] 28 | pub struct SignalToken { 29 | inner: Arc, 30 | } 31 | 32 | pub struct WaitToken { 33 | inner: Arc, 34 | } 35 | 36 | impl !Send for WaitToken {} 37 | 38 | impl !Sync for WaitToken {} 39 | 40 | pub fn tokens() -> (WaitToken, SignalToken) { 41 | let inner = Arc::new(Inner { 42 | thread: thread::current(), 43 | woken: AtomicBool::new(false), 44 | }); 45 | let wait_token = WaitToken { 46 | inner: inner.clone(), 47 | }; 48 | let signal_token = SignalToken { 49 | inner, 50 | }; 51 | (wait_token, signal_token) 52 | } 53 | 54 | impl SignalToken { 55 | pub fn signal(&self) -> bool { 56 | let wake = !self.inner.woken.compare_and_swap(false, true, Ordering::SeqCst); 57 | if wake { 58 | self.inner.thread.unpark(); 59 | } 60 | wake 61 | } 62 | 63 | /// Convert to an unsafe usize value. Useful for storing in a pipe's state 64 | /// flag. 65 | #[inline] 66 | pub unsafe fn cast_to_usize(self) -> usize { 67 | mem::transmute(self.inner) 68 | } 69 | 70 | /// Convert from an unsafe usize value. Useful for retrieving a pipe's state 71 | /// flag. 72 | #[inline] 73 | pub unsafe fn cast_from_usize(signal_ptr: usize) -> SignalToken { 74 | SignalToken { inner: mem::transmute(signal_ptr) } 75 | } 76 | } 77 | 78 | impl WaitToken { 79 | pub fn wait(self) { 80 | while !self.inner.woken.load(Ordering::SeqCst) { 81 | thread::park() 82 | } 83 | } 84 | 85 | /// Returns true if we wake up normally, false otherwise. 86 | pub fn wait_max_until(self, end: Instant) -> bool { 87 | while !self.inner.woken.load(Ordering::SeqCst) { 88 | let now = Instant::now(); 89 | if now >= end { 90 | return false; 91 | } 92 | thread::park_timeout(end - now) 93 | } 94 | true 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ctr-std/src/sync/mpsc/cache_aligned.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ops::{Deref, DerefMut}; 12 | 13 | #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] 14 | #[repr(align(64))] 15 | pub(super) struct Aligner; 16 | 17 | #[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] 18 | pub(super) struct CacheAligned(pub T, pub Aligner); 19 | 20 | impl Deref for CacheAligned { 21 | type Target = T; 22 | fn deref(&self) -> &Self::Target { 23 | &self.0 24 | } 25 | } 26 | 27 | impl DerefMut for CacheAligned { 28 | fn deref_mut(&mut self) -> &mut Self::Target { 29 | &mut self.0 30 | } 31 | } 32 | 33 | impl CacheAligned { 34 | pub(super) fn new(t: T) -> Self { 35 | CacheAligned(t, Aligner) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/abi/bitflags.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018 Nuxi (https://nuxi.nl/) and contributors. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions 5 | // are met: 6 | // 1. Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // 2. Redistributions in binary form must reproduce the above copyright 9 | // notice, this list of conditions and the following disclaimer in the 10 | // documentation and/or other materials provided with the distribution. 11 | // 12 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18 | // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 | // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 | // SUCH DAMAGE. 23 | 24 | // Appease Rust's tidy. 25 | // ignore-license 26 | 27 | #[cfg(feature = "bitflags")] 28 | #[macro_use] 29 | extern crate bitflags; 30 | 31 | // Minimal implementation of bitflags! in case we can't depend on the bitflags 32 | // crate. Only implements `bits()` and a `from_bits_truncate()` that doesn't 33 | // actually truncate. 34 | #[cfg(not(feature = "bitflags"))] 35 | macro_rules! bitflags { 36 | ( 37 | $(#[$attr:meta])* 38 | pub struct $name:ident: $type:ty { 39 | $($(#[$const_attr:meta])* const $const:ident = $val:expr;)* 40 | } 41 | ) => { 42 | $(#[$attr])* 43 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 44 | pub struct $name { bits: $type } 45 | impl $name { 46 | $($(#[$const_attr])* pub const $const: $name = $name{ bits: $val };)* 47 | pub fn bits(&self) -> $type { self.bits } 48 | pub fn from_bits_truncate(bits: $type) -> Self { $name{ bits } } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/abi/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #[allow(warnings)] 12 | mod cloudabi; 13 | pub use self::cloudabi::*; 14 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/args.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use sys::cloudabi::shims::args::*; 12 | 13 | #[allow(dead_code)] 14 | pub fn init(_: isize, _: *const *const u8) {} 15 | 16 | #[allow(dead_code)] 17 | pub fn cleanup() {} 18 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/os.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ffi::CStr; 12 | use libc::{self, c_int}; 13 | use str; 14 | 15 | pub use sys::cloudabi::shims::os::*; 16 | 17 | pub fn errno() -> i32 { 18 | extern "C" { 19 | #[thread_local] 20 | static errno: c_int; 21 | } 22 | 23 | unsafe { errno as i32 } 24 | } 25 | 26 | /// Gets a detailed string description for the given error number. 27 | pub fn error_string(errno: i32) -> String { 28 | // cloudlibc's strerror() is guaranteed to be thread-safe. There is 29 | // thus no need to use strerror_r(). 30 | str::from_utf8(unsafe { CStr::from_ptr(libc::strerror(errno)) }.to_bytes()) 31 | .unwrap() 32 | .to_owned() 33 | } 34 | 35 | pub fn exit(code: i32) -> ! { 36 | unsafe { libc::exit(code as c_int) } 37 | } 38 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/shims/args.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ffi::OsString; 12 | 13 | pub struct Args(()); 14 | 15 | impl Args { 16 | pub fn inner_debug(&self) -> &[OsString] { 17 | &[] 18 | } 19 | } 20 | 21 | impl Iterator for Args { 22 | type Item = OsString; 23 | fn next(&mut self) -> Option { 24 | None 25 | } 26 | fn size_hint(&self) -> (usize, Option) { 27 | (0, Some(0)) 28 | } 29 | } 30 | 31 | impl ExactSizeIterator for Args { 32 | fn len(&self) -> usize { 33 | 0 34 | } 35 | } 36 | 37 | impl DoubleEndedIterator for Args { 38 | fn next_back(&mut self) -> Option { 39 | None 40 | } 41 | } 42 | 43 | pub fn args() -> Args { 44 | Args(()) 45 | } 46 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/shims/env.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub mod os { 12 | pub const FAMILY: &'static str = "cloudabi"; 13 | pub const OS: &'static str = "cloudabi"; 14 | pub const DLL_PREFIX: &'static str = "lib"; 15 | pub const DLL_SUFFIX: &'static str = ".so"; 16 | pub const DLL_EXTENSION: &'static str = "so"; 17 | pub const EXE_SUFFIX: &'static str = ""; 18 | pub const EXE_EXTENSION: &'static str = ""; 19 | } 20 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/shims/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | 13 | pub mod args; 14 | pub mod env; 15 | pub mod fs; 16 | pub mod net; 17 | #[path = "../../unix/path.rs"] 18 | pub mod path; 19 | pub mod pipe; 20 | pub mod process; 21 | pub mod os; 22 | 23 | // This enum is used as the storage for a bunch of types which can't actually exist. 24 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] 25 | pub enum Void {} 26 | 27 | pub fn unsupported() -> io::Result { 28 | Err(io::Error::new( 29 | io::ErrorKind::Other, 30 | "This function is not available on CloudABI.", 31 | )) 32 | } 33 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/shims/os.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use error::Error as StdError; 12 | use ffi::{OsStr, OsString}; 13 | use fmt; 14 | use io; 15 | use iter; 16 | use path::{self, PathBuf}; 17 | use sys::{unsupported, Void}; 18 | 19 | pub fn getcwd() -> io::Result { 20 | unsupported() 21 | } 22 | 23 | pub fn chdir(_: &path::Path) -> io::Result<()> { 24 | unsupported() 25 | } 26 | 27 | pub type Env = iter::Empty<(OsString, OsString)>; 28 | 29 | pub fn env() -> Env { 30 | iter::empty() 31 | } 32 | 33 | pub fn getenv(_: &OsStr) -> io::Result> { 34 | Ok(None) 35 | } 36 | 37 | pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { 38 | unsupported() 39 | } 40 | 41 | pub fn unsetenv(_: &OsStr) -> io::Result<()> { 42 | unsupported() 43 | } 44 | 45 | pub struct SplitPaths<'a>(&'a Void); 46 | 47 | pub fn split_paths(_unparsed: &OsStr) -> SplitPaths { 48 | panic!("unsupported") 49 | } 50 | 51 | impl<'a> Iterator for SplitPaths<'a> { 52 | type Item = PathBuf; 53 | fn next(&mut self) -> Option { 54 | match *self.0 {} 55 | } 56 | } 57 | 58 | #[derive(Debug)] 59 | pub struct JoinPathsError; 60 | 61 | pub fn join_paths(_paths: I) -> Result 62 | where 63 | I: Iterator, 64 | T: AsRef, 65 | { 66 | Err(JoinPathsError) 67 | } 68 | 69 | impl fmt::Display for JoinPathsError { 70 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 71 | "not supported on CloudABI yet".fmt(f) 72 | } 73 | } 74 | 75 | impl StdError for JoinPathsError { 76 | fn description(&self) -> &str { 77 | "not supported on CloudABI yet" 78 | } 79 | } 80 | 81 | pub fn home_dir() -> Option { 82 | None 83 | } 84 | 85 | pub fn temp_dir() -> PathBuf { 86 | PathBuf::from("/tmp") 87 | } 88 | 89 | pub fn current_exe() -> io::Result { 90 | unsupported() 91 | } 92 | 93 | pub fn getpid() -> u32 { 94 | 1 95 | } 96 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/shims/pipe.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::Void; 13 | 14 | pub struct AnonPipe(Void); 15 | 16 | impl AnonPipe { 17 | pub fn read(&self, _buf: &mut [u8]) -> io::Result { 18 | match self.0 {} 19 | } 20 | 21 | pub fn write(&self, _buf: &[u8]) -> io::Result { 22 | match self.0 {} 23 | } 24 | 25 | pub fn diverge(&self) -> ! { 26 | match self.0 {} 27 | } 28 | } 29 | 30 | pub fn read2(p1: AnonPipe, _v1: &mut Vec, _p2: AnonPipe, _v2: &mut Vec) -> io::Result<()> { 31 | match p1.0 {} 32 | } 33 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/stack_overflow.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg_attr(test, allow(dead_code))] 12 | 13 | pub struct Handler; 14 | 15 | impl Handler { 16 | pub unsafe fn new() -> Handler { 17 | Handler 18 | } 19 | } 20 | 21 | pub unsafe fn init() {} 22 | 23 | pub unsafe fn cleanup() {} 24 | -------------------------------------------------------------------------------- /ctr-std/src/sys/cloudabi/stdio.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::cloudabi::abi; 13 | 14 | pub struct Stdin(()); 15 | pub struct Stdout(()); 16 | pub struct Stderr(()); 17 | 18 | impl Stdin { 19 | pub fn new() -> io::Result { 20 | Ok(Stdin(())) 21 | } 22 | 23 | pub fn read(&self, _: &mut [u8]) -> io::Result { 24 | Ok(0) 25 | } 26 | } 27 | 28 | impl Stdout { 29 | pub fn new() -> io::Result { 30 | Ok(Stdout(())) 31 | } 32 | 33 | pub fn write(&self, _: &[u8]) -> io::Result { 34 | Err(io::Error::new( 35 | io::ErrorKind::BrokenPipe, 36 | "Stdout is not connected to any output in this environment", 37 | )) 38 | } 39 | 40 | pub fn flush(&self) -> io::Result<()> { 41 | Ok(()) 42 | } 43 | } 44 | 45 | impl Stderr { 46 | pub fn new() -> io::Result { 47 | Ok(Stderr(())) 48 | } 49 | 50 | pub fn write(&self, _: &[u8]) -> io::Result { 51 | Err(io::Error::new( 52 | io::ErrorKind::BrokenPipe, 53 | "Stderr is not connected to any output in this environment", 54 | )) 55 | } 56 | 57 | pub fn flush(&self) -> io::Result<()> { 58 | Ok(()) 59 | } 60 | } 61 | 62 | // FIXME: right now this raw stderr handle is used in a few places because 63 | // std::io::stderr_raw isn't exposed, but once that's exposed this impl 64 | // should go away 65 | impl io::Write for Stderr { 66 | fn write(&mut self, data: &[u8]) -> io::Result { 67 | Stderr::write(self, data) 68 | } 69 | 70 | fn flush(&mut self) -> io::Result<()> { 71 | Stderr::flush(self) 72 | } 73 | } 74 | 75 | pub fn is_ebadf(err: &io::Error) -> bool { 76 | err.raw_os_error() == Some(abi::errno::BADF as i32) 77 | } 78 | 79 | pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; 80 | 81 | pub fn stderr_prints_nothing() -> bool { 82 | false 83 | } 84 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/args.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ffi::OsString; 12 | use marker::PhantomData; 13 | use vec; 14 | 15 | pub unsafe fn init(_argc: isize, _argv: *const *const u8) { 16 | // Currently null because we haven't implemented args yet 17 | } 18 | 19 | pub unsafe fn cleanup() { 20 | } 21 | 22 | pub fn args() -> Args { 23 | return Args { 24 | iter: Vec::new().into_iter(), 25 | _dont_send_or_sync_me: PhantomData, 26 | } 27 | } 28 | 29 | pub struct Args { 30 | iter: vec::IntoIter, 31 | _dont_send_or_sync_me: PhantomData<*mut ()>, 32 | } 33 | 34 | impl Args { 35 | pub fn inner_debug(&self) -> &[OsString] { 36 | self.iter.as_slice() 37 | } 38 | } 39 | 40 | impl Iterator for Args { 41 | type Item = OsString; 42 | fn next(&mut self) -> Option { 43 | self.iter.next() 44 | } 45 | fn size_hint(&self) -> (usize, Option) { 46 | self.iter.size_hint() 47 | } 48 | } 49 | 50 | impl ExactSizeIterator for Args { 51 | fn len(&self) -> usize { 52 | self.iter.len() 53 | } 54 | } 55 | 56 | impl DoubleEndedIterator for Args { 57 | fn next_back(&mut self) -> Option { 58 | self.iter.next_back() 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/backtrace/printing/dladdr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use intrinsics; 13 | use ffi::CStr; 14 | use libc; 15 | use sys::backtrace::BacktraceContext; 16 | use sys_common::backtrace::Frame; 17 | 18 | pub fn resolve_symname(frame: Frame, 19 | callback: F, 20 | _: &BacktraceContext) -> io::Result<()> 21 | where F: FnOnce(Option<&str>) -> io::Result<()> 22 | { 23 | unsafe { 24 | let mut info: Dl_info = intrinsics::init(); 25 | let symname = if dladdr(frame.exact_position as *mut _, &mut info) == 0 || 26 | info.dli_sname.is_null() { 27 | None 28 | } else { 29 | CStr::from_ptr(info.dli_sname).to_str().ok() 30 | }; 31 | callback(symname) 32 | } 33 | } 34 | 35 | #[repr(C)] 36 | struct Dl_info { 37 | dli_fname: *const libc::c_char, 38 | dli_fbase: *mut libc::c_void, 39 | dli_sname: *const libc::c_char, 40 | dli_saddr: *mut libc::c_void, 41 | } 42 | 43 | extern { 44 | fn dladdr(addr: *const libc::c_void, info: *mut Dl_info) -> libc::c_int; 45 | } 46 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/backtrace/printing/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | mod dladdr; 12 | 13 | use sys::backtrace::BacktraceContext; 14 | use sys_common::backtrace::Frame; 15 | use io; 16 | 17 | #[cfg(target_os = "emscripten")] 18 | pub use self::dladdr::resolve_symname; 19 | 20 | #[cfg(target_os = "emscripten")] 21 | pub fn foreach_symbol_fileline(_: Frame, _: F, _: &BacktraceContext) -> io::Result 22 | where 23 | F: FnMut(&[u8], u32) -> io::Result<()> 24 | { 25 | Ok(false) 26 | } 27 | 28 | #[cfg(not(target_os = "emscripten"))] 29 | pub use sys_common::gnu::libbacktrace::foreach_symbol_fileline; 30 | 31 | #[cfg(not(target_os = "emscripten"))] 32 | pub fn resolve_symname(frame: Frame, callback: F, bc: &BacktraceContext) -> io::Result<()> 33 | where 34 | F: FnOnce(Option<&str>) -> io::Result<()> 35 | { 36 | ::sys_common::gnu::libbacktrace::resolve_symname(frame, |symname| { 37 | if symname.is_some() { 38 | callback(symname) 39 | } else { 40 | dladdr::resolve_symname(frame, callback, bc) 41 | } 42 | }, bc) 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/backtrace/tracing/backtrace_fn.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | /// As always - iOS on arm uses SjLj exceptions and 12 | /// _Unwind_Backtrace is even not available there. Still, 13 | /// backtraces could be extracted using a backtrace function, 14 | /// which thanks god is public 15 | /// 16 | /// As mentioned in a huge comment block in `super::super`, backtrace 17 | /// doesn't play well with green threads, so while it is extremely nice and 18 | /// simple to use it should be used only on iOS devices as the only viable 19 | /// option. 20 | 21 | use io; 22 | use libc; 23 | use sys::backtrace::BacktraceContext; 24 | use sys_common::backtrace::Frame; 25 | 26 | #[inline(never)] // if we know this is a function call, we can skip it when 27 | // tracing 28 | pub fn unwind_backtrace(frames: &mut [Frame]) 29 | -> io::Result<(usize, BacktraceContext)> 30 | { 31 | const FRAME_LEN: usize = 100; 32 | assert!(FRAME_LEN >= frames.len()); 33 | let mut raw_frames = [::ptr::null_mut(); FRAME_LEN]; 34 | let nb_frames = unsafe { 35 | backtrace(raw_frames.as_mut_ptr(), raw_frames.len() as libc::c_int) 36 | } as usize; 37 | for (from, to) in raw_frames.iter().zip(frames.iter_mut()).take(nb_frames) { 38 | *to = Frame { 39 | exact_position: *from as *mut u8, 40 | symbol_addr: *from as *mut u8, 41 | inline_context: 0, 42 | }; 43 | } 44 | Ok((nb_frames as usize, BacktraceContext)) 45 | } 46 | 47 | extern { 48 | fn backtrace(buf: *mut *mut libc::c_void, sz: libc::c_int) -> libc::c_int; 49 | } 50 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/backtrace/tracing/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use self::imp::*; 12 | 13 | #[cfg(not(all(target_os = "ios", target_arch = "arm")))] 14 | #[path = "gcc_s.rs"] 15 | mod imp; 16 | #[cfg(all(target_os = "ios", target_arch = "arm"))] 17 | #[path = "backtrace_fn.rs"] 18 | mod imp; 19 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/cmath.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg(not(test))] 12 | 13 | use libc::{c_float, c_double}; 14 | 15 | #[link_name = "m"] 16 | extern { 17 | pub fn acos(n: c_double) -> c_double; 18 | pub fn acosf(n: c_float) -> c_float; 19 | pub fn asin(n: c_double) -> c_double; 20 | pub fn asinf(n: c_float) -> c_float; 21 | pub fn atan(n: c_double) -> c_double; 22 | pub fn atan2(a: c_double, b: c_double) -> c_double; 23 | pub fn atan2f(a: c_float, b: c_float) -> c_float; 24 | pub fn atanf(n: c_float) -> c_float; 25 | pub fn cbrt(n: c_double) -> c_double; 26 | pub fn cbrtf(n: c_float) -> c_float; 27 | pub fn cosh(n: c_double) -> c_double; 28 | pub fn coshf(n: c_float) -> c_float; 29 | pub fn expm1(n: c_double) -> c_double; 30 | pub fn expm1f(n: c_float) -> c_float; 31 | pub fn fdim(a: c_double, b: c_double) -> c_double; 32 | pub fn fdimf(a: c_float, b: c_float) -> c_float; 33 | pub fn hypot(x: c_double, y: c_double) -> c_double; 34 | pub fn hypotf(x: c_float, y: c_float) -> c_float; 35 | pub fn log1p(n: c_double) -> c_double; 36 | pub fn log1pf(n: c_float) -> c_float; 37 | pub fn sinh(n: c_double) -> c_double; 38 | pub fn sinhf(n: c_float) -> c_float; 39 | pub fn tan(n: c_double) -> c_double; 40 | pub fn tanf(n: c_float) -> c_float; 41 | pub fn tanh(n: c_double) -> c_double; 42 | pub fn tanhf(n: c_float) -> c_float; 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/ext/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Experimental extensions to `std` for Unix platforms. 12 | //! 13 | //! Provides access to platform-level information on Unix platforms, and 14 | //! exposes Unix-specific functions that would otherwise be inappropriate as 15 | //! part of the core `std` library. 16 | //! 17 | //! It exposes more ways to deal with platform-specific strings (`OsStr`, 18 | //! `OsString`), allows to set permissions more granularly, extract low-level 19 | //! file descriptors from files and sockets, and has platform-specific helpers 20 | //! for spawning processes. 21 | //! 22 | //! # Examples 23 | //! 24 | //! ```no_run 25 | //! use std::fs::File; 26 | //! use std::os::unix::prelude::*; 27 | //! 28 | //! fn main() { 29 | //! let f = File::create("foo.txt").unwrap(); 30 | //! let fd = f.as_raw_fd(); 31 | //! 32 | //! // use fd with native unix bindings 33 | //! } 34 | //! ``` 35 | 36 | #![stable(feature = "rust1", since = "1.0.0")] 37 | #![doc(cfg(unix))] 38 | 39 | pub mod io; 40 | pub mod ffi; 41 | pub mod fs; 42 | pub mod raw; 43 | 44 | /// A prelude for conveniently writing platform-specific code. 45 | /// 46 | /// Includes all extension traits, and some important type definitions. 47 | #[stable(feature = "rust1", since = "1.0.0")] 48 | pub mod prelude { 49 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 50 | pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; 51 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 52 | pub use super::ffi::{OsStrExt, OsStringExt}; 53 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 54 | pub use super::fs::{PermissionsExt, OpenOptionsExt, MetadataExt, FileTypeExt}; 55 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 56 | pub use super::fs::DirEntryExt; 57 | #[doc(no_inline)] #[stable(feature = "file_offset", since = "1.15.0")] 58 | pub use super::fs::FileExt; 59 | } 60 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/ext/raw.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Unix-specific primitives available on all unix platforms 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | #![rustc_deprecated(since = "1.8.0", 15 | reason = "these type aliases are no longer supported by \ 16 | the standard library, the `libc` crate on \ 17 | crates.io should be used instead for the correct \ 18 | definitions")] 19 | #![allow(deprecated)] 20 | 21 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type uid_t = u32; 22 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32; 23 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type pid_t = i32; 24 | 25 | #[doc(inline)] 26 | #[stable(feature = "pthread_t", since = "1.8.0")] 27 | pub use sys::platform::raw::pthread_t; 28 | #[doc(inline)] 29 | #[stable(feature = "raw_ext", since = "1.1.0")] 30 | pub use sys::platform::raw::{dev_t, ino_t, mode_t, nlink_t, off_t, blksize_t}; 31 | #[doc(inline)] 32 | #[stable(feature = "raw_ext", since = "1.1.0")] 33 | pub use sys::platform::raw::{blkcnt_t, time_t}; 34 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/memchr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | // 11 | // Original implementation taken from rust-memchr 12 | // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch 13 | 14 | pub fn memchr(needle: u8, haystack: &[u8]) -> Option { 15 | use libc; 16 | 17 | let p = unsafe { 18 | libc::memchr( 19 | haystack.as_ptr() as *const libc::c_void, 20 | needle as libc::c_int, 21 | haystack.len()) 22 | }; 23 | if p.is_null() { 24 | None 25 | } else { 26 | Some(p as usize - (haystack.as_ptr() as usize)) 27 | } 28 | } 29 | 30 | pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { 31 | 32 | #[cfg(target_os = "linux")] 33 | fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { 34 | use libc; 35 | 36 | // GNU's memrchr() will - unlike memchr() - error if haystack is empty. 37 | if haystack.is_empty() {return None} 38 | let p = unsafe { 39 | libc::memrchr( 40 | haystack.as_ptr() as *const libc::c_void, 41 | needle as libc::c_int, 42 | haystack.len()) 43 | }; 44 | if p.is_null() { 45 | None 46 | } else { 47 | Some(p as usize - (haystack.as_ptr() as usize)) 48 | } 49 | } 50 | 51 | #[cfg(not(target_os = "linux"))] 52 | fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { 53 | ::core::slice::memchr::memrchr(needle, haystack) 54 | } 55 | 56 | memrchr_specific(needle, haystack) 57 | } 58 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/mutex.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::UnsafeCell; 12 | use mem; 13 | 14 | pub struct Mutex { 15 | inner: UnsafeCell<::libctru::LightLock>, 16 | } 17 | 18 | #[inline] 19 | pub unsafe fn raw(m: &Mutex) -> *mut ::libctru::LightLock { 20 | m.inner.get() 21 | } 22 | 23 | unsafe impl Send for Mutex {} 24 | unsafe impl Sync for Mutex {} 25 | 26 | impl Mutex { 27 | pub const fn new() -> Mutex { 28 | Mutex { inner: UnsafeCell::new(0) } 29 | } 30 | 31 | #[inline] 32 | pub unsafe fn init(&mut self) { 33 | ::libctru::LightLock_Init(self.inner.get()); 34 | } 35 | 36 | #[inline] 37 | pub unsafe fn lock(&self) { 38 | ::libctru::LightLock_Lock(self.inner.get()); 39 | } 40 | 41 | #[inline] 42 | pub unsafe fn unlock(&self) { 43 | ::libctru::LightLock_Unlock(self.inner.get()); 44 | } 45 | 46 | #[inline] 47 | pub unsafe fn try_lock(&self) -> bool { 48 | match ::libctru::LightLock_TryLock(self.inner.get()) { 49 | 0 => false, 50 | _ => true, 51 | } 52 | } 53 | 54 | #[inline] 55 | pub unsafe fn destroy(&self) { 56 | } 57 | } 58 | 59 | pub struct ReentrantMutex { inner: UnsafeCell<::libctru::RecursiveLock> } 60 | 61 | unsafe impl Send for ReentrantMutex {} 62 | unsafe impl Sync for ReentrantMutex {} 63 | 64 | impl ReentrantMutex { 65 | pub unsafe fn uninitialized() -> ReentrantMutex { 66 | ReentrantMutex { inner: mem::uninitialized() } 67 | } 68 | 69 | pub unsafe fn init(&mut self) { 70 | ::libctru::RecursiveLock_Init(self.inner.get()); 71 | } 72 | 73 | pub unsafe fn lock(&self) { 74 | ::libctru::RecursiveLock_Lock(self.inner.get()); 75 | } 76 | 77 | #[inline] 78 | pub unsafe fn try_lock(&self) -> bool { 79 | match ::libctru::RecursiveLock_TryLock(self.inner.get()) { 80 | 0 => false, 81 | _ => true, 82 | } 83 | } 84 | 85 | pub unsafe fn unlock(&self) { 86 | ::libctru::RecursiveLock_Unlock(self.inner.get()); 87 | } 88 | 89 | pub unsafe fn destroy(&self) {} 90 | } 91 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/path.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use path::Prefix; 12 | use ffi::OsStr; 13 | 14 | #[inline] 15 | pub fn is_sep_byte(b: u8) -> bool { 16 | b == b'/' 17 | } 18 | 19 | #[inline] 20 | pub fn is_verbatim_sep(b: u8) -> bool { 21 | b == b'/' 22 | } 23 | 24 | pub fn parse_prefix(_: &OsStr) -> Option { 25 | None 26 | } 27 | 28 | pub const MAIN_SEP_STR: &'static str = "/"; 29 | pub const MAIN_SEP: char = '/'; 30 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/stdio.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use libc; 13 | use sys::fd::FileDesc; 14 | 15 | pub struct Stdin(()); 16 | pub struct Stdout(()); 17 | pub struct Stderr(()); 18 | 19 | impl Stdin { 20 | pub fn new() -> io::Result { Ok(Stdin(())) } 21 | 22 | pub fn read(&self, data: &mut [u8]) -> io::Result { 23 | let fd = FileDesc::new(libc::STDIN_FILENO); 24 | let ret = fd.read(data); 25 | fd.into_raw(); 26 | ret 27 | } 28 | } 29 | 30 | impl Stdout { 31 | pub fn new() -> io::Result { Ok(Stdout(())) } 32 | 33 | pub fn write(&self, data: &[u8]) -> io::Result { 34 | let fd = FileDesc::new(libc::STDOUT_FILENO); 35 | let ret = fd.write(data); 36 | fd.into_raw(); 37 | ret 38 | } 39 | 40 | pub fn flush(&self) -> io::Result<()> { 41 | Ok(()) 42 | } 43 | } 44 | 45 | impl Stderr { 46 | pub fn new() -> io::Result { Ok(Stderr(())) } 47 | 48 | pub fn write(&self, data: &[u8]) -> io::Result { 49 | let fd = FileDesc::new(libc::STDERR_FILENO); 50 | let ret = fd.write(data); 51 | fd.into_raw(); 52 | ret 53 | } 54 | 55 | pub fn flush(&self) -> io::Result<()> { 56 | Ok(()) 57 | } 58 | } 59 | 60 | // FIXME: right now this raw stderr handle is used in a few places because 61 | // std::io::stderr_raw isn't exposed, but once that's exposed this impl 62 | // should go away 63 | impl io::Write for Stderr { 64 | fn write(&mut self, data: &[u8]) -> io::Result { 65 | Stderr::write(self, data) 66 | } 67 | 68 | fn flush(&mut self) -> io::Result<()> { 69 | Stderr::flush(self) 70 | } 71 | } 72 | 73 | pub fn is_ebadf(err: &io::Error) -> bool { 74 | err.raw_os_error() == Some(libc::EBADF as i32) 75 | } 76 | 77 | pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; 78 | 79 | pub fn stderr_prints_nothing() -> bool { 80 | false 81 | } 82 | -------------------------------------------------------------------------------- /ctr-std/src/sys/horizon/thread_local.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code)] // not used on all platforms 12 | 13 | use collections::BTreeMap; 14 | use ptr; 15 | use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; 16 | 17 | pub type Key = usize; 18 | 19 | type Dtor = unsafe extern fn(*mut u8); 20 | 21 | static NEXT_KEY: AtomicUsize = ATOMIC_USIZE_INIT; 22 | 23 | static mut KEYS: *mut BTreeMap> = ptr::null_mut(); 24 | 25 | #[thread_local] 26 | static mut LOCALS: *mut BTreeMap = ptr::null_mut(); 27 | 28 | unsafe fn keys() -> &'static mut BTreeMap> { 29 | if KEYS == ptr::null_mut() { 30 | KEYS = Box::into_raw(Box::new(BTreeMap::new())); 31 | } 32 | &mut *KEYS 33 | } 34 | 35 | unsafe fn locals() -> &'static mut BTreeMap { 36 | if LOCALS == ptr::null_mut() { 37 | LOCALS = Box::into_raw(Box::new(BTreeMap::new())); 38 | } 39 | &mut *LOCALS 40 | } 41 | 42 | #[inline] 43 | pub unsafe fn create(dtor: Option) -> Key { 44 | let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst); 45 | keys().insert(key, dtor); 46 | key 47 | } 48 | 49 | #[inline] 50 | pub unsafe fn get(key: Key) -> *mut u8 { 51 | if let Some(&entry) = locals().get(&key) { 52 | entry 53 | } else { 54 | ptr::null_mut() 55 | } 56 | } 57 | 58 | #[inline] 59 | pub unsafe fn set(key: Key, value: *mut u8) { 60 | locals().insert(key, value); 61 | } 62 | 63 | #[inline] 64 | pub unsafe fn destroy(key: Key) { 65 | keys().remove(&key); 66 | } 67 | 68 | #[inline] 69 | pub fn requires_synchronized_create() -> bool { 70 | false 71 | } -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/backtrace/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | /// See sys/unix/backtrace/mod.rs for an explanation of the method used here. 12 | 13 | pub use self::tracing::unwind_backtrace; 14 | pub use self::printing::{foreach_symbol_fileline, resolve_symname}; 15 | 16 | // tracing impls: 17 | mod tracing; 18 | // symbol resolvers: 19 | mod printing; 20 | 21 | pub mod gnu { 22 | use io; 23 | use fs; 24 | use libc::c_char; 25 | use vec::Vec; 26 | use ffi::OsStr; 27 | use os::unix::ffi::OsStrExt; 28 | use io::Read; 29 | 30 | pub fn get_executable_filename() -> io::Result<(Vec, fs::File)> { 31 | let mut exefile = fs::File::open("sys:exe")?; 32 | let mut exename = Vec::new(); 33 | exefile.read_to_end(&mut exename)?; 34 | if exename.last() == Some(&b'\n') { 35 | exename.pop(); 36 | } 37 | let file = fs::File::open(OsStr::from_bytes(&exename))?; 38 | Ok((exename.into_iter().map(|c| c as c_char).collect(), file)) 39 | } 40 | } 41 | 42 | pub struct BacktraceContext; 43 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/backtrace/printing.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use sys_common::gnu::libbacktrace::{foreach_symbol_fileline, resolve_symname}; 12 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/cmath.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg(not(test))] 12 | 13 | use libc::{c_float, c_double}; 14 | 15 | #[link_name = "m"] 16 | extern { 17 | pub fn acos(n: c_double) -> c_double; 18 | pub fn acosf(n: c_float) -> c_float; 19 | pub fn asin(n: c_double) -> c_double; 20 | pub fn asinf(n: c_float) -> c_float; 21 | pub fn atan(n: c_double) -> c_double; 22 | pub fn atan2(a: c_double, b: c_double) -> c_double; 23 | pub fn atan2f(a: c_float, b: c_float) -> c_float; 24 | pub fn atanf(n: c_float) -> c_float; 25 | pub fn cbrt(n: c_double) -> c_double; 26 | pub fn cbrtf(n: c_float) -> c_float; 27 | pub fn cosh(n: c_double) -> c_double; 28 | pub fn coshf(n: c_float) -> c_float; 29 | pub fn expm1(n: c_double) -> c_double; 30 | pub fn expm1f(n: c_float) -> c_float; 31 | pub fn fdim(a: c_double, b: c_double) -> c_double; 32 | pub fn fdimf(a: c_float, b: c_float) -> c_float; 33 | pub fn hypot(x: c_double, y: c_double) -> c_double; 34 | pub fn hypotf(x: c_float, y: c_float) -> c_float; 35 | pub fn log1p(n: c_double) -> c_double; 36 | pub fn log1pf(n: c_float) -> c_float; 37 | pub fn sinh(n: c_double) -> c_double; 38 | pub fn sinhf(n: c_float) -> c_float; 39 | pub fn tan(n: c_double) -> c_double; 40 | pub fn tanf(n: c_float) -> c_float; 41 | pub fn tanh(n: c_double) -> c_double; 42 | pub fn tanhf(n: c_float) -> c_float; 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/env.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub mod os { 12 | pub const FAMILY: &'static str = "redox"; 13 | pub const OS: &'static str = "redox"; 14 | pub const DLL_PREFIX: &'static str = "lib"; 15 | pub const DLL_SUFFIX: &'static str = ".so"; 16 | pub const DLL_EXTENSION: &'static str = "so"; 17 | pub const EXE_SUFFIX: &'static str = ""; 18 | pub const EXE_EXTENSION: &'static str = ""; 19 | } 20 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/ext/ffi.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Redox-specific extension to the primitives in the `std::ffi` module. 12 | 13 | #![stable(feature = "rust1", since = "1.0.0")] 14 | 15 | use ffi::{OsStr, OsString}; 16 | use mem; 17 | use sys::os_str::Buf; 18 | use sys_common::{FromInner, IntoInner, AsInner}; 19 | 20 | /// Redox-specific extensions to [`OsString`]. 21 | /// 22 | /// [`OsString`]: ../../../../std/ffi/struct.OsString.html 23 | #[stable(feature = "rust1", since = "1.0.0")] 24 | pub trait OsStringExt { 25 | /// Creates an `OsString` from a byte vector. 26 | #[stable(feature = "rust1", since = "1.0.0")] 27 | fn from_vec(vec: Vec) -> Self; 28 | 29 | /// Yields the underlying byte vector of this `OsString`. 30 | #[stable(feature = "rust1", since = "1.0.0")] 31 | fn into_vec(self) -> Vec; 32 | } 33 | 34 | #[stable(feature = "rust1", since = "1.0.0")] 35 | impl OsStringExt for OsString { 36 | fn from_vec(vec: Vec) -> OsString { 37 | FromInner::from_inner(Buf { inner: vec }) 38 | } 39 | fn into_vec(self) -> Vec { 40 | self.into_inner().inner 41 | } 42 | } 43 | 44 | /// Redox-specific extensions to [`OsStr`]. 45 | /// 46 | /// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html 47 | #[stable(feature = "rust1", since = "1.0.0")] 48 | pub trait OsStrExt { 49 | #[stable(feature = "rust1", since = "1.0.0")] 50 | fn from_bytes(slice: &[u8]) -> &Self; 51 | 52 | /// Gets the underlying byte view of the `OsStr` slice. 53 | #[stable(feature = "rust1", since = "1.0.0")] 54 | fn as_bytes(&self) -> &[u8]; 55 | } 56 | 57 | #[stable(feature = "rust1", since = "1.0.0")] 58 | impl OsStrExt for OsStr { 59 | fn from_bytes(slice: &[u8]) -> &OsStr { 60 | unsafe { mem::transmute(slice) } 61 | } 62 | fn as_bytes(&self) -> &[u8] { 63 | &self.as_inner().inner 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/ext/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Experimental extensions to `std` for Unix platforms. 12 | //! 13 | //! For now, this module is limited to extracting file descriptors, 14 | //! but its functionality will grow over time. 15 | //! 16 | //! # Examples 17 | //! 18 | //! ```no_run 19 | //! use std::fs::File; 20 | //! use std::os::unix::prelude::*; 21 | //! 22 | //! fn main() { 23 | //! let f = File::create("foo.txt").unwrap(); 24 | //! let fd = f.as_raw_fd(); 25 | //! 26 | //! // use fd with native unix bindings 27 | //! } 28 | //! ``` 29 | 30 | #![stable(feature = "rust1", since = "1.0.0")] 31 | #![doc(cfg(target_os = "redox"))] 32 | 33 | pub mod ffi; 34 | pub mod fs; 35 | pub mod io; 36 | pub mod net; 37 | pub mod process; 38 | pub mod thread; 39 | 40 | /// A prelude for conveniently writing platform-specific code. 41 | /// 42 | /// Includes all extension traits, and some important type definitions. 43 | #[stable(feature = "rust1", since = "1.0.0")] 44 | pub mod prelude { 45 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 46 | pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; 47 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 48 | pub use super::ffi::{OsStrExt, OsStringExt}; 49 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 50 | pub use super::fs::{FileTypeExt, PermissionsExt, OpenOptionsExt, MetadataExt}; 51 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 52 | pub use super::thread::JoinHandleExt; 53 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 54 | pub use super::process::{CommandExt, ExitStatusExt}; 55 | } 56 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/ext/thread.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Redox-specific extensions to primitives in the `std::thread` module. 12 | 13 | #![stable(feature = "thread_extensions", since = "1.9.0")] 14 | 15 | use sys_common::{AsInner, IntoInner}; 16 | use thread::JoinHandle; 17 | 18 | #[stable(feature = "thread_extensions", since = "1.9.0")] 19 | #[allow(deprecated)] 20 | pub type RawPthread = usize; 21 | 22 | /// Redox-specific extensions to [`thread::JoinHandle`]. 23 | /// 24 | /// [`thread::JoinHandle`]: ../../../../std/thread/struct.JoinHandle.html 25 | #[stable(feature = "thread_extensions", since = "1.9.0")] 26 | pub trait JoinHandleExt { 27 | /// Extracts the raw pthread_t without taking ownership 28 | #[stable(feature = "thread_extensions", since = "1.9.0")] 29 | fn as_pthread_t(&self) -> RawPthread; 30 | 31 | /// Consumes the thread, returning the raw pthread_t 32 | /// 33 | /// This function **transfers ownership** of the underlying pthread_t to 34 | /// the caller. Callers are then the unique owners of the pthread_t and 35 | /// must either detach or join the pthread_t once it's no longer needed. 36 | #[stable(feature = "thread_extensions", since = "1.9.0")] 37 | fn into_pthread_t(self) -> RawPthread; 38 | } 39 | 40 | #[stable(feature = "thread_extensions", since = "1.9.0")] 41 | impl JoinHandleExt for JoinHandle { 42 | fn as_pthread_t(&self) -> RawPthread { 43 | self.as_inner().id() as RawPthread 44 | } 45 | 46 | fn into_pthread_t(self) -> RawPthread { 47 | self.into_inner().into_id() as RawPthread 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/memchr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | // 11 | // Original implementation taken from rust-memchr 12 | // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch 13 | 14 | pub use core::slice::memchr::{memchr, memrchr}; 15 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code, missing_docs, bad_style)] 12 | 13 | use io::{self, ErrorKind}; 14 | 15 | pub use libc::strlen; 16 | pub use self::rand::hashmap_random_keys; 17 | 18 | pub mod args; 19 | #[cfg(feature = "backtrace")] 20 | pub mod backtrace; 21 | pub mod cmath; 22 | pub mod condvar; 23 | pub mod env; 24 | pub mod ext; 25 | pub mod fast_thread_local; 26 | pub mod fd; 27 | pub mod fs; 28 | pub mod memchr; 29 | pub mod mutex; 30 | pub mod net; 31 | pub mod os; 32 | pub mod os_str; 33 | pub mod path; 34 | pub mod pipe; 35 | pub mod process; 36 | pub mod rand; 37 | pub mod rwlock; 38 | pub mod stack_overflow; 39 | pub mod stdio; 40 | pub mod syscall; 41 | pub mod thread; 42 | pub mod thread_local; 43 | pub mod time; 44 | 45 | #[cfg(not(test))] 46 | pub fn init() {} 47 | 48 | pub fn decode_error_kind(errno: i32) -> ErrorKind { 49 | match errno { 50 | syscall::ECONNREFUSED => ErrorKind::ConnectionRefused, 51 | syscall::ECONNRESET => ErrorKind::ConnectionReset, 52 | syscall::EPERM | syscall::EACCES => ErrorKind::PermissionDenied, 53 | syscall::EPIPE => ErrorKind::BrokenPipe, 54 | syscall::ENOTCONN => ErrorKind::NotConnected, 55 | syscall::ECONNABORTED => ErrorKind::ConnectionAborted, 56 | syscall::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable, 57 | syscall::EADDRINUSE => ErrorKind::AddrInUse, 58 | syscall::ENOENT => ErrorKind::NotFound, 59 | syscall::EINTR => ErrorKind::Interrupted, 60 | syscall::EINVAL => ErrorKind::InvalidInput, 61 | syscall::ETIMEDOUT => ErrorKind::TimedOut, 62 | syscall::EEXIST => ErrorKind::AlreadyExists, 63 | 64 | // These two constants can have the same value on some systems, 65 | // but different values on others, so we can't use a match 66 | // clause 67 | x if x == syscall::EAGAIN || x == syscall::EWOULDBLOCK => 68 | ErrorKind::WouldBlock, 69 | 70 | _ => ErrorKind::Other, 71 | } 72 | } 73 | 74 | pub fn cvt(result: Result) -> io::Result { 75 | result.map_err(|err| io::Error::from_raw_os_error(err.errno)) 76 | } 77 | 78 | /// On Redox, use an illegal instruction to abort 79 | pub unsafe fn abort_internal() -> ! { 80 | ::core::intrinsics::abort(); 81 | } 82 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/net/dns/answer.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use string::String; 12 | use vec::Vec; 13 | 14 | #[derive(Clone, Debug)] 15 | pub struct DnsAnswer { 16 | pub name: String, 17 | pub a_type: u16, 18 | pub a_class: u16, 19 | pub ttl_a: u16, 20 | pub ttl_b: u16, 21 | pub data: Vec 22 | } 23 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/net/dns/query.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use string::String; 12 | 13 | #[derive(Clone, Debug)] 14 | pub struct DnsQuery { 15 | pub name: String, 16 | pub q_type: u16, 17 | pub q_class: u16 18 | } 19 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/net/netc.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub type in_addr_t = u32; 12 | pub type in_port_t = u16; 13 | 14 | pub type socklen_t = u32; 15 | pub type sa_family_t = u16; 16 | 17 | pub const AF_INET: sa_family_t = 2; 18 | pub const AF_INET6: sa_family_t = 23; 19 | 20 | #[derive(Copy, Clone)] 21 | #[repr(C)] 22 | pub struct in_addr { 23 | pub s_addr: in_addr_t, 24 | } 25 | 26 | #[derive(Copy, Clone)] 27 | #[repr(align(4))] 28 | #[repr(C)] 29 | pub struct in6_addr { 30 | pub s6_addr: [u8; 16], 31 | } 32 | 33 | #[derive(Copy, Clone)] 34 | #[repr(C)] 35 | pub struct sockaddr { 36 | pub sa_family: sa_family_t, 37 | pub sa_data: [u8; 14], 38 | } 39 | 40 | #[derive(Copy, Clone)] 41 | #[repr(C)] 42 | pub struct sockaddr_in { 43 | pub sin_family: sa_family_t, 44 | pub sin_port: in_port_t, 45 | pub sin_addr: in_addr, 46 | pub sin_zero: [u8; 8], 47 | } 48 | 49 | #[derive(Copy, Clone)] 50 | #[repr(C)] 51 | pub struct sockaddr_in6 { 52 | pub sin6_family: sa_family_t, 53 | pub sin6_port: in_port_t, 54 | pub sin6_flowinfo: u32, 55 | pub sin6_addr: in6_addr, 56 | pub sin6_scope_id: u32, 57 | } 58 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/path.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ffi::OsStr; 12 | use path::Prefix; 13 | 14 | #[inline] 15 | pub fn is_sep_byte(b: u8) -> bool { 16 | b == b'/' 17 | } 18 | 19 | #[inline] 20 | pub fn is_verbatim_sep(b: u8) -> bool { 21 | b == b'/' 22 | } 23 | 24 | pub fn parse_prefix(path: &OsStr) -> Option { 25 | if let Some(path_str) = path.to_str() { 26 | if let Some(_i) = path_str.find(':') { 27 | // FIXME: Redox specific prefix 28 | // Some(Prefix::Verbatim(OsStr::new(&path_str[..i]))) 29 | None 30 | } else { 31 | None 32 | } 33 | } else { 34 | None 35 | } 36 | } 37 | 38 | pub const MAIN_SEP_STR: &'static str = "/"; 39 | pub const MAIN_SEP: char = '/'; 40 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/rand.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub fn hashmap_random_keys() -> (u64, u64) { 12 | (0, 0) 13 | } 14 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/rwlock.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use super::mutex::Mutex; 12 | 13 | pub struct RWLock { 14 | mutex: Mutex 15 | } 16 | 17 | unsafe impl Send for RWLock {} 18 | unsafe impl Sync for RWLock {} 19 | 20 | impl RWLock { 21 | pub const fn new() -> RWLock { 22 | RWLock { 23 | mutex: Mutex::new() 24 | } 25 | } 26 | 27 | #[inline] 28 | pub unsafe fn read(&self) { 29 | self.mutex.lock(); 30 | } 31 | 32 | #[inline] 33 | pub unsafe fn try_read(&self) -> bool { 34 | self.mutex.try_lock() 35 | } 36 | 37 | #[inline] 38 | pub unsafe fn write(&self) { 39 | self.mutex.lock(); 40 | } 41 | 42 | #[inline] 43 | pub unsafe fn try_write(&self) -> bool { 44 | self.mutex.try_lock() 45 | } 46 | 47 | #[inline] 48 | pub unsafe fn read_unlock(&self) { 49 | self.mutex.unlock(); 50 | } 51 | 52 | #[inline] 53 | pub unsafe fn write_unlock(&self) { 54 | self.mutex.unlock(); 55 | } 56 | 57 | #[inline] 58 | pub unsafe fn destroy(&self) { 59 | self.mutex.destroy(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/stack_overflow.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg_attr(test, allow(dead_code))] 12 | 13 | pub struct Handler; 14 | 15 | impl Handler { 16 | pub unsafe fn new() -> Handler { 17 | Handler 18 | } 19 | } 20 | 21 | pub unsafe fn init() { 22 | 23 | } 24 | 25 | pub unsafe fn cleanup() { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/stdio.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::{cvt, syscall}; 13 | use sys::fd::FileDesc; 14 | 15 | pub struct Stdin(()); 16 | pub struct Stdout(()); 17 | pub struct Stderr(()); 18 | 19 | impl Stdin { 20 | pub fn new() -> io::Result { Ok(Stdin(())) } 21 | 22 | pub fn read(&self, data: &mut [u8]) -> io::Result { 23 | let fd = FileDesc::new(0); 24 | let ret = fd.read(data); 25 | fd.into_raw(); 26 | ret 27 | } 28 | } 29 | 30 | impl Stdout { 31 | pub fn new() -> io::Result { Ok(Stdout(())) } 32 | 33 | pub fn write(&self, data: &[u8]) -> io::Result { 34 | let fd = FileDesc::new(1); 35 | let ret = fd.write(data); 36 | fd.into_raw(); 37 | ret 38 | } 39 | 40 | pub fn flush(&self) -> io::Result<()> { 41 | cvt(syscall::fsync(1)).and(Ok(())) 42 | } 43 | } 44 | 45 | impl Stderr { 46 | pub fn new() -> io::Result { Ok(Stderr(())) } 47 | 48 | pub fn write(&self, data: &[u8]) -> io::Result { 49 | let fd = FileDesc::new(2); 50 | let ret = fd.write(data); 51 | fd.into_raw(); 52 | ret 53 | } 54 | 55 | pub fn flush(&self) -> io::Result<()> { 56 | cvt(syscall::fsync(2)).and(Ok(())) 57 | } 58 | } 59 | 60 | // FIXME: right now this raw stderr handle is used in a few places because 61 | // std::io::stderr_raw isn't exposed, but once that's exposed this impl 62 | // should go away 63 | impl io::Write for Stderr { 64 | fn write(&mut self, data: &[u8]) -> io::Result { 65 | Stderr::write(self, data) 66 | } 67 | 68 | fn flush(&mut self) -> io::Result<()> { 69 | Stderr::flush(self) 70 | } 71 | } 72 | 73 | pub fn is_ebadf(err: &io::Error) -> bool { 74 | err.raw_os_error() == Some(::sys::syscall::EBADF as i32) 75 | } 76 | 77 | pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; 78 | 79 | pub fn stderr_prints_nothing() -> bool { 80 | false 81 | } 82 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/syscall/arch/arm.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use super::error::{Error, Result}; 12 | 13 | pub unsafe fn syscall0(mut a: usize) -> Result { 14 | asm!("swi $$0" 15 | : "={r0}"(a) 16 | : "{r7}"(a) 17 | : "memory" 18 | : "volatile"); 19 | 20 | Error::demux(a) 21 | } 22 | 23 | pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { 24 | asm!("swi $$0" 25 | : "={r0}"(a) 26 | : "{r7}"(a), "{r0}"(b) 27 | : "memory" 28 | : "volatile"); 29 | 30 | Error::demux(a) 31 | } 32 | 33 | // Clobbers all registers - special for clone 34 | pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { 35 | asm!("swi $$0" 36 | : "={r0}"(a) 37 | : "{r7}"(a), "{r0}"(b) 38 | : "memory", "r0", "r1", "r2", "r3", "r4" 39 | : "volatile"); 40 | 41 | Error::demux(a) 42 | } 43 | 44 | pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { 45 | asm!("swi $$0" 46 | : "={r0}"(a) 47 | : "{r7}"(a), "{r0}"(b), "{r1}"(c) 48 | : "memory" 49 | : "volatile"); 50 | 51 | Error::demux(a) 52 | } 53 | 54 | pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { 55 | asm!("swi $$0" 56 | : "={r0}"(a) 57 | : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d) 58 | : "memory" 59 | : "volatile"); 60 | 61 | Error::demux(a) 62 | } 63 | 64 | pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { 65 | asm!("swi $$0" 66 | : "={r0}"(a) 67 | : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e) 68 | : "memory" 69 | : "volatile"); 70 | 71 | Error::demux(a) 72 | } 73 | 74 | pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) 75 | -> Result { 76 | asm!("swi $$0" 77 | : "={r0}"(a) 78 | : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f) 79 | : "memory" 80 | : "volatile"); 81 | 82 | Error::demux(a) 83 | } 84 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/syscall/arch/x86.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use super::error::{Error, Result}; 12 | 13 | pub unsafe fn syscall0(mut a: usize) -> Result { 14 | asm!("int 0x80" 15 | : "={eax}"(a) 16 | : "{eax}"(a) 17 | : "memory" 18 | : "intel", "volatile"); 19 | 20 | Error::demux(a) 21 | } 22 | 23 | pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { 24 | asm!("int 0x80" 25 | : "={eax}"(a) 26 | : "{eax}"(a), "{ebx}"(b) 27 | : "memory" 28 | : "intel", "volatile"); 29 | 30 | Error::demux(a) 31 | } 32 | 33 | // Clobbers all registers - special for clone 34 | pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { 35 | asm!("int 0x80" 36 | : "={eax}"(a) 37 | : "{eax}"(a), "{ebx}"(b) 38 | : "memory", "ebx", "ecx", "edx", "esi", "edi" 39 | : "intel", "volatile"); 40 | 41 | Error::demux(a) 42 | } 43 | 44 | pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { 45 | asm!("int 0x80" 46 | : "={eax}"(a) 47 | : "{eax}"(a), "{ebx}"(b), "{ecx}"(c) 48 | : "memory" 49 | : "intel", "volatile"); 50 | 51 | Error::demux(a) 52 | } 53 | 54 | pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { 55 | asm!("int 0x80" 56 | : "={eax}"(a) 57 | : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d) 58 | : "memory" 59 | : "intel", "volatile"); 60 | 61 | Error::demux(a) 62 | } 63 | 64 | pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { 65 | asm!("int 0x80" 66 | : "={eax}"(a) 67 | : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e) 68 | : "memory" 69 | : "intel", "volatile"); 70 | 71 | Error::demux(a) 72 | } 73 | 74 | pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) 75 | -> Result { 76 | asm!("int 0x80" 77 | : "={eax}"(a) 78 | : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f) 79 | : "memory" 80 | : "intel", "volatile"); 81 | 82 | Error::demux(a) 83 | } 84 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/syscall/arch/x86_64.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use super::error::{Error, Result}; 12 | 13 | pub unsafe fn syscall0(mut a: usize) -> Result { 14 | asm!("int 0x80" 15 | : "={rax}"(a) 16 | : "{rax}"(a) 17 | : "memory" 18 | : "intel", "volatile"); 19 | 20 | Error::demux(a) 21 | } 22 | 23 | pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { 24 | asm!("int 0x80" 25 | : "={rax}"(a) 26 | : "{rax}"(a), "{rbx}"(b) 27 | : "memory" 28 | : "intel", "volatile"); 29 | 30 | Error::demux(a) 31 | } 32 | 33 | // Clobbers all registers - special for clone 34 | pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { 35 | asm!("int 0x80" 36 | : "={rax}"(a) 37 | : "{rax}"(a), "{rbx}"(b) 38 | : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", 39 | "r9", "r10", "r11", "r12", "r13", "r14", "r15" 40 | : "intel", "volatile"); 41 | 42 | Error::demux(a) 43 | } 44 | 45 | pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { 46 | asm!("int 0x80" 47 | : "={rax}"(a) 48 | : "{rax}"(a), "{rbx}"(b), "{rcx}"(c) 49 | : "memory" 50 | : "intel", "volatile"); 51 | 52 | Error::demux(a) 53 | } 54 | 55 | pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { 56 | asm!("int 0x80" 57 | : "={rax}"(a) 58 | : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d) 59 | : "memory" 60 | : "intel", "volatile"); 61 | 62 | Error::demux(a) 63 | } 64 | 65 | pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { 66 | asm!("int 0x80" 67 | : "={rax}"(a) 68 | : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e) 69 | : "memory" 70 | : "intel", "volatile"); 71 | 72 | Error::demux(a) 73 | } 74 | 75 | pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) 76 | -> Result { 77 | asm!("int 0x80" 78 | : "={rax}"(a) 79 | : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f) 80 | : "memory" 81 | : "intel", "volatile"); 82 | 83 | Error::demux(a) 84 | } 85 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/syscall/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use self::arch::*; 12 | pub use self::call::*; 13 | pub use self::data::*; 14 | pub use self::error::*; 15 | pub use self::flag::*; 16 | pub use self::number::*; 17 | 18 | #[cfg(target_arch = "arm")] 19 | #[path="arch/arm.rs"] 20 | mod arch; 21 | 22 | #[cfg(target_arch = "x86")] 23 | #[path="arch/x86.rs"] 24 | mod arch; 25 | 26 | #[cfg(target_arch = "x86_64")] 27 | #[path="arch/x86_64.rs"] 28 | mod arch; 29 | 30 | /// Function definitions 31 | pub mod call; 32 | 33 | /// Complex structures that are used for some system calls 34 | pub mod data; 35 | 36 | /// All errors that can be generated by a system call 37 | pub mod error; 38 | 39 | /// Flags used as an argument to many system calls 40 | pub mod flag; 41 | 42 | /// Call numbers used by each system call 43 | pub mod number; 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/redox/thread_local.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code)] // not used on all platforms 12 | 13 | use collections::BTreeMap; 14 | use ptr; 15 | use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; 16 | 17 | pub type Key = usize; 18 | 19 | type Dtor = unsafe extern fn(*mut u8); 20 | 21 | static NEXT_KEY: AtomicUsize = ATOMIC_USIZE_INIT; 22 | 23 | static mut KEYS: *mut BTreeMap> = ptr::null_mut(); 24 | 25 | #[thread_local] 26 | static mut LOCALS: *mut BTreeMap = ptr::null_mut(); 27 | 28 | unsafe fn keys() -> &'static mut BTreeMap> { 29 | if KEYS == ptr::null_mut() { 30 | KEYS = Box::into_raw(Box::new(BTreeMap::new())); 31 | } 32 | &mut *KEYS 33 | } 34 | 35 | unsafe fn locals() -> &'static mut BTreeMap { 36 | if LOCALS == ptr::null_mut() { 37 | LOCALS = Box::into_raw(Box::new(BTreeMap::new())); 38 | } 39 | &mut *LOCALS 40 | } 41 | 42 | #[inline] 43 | pub unsafe fn create(dtor: Option) -> Key { 44 | let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst); 45 | keys().insert(key, dtor); 46 | key 47 | } 48 | 49 | #[inline] 50 | pub unsafe fn get(key: Key) -> *mut u8 { 51 | if let Some(&entry) = locals().get(&key) { 52 | entry 53 | } else { 54 | ptr::null_mut() 55 | } 56 | } 57 | 58 | #[inline] 59 | pub unsafe fn set(key: Key, value: *mut u8) { 60 | locals().insert(key, value); 61 | } 62 | 63 | #[inline] 64 | pub unsafe fn destroy(key: Key) { 65 | keys().remove(&key); 66 | } 67 | 68 | #[inline] 69 | pub fn requires_synchronized_create() -> bool { 70 | false 71 | } 72 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/backtrace/printing/dladdr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use intrinsics; 13 | use ffi::CStr; 14 | use libc; 15 | use sys::backtrace::BacktraceContext; 16 | use sys_common::backtrace::Frame; 17 | 18 | pub fn resolve_symname(frame: Frame, 19 | callback: F, 20 | _: &BacktraceContext) -> io::Result<()> 21 | where F: FnOnce(Option<&str>) -> io::Result<()> 22 | { 23 | unsafe { 24 | let mut info: Dl_info = intrinsics::init(); 25 | let symname = if dladdr(frame.exact_position as *mut _, &mut info) == 0 || 26 | info.dli_sname.is_null() { 27 | None 28 | } else { 29 | CStr::from_ptr(info.dli_sname).to_str().ok() 30 | }; 31 | callback(symname) 32 | } 33 | } 34 | 35 | #[repr(C)] 36 | struct Dl_info { 37 | dli_fname: *const libc::c_char, 38 | dli_fbase: *mut libc::c_void, 39 | dli_sname: *const libc::c_char, 40 | dli_saddr: *mut libc::c_void, 41 | } 42 | 43 | extern { 44 | fn dladdr(addr: *const libc::c_void, info: *mut Dl_info) -> libc::c_int; 45 | } 46 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/backtrace/printing/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | mod dladdr; 12 | 13 | use sys::backtrace::BacktraceContext; 14 | use sys_common::backtrace::Frame; 15 | use io; 16 | 17 | #[cfg(target_os = "emscripten")] 18 | pub use self::dladdr::resolve_symname; 19 | 20 | #[cfg(target_os = "emscripten")] 21 | pub fn foreach_symbol_fileline(_: Frame, _: F, _: &BacktraceContext) -> io::Result 22 | where 23 | F: FnMut(&[u8], u32) -> io::Result<()> 24 | { 25 | Ok(false) 26 | } 27 | 28 | #[cfg(not(target_os = "emscripten"))] 29 | pub use sys_common::gnu::libbacktrace::foreach_symbol_fileline; 30 | 31 | #[cfg(not(target_os = "emscripten"))] 32 | pub fn resolve_symname(frame: Frame, callback: F, bc: &BacktraceContext) -> io::Result<()> 33 | where 34 | F: FnOnce(Option<&str>) -> io::Result<()> 35 | { 36 | ::sys_common::gnu::libbacktrace::resolve_symname(frame, |symname| { 37 | if symname.is_some() { 38 | callback(symname) 39 | } else { 40 | dladdr::resolve_symname(frame, callback, bc) 41 | } 42 | }, bc) 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/backtrace/tracing/backtrace_fn.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | /// As always - iOS on arm uses SjLj exceptions and 12 | /// _Unwind_Backtrace is even not available there. Still, 13 | /// backtraces could be extracted using a backtrace function, 14 | /// which thanks god is public 15 | /// 16 | /// As mentioned in a huge comment block in `super::super`, backtrace 17 | /// doesn't play well with green threads, so while it is extremely nice and 18 | /// simple to use it should be used only on iOS devices as the only viable 19 | /// option. 20 | 21 | use io; 22 | use libc; 23 | use sys::backtrace::BacktraceContext; 24 | use sys_common::backtrace::Frame; 25 | 26 | #[inline(never)] // if we know this is a function call, we can skip it when 27 | // tracing 28 | pub fn unwind_backtrace(frames: &mut [Frame]) 29 | -> io::Result<(usize, BacktraceContext)> 30 | { 31 | const FRAME_LEN: usize = 100; 32 | assert!(FRAME_LEN >= frames.len()); 33 | let mut raw_frames = [::ptr::null_mut(); FRAME_LEN]; 34 | let nb_frames = unsafe { 35 | backtrace(raw_frames.as_mut_ptr(), raw_frames.len() as libc::c_int) 36 | } as usize; 37 | for (from, to) in raw_frames.iter().zip(frames.iter_mut()).take(nb_frames) { 38 | *to = Frame { 39 | exact_position: *from as *mut u8, 40 | symbol_addr: *from as *mut u8, 41 | inline_context: 0, 42 | }; 43 | } 44 | Ok((nb_frames as usize, BacktraceContext)) 45 | } 46 | 47 | extern { 48 | fn backtrace(buf: *mut *mut libc::c_void, sz: libc::c_int) -> libc::c_int; 49 | } 50 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/backtrace/tracing/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use self::imp::*; 12 | 13 | #[cfg(not(all(target_os = "ios", target_arch = "arm")))] 14 | #[path = "gcc_s.rs"] 15 | mod imp; 16 | #[cfg(all(target_os = "ios", target_arch = "arm"))] 17 | #[path = "backtrace_fn.rs"] 18 | mod imp; 19 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/cmath.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg(not(test))] 12 | 13 | use libc::{c_float, c_double}; 14 | 15 | #[link_name = "m"] 16 | extern { 17 | pub fn acos(n: c_double) -> c_double; 18 | pub fn acosf(n: c_float) -> c_float; 19 | pub fn asin(n: c_double) -> c_double; 20 | pub fn asinf(n: c_float) -> c_float; 21 | pub fn atan(n: c_double) -> c_double; 22 | pub fn atan2(a: c_double, b: c_double) -> c_double; 23 | pub fn atan2f(a: c_float, b: c_float) -> c_float; 24 | pub fn atanf(n: c_float) -> c_float; 25 | pub fn cbrt(n: c_double) -> c_double; 26 | pub fn cbrtf(n: c_float) -> c_float; 27 | pub fn cosh(n: c_double) -> c_double; 28 | pub fn coshf(n: c_float) -> c_float; 29 | pub fn expm1(n: c_double) -> c_double; 30 | pub fn expm1f(n: c_float) -> c_float; 31 | pub fn fdim(a: c_double, b: c_double) -> c_double; 32 | pub fn fdimf(a: c_float, b: c_float) -> c_float; 33 | pub fn hypot(x: c_double, y: c_double) -> c_double; 34 | pub fn hypotf(x: c_float, y: c_float) -> c_float; 35 | pub fn log1p(n: c_double) -> c_double; 36 | pub fn log1pf(n: c_float) -> c_float; 37 | pub fn sinh(n: c_double) -> c_double; 38 | pub fn sinhf(n: c_float) -> c_float; 39 | pub fn tan(n: c_double) -> c_double; 40 | pub fn tanf(n: c_float) -> c_float; 41 | pub fn tanh(n: c_double) -> c_double; 42 | pub fn tanhf(n: c_float) -> c_float; 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/ext/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Experimental extensions to `std` for Unix platforms. 12 | //! 13 | //! Provides access to platform-level information on Unix platforms, and 14 | //! exposes Unix-specific functions that would otherwise be inappropriate as 15 | //! part of the core `std` library. 16 | //! 17 | //! It exposes more ways to deal with platform-specific strings (`OsStr`, 18 | //! `OsString`), allows to set permissions more granularly, extract low-level 19 | //! file descriptors from files and sockets, and has platform-specific helpers 20 | //! for spawning processes. 21 | //! 22 | //! # Examples 23 | //! 24 | //! ```no_run 25 | //! use std::fs::File; 26 | //! use std::os::unix::prelude::*; 27 | //! 28 | //! fn main() { 29 | //! let f = File::create("foo.txt").unwrap(); 30 | //! let fd = f.as_raw_fd(); 31 | //! 32 | //! // use fd with native unix bindings 33 | //! } 34 | //! ``` 35 | 36 | #![stable(feature = "rust1", since = "1.0.0")] 37 | #![doc(cfg(unix))] 38 | #![allow(missing_docs)] 39 | 40 | pub mod io; 41 | pub mod ffi; 42 | pub mod fs; 43 | pub mod process; 44 | pub mod raw; 45 | pub mod thread; 46 | pub mod net; 47 | 48 | /// A prelude for conveniently writing platform-specific code. 49 | /// 50 | /// Includes all extension traits, and some important type definitions. 51 | #[stable(feature = "rust1", since = "1.0.0")] 52 | pub mod prelude { 53 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 54 | pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; 55 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 56 | pub use super::ffi::{OsStrExt, OsStringExt}; 57 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 58 | pub use super::fs::{PermissionsExt, OpenOptionsExt, MetadataExt, FileTypeExt}; 59 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 60 | pub use super::fs::DirEntryExt; 61 | #[doc(no_inline)] #[stable(feature = "file_offset", since = "1.15.0")] 62 | pub use super::fs::FileExt; 63 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 64 | pub use super::thread::JoinHandleExt; 65 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 66 | pub use super::process::{CommandExt, ExitStatusExt}; 67 | } 68 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/ext/raw.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Unix-specific primitives available on all unix platforms 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | #![rustc_deprecated(since = "1.8.0", 15 | reason = "these type aliases are no longer supported by \ 16 | the standard library, the `libc` crate on \ 17 | crates.io should be used instead for the correct \ 18 | definitions")] 19 | #![allow(deprecated)] 20 | 21 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type uid_t = u32; 22 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32; 23 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type pid_t = i32; 24 | 25 | #[doc(inline)] 26 | #[stable(feature = "pthread_t", since = "1.8.0")] 27 | pub use sys::platform::raw::pthread_t; 28 | #[doc(inline)] 29 | #[stable(feature = "raw_ext", since = "1.1.0")] 30 | pub use sys::platform::raw::{dev_t, ino_t, mode_t, nlink_t, off_t, blksize_t}; 31 | #[doc(inline)] 32 | #[stable(feature = "raw_ext", since = "1.1.0")] 33 | pub use sys::platform::raw::{blkcnt_t, time_t}; 34 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/ext/thread.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Unix-specific extensions to primitives in the `std::thread` module. 12 | 13 | #![stable(feature = "thread_extensions", since = "1.9.0")] 14 | 15 | #[allow(deprecated)] 16 | use os::unix::raw::pthread_t; 17 | use sys_common::{AsInner, IntoInner}; 18 | use thread::JoinHandle; 19 | 20 | #[stable(feature = "thread_extensions", since = "1.9.0")] 21 | #[allow(deprecated)] 22 | pub type RawPthread = pthread_t; 23 | 24 | /// Unix-specific extensions to [`thread::JoinHandle`]. 25 | /// 26 | /// [`thread::JoinHandle`]: ../../../../std/thread/struct.JoinHandle.html 27 | #[stable(feature = "thread_extensions", since = "1.9.0")] 28 | pub trait JoinHandleExt { 29 | /// Extracts the raw pthread_t without taking ownership 30 | #[stable(feature = "thread_extensions", since = "1.9.0")] 31 | fn as_pthread_t(&self) -> RawPthread; 32 | 33 | /// Consumes the thread, returning the raw pthread_t 34 | /// 35 | /// This function **transfers ownership** of the underlying pthread_t to 36 | /// the caller. Callers are then the unique owners of the pthread_t and 37 | /// must either detach or join the pthread_t once it's no longer needed. 38 | #[stable(feature = "thread_extensions", since = "1.9.0")] 39 | fn into_pthread_t(self) -> RawPthread; 40 | } 41 | 42 | #[stable(feature = "thread_extensions", since = "1.9.0")] 43 | impl JoinHandleExt for JoinHandle { 44 | fn as_pthread_t(&self) -> RawPthread { 45 | self.as_inner().id() as RawPthread 46 | } 47 | 48 | fn into_pthread_t(self) -> RawPthread { 49 | self.into_inner().into_id() as RawPthread 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/memchr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | // 11 | // Original implementation taken from rust-memchr 12 | // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch 13 | 14 | pub fn memchr(needle: u8, haystack: &[u8]) -> Option { 15 | use libc; 16 | 17 | let p = unsafe { 18 | libc::memchr( 19 | haystack.as_ptr() as *const libc::c_void, 20 | needle as libc::c_int, 21 | haystack.len()) 22 | }; 23 | if p.is_null() { 24 | None 25 | } else { 26 | Some(p as usize - (haystack.as_ptr() as usize)) 27 | } 28 | } 29 | 30 | pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { 31 | 32 | #[cfg(target_os = "linux")] 33 | fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { 34 | use libc; 35 | 36 | // GNU's memrchr() will - unlike memchr() - error if haystack is empty. 37 | if haystack.is_empty() {return None} 38 | let p = unsafe { 39 | libc::memrchr( 40 | haystack.as_ptr() as *const libc::c_void, 41 | needle as libc::c_int, 42 | haystack.len()) 43 | }; 44 | if p.is_null() { 45 | None 46 | } else { 47 | Some(p as usize - (haystack.as_ptr() as usize)) 48 | } 49 | } 50 | 51 | #[cfg(not(target_os = "linux"))] 52 | fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { 53 | ::core::slice::memchr::memrchr(needle, haystack) 54 | } 55 | 56 | memrchr_specific(needle, haystack) 57 | } 58 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/path.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use path::Prefix; 12 | use ffi::OsStr; 13 | 14 | #[inline] 15 | pub fn is_sep_byte(b: u8) -> bool { 16 | b == b'/' 17 | } 18 | 19 | #[inline] 20 | pub fn is_verbatim_sep(b: u8) -> bool { 21 | b == b'/' 22 | } 23 | 24 | pub fn parse_prefix(_: &OsStr) -> Option { 25 | None 26 | } 27 | 28 | pub const MAIN_SEP_STR: &'static str = "/"; 29 | pub const MAIN_SEP: char = '/'; 30 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/process/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use self::process_common::{Command, ExitStatus, ExitCode, Stdio, StdioPipes}; 12 | pub use self::process_inner::Process; 13 | 14 | mod process_common; 15 | #[cfg(not(target_os = "fuchsia"))] 16 | #[path = "process_unix.rs"] 17 | mod process_inner; 18 | #[cfg(target_os = "fuchsia")] 19 | #[path = "process_fuchsia.rs"] 20 | mod process_inner; 21 | #[cfg(target_os = "fuchsia")] 22 | mod zircon; 23 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/stdio.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use libc; 13 | use sys::fd::FileDesc; 14 | 15 | pub struct Stdin(()); 16 | pub struct Stdout(()); 17 | pub struct Stderr(()); 18 | 19 | impl Stdin { 20 | pub fn new() -> io::Result { Ok(Stdin(())) } 21 | 22 | pub fn read(&self, data: &mut [u8]) -> io::Result { 23 | let fd = FileDesc::new(libc::STDIN_FILENO); 24 | let ret = fd.read(data); 25 | fd.into_raw(); 26 | ret 27 | } 28 | } 29 | 30 | impl Stdout { 31 | pub fn new() -> io::Result { Ok(Stdout(())) } 32 | 33 | pub fn write(&self, data: &[u8]) -> io::Result { 34 | let fd = FileDesc::new(libc::STDOUT_FILENO); 35 | let ret = fd.write(data); 36 | fd.into_raw(); 37 | ret 38 | } 39 | 40 | pub fn flush(&self) -> io::Result<()> { 41 | Ok(()) 42 | } 43 | } 44 | 45 | impl Stderr { 46 | pub fn new() -> io::Result { Ok(Stderr(())) } 47 | 48 | pub fn write(&self, data: &[u8]) -> io::Result { 49 | let fd = FileDesc::new(libc::STDERR_FILENO); 50 | let ret = fd.write(data); 51 | fd.into_raw(); 52 | ret 53 | } 54 | 55 | pub fn flush(&self) -> io::Result<()> { 56 | Ok(()) 57 | } 58 | } 59 | 60 | // FIXME: right now this raw stderr handle is used in a few places because 61 | // std::io::stderr_raw isn't exposed, but once that's exposed this impl 62 | // should go away 63 | impl io::Write for Stderr { 64 | fn write(&mut self, data: &[u8]) -> io::Result { 65 | Stderr::write(self, data) 66 | } 67 | 68 | fn flush(&mut self) -> io::Result<()> { 69 | Stderr::flush(self) 70 | } 71 | } 72 | 73 | pub fn is_ebadf(err: &io::Error) -> bool { 74 | err.raw_os_error() == Some(libc::EBADF as i32) 75 | } 76 | 77 | pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; 78 | 79 | pub fn stderr_prints_nothing() -> bool { 80 | false 81 | } 82 | -------------------------------------------------------------------------------- /ctr-std/src/sys/unix/thread_local.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code)] // not used on all platforms 12 | 13 | use mem; 14 | use libc; 15 | 16 | pub type Key = libc::pthread_key_t; 17 | 18 | #[inline] 19 | pub unsafe fn create(dtor: Option) -> Key { 20 | let mut key = 0; 21 | assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0); 22 | key 23 | } 24 | 25 | #[inline] 26 | pub unsafe fn set(key: Key, value: *mut u8) { 27 | let r = libc::pthread_setspecific(key, value as *mut _); 28 | debug_assert_eq!(r, 0); 29 | } 30 | 31 | #[inline] 32 | pub unsafe fn get(key: Key) -> *mut u8 { 33 | libc::pthread_getspecific(key) as *mut u8 34 | } 35 | 36 | #[inline] 37 | pub unsafe fn destroy(key: Key) { 38 | let r = libc::pthread_key_delete(key); 39 | debug_assert_eq!(r, 0); 40 | } 41 | 42 | #[inline] 43 | pub fn requires_synchronized_create() -> bool { 44 | false 45 | } 46 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/args.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use ffi::OsString; 12 | use marker::PhantomData; 13 | use vec; 14 | use sys::ArgsSysCall; 15 | 16 | pub unsafe fn init(_argc: isize, _argv: *const *const u8) { 17 | // On wasm these should always be null, so there's nothing for us to do here 18 | } 19 | 20 | pub unsafe fn cleanup() { 21 | } 22 | 23 | pub fn args() -> Args { 24 | let v = ArgsSysCall::perform(); 25 | Args { 26 | iter: v.into_iter(), 27 | _dont_send_or_sync_me: PhantomData, 28 | } 29 | } 30 | 31 | pub struct Args { 32 | iter: vec::IntoIter, 33 | _dont_send_or_sync_me: PhantomData<*mut ()>, 34 | } 35 | 36 | impl Args { 37 | pub fn inner_debug(&self) -> &[OsString] { 38 | self.iter.as_slice() 39 | } 40 | } 41 | 42 | impl Iterator for Args { 43 | type Item = OsString; 44 | fn next(&mut self) -> Option { 45 | self.iter.next() 46 | } 47 | fn size_hint(&self) -> (usize, Option) { 48 | self.iter.size_hint() 49 | } 50 | } 51 | 52 | impl ExactSizeIterator for Args { 53 | fn len(&self) -> usize { 54 | self.iter.len() 55 | } 56 | } 57 | 58 | impl DoubleEndedIterator for Args { 59 | fn next_back(&mut self) -> Option { 60 | self.iter.next_back() 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/backtrace.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::unsupported; 13 | use sys_common::backtrace::Frame; 14 | 15 | pub struct BacktraceContext; 16 | 17 | pub fn unwind_backtrace(_frames: &mut [Frame]) 18 | -> io::Result<(usize, BacktraceContext)> 19 | { 20 | unsupported() 21 | } 22 | 23 | pub fn resolve_symname(_frame: Frame, 24 | _callback: F, 25 | _: &BacktraceContext) -> io::Result<()> 26 | where F: FnOnce(Option<&str>) -> io::Result<()> 27 | { 28 | unsupported() 29 | } 30 | 31 | pub fn foreach_symbol_fileline(_: Frame, 32 | _: F, 33 | _: &BacktraceContext) -> io::Result 34 | where F: FnMut(&[u8], u32) -> io::Result<()> 35 | { 36 | unsupported() 37 | } 38 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/condvar.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use sys::mutex::Mutex; 12 | use time::Duration; 13 | 14 | pub struct Condvar { } 15 | 16 | impl Condvar { 17 | pub const fn new() -> Condvar { 18 | Condvar { } 19 | } 20 | 21 | #[inline] 22 | pub unsafe fn init(&mut self) {} 23 | 24 | #[inline] 25 | pub unsafe fn notify_one(&self) { 26 | } 27 | 28 | #[inline] 29 | pub unsafe fn notify_all(&self) { 30 | } 31 | 32 | pub unsafe fn wait(&self, _mutex: &Mutex) { 33 | panic!("can't block with web assembly") 34 | } 35 | 36 | pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool { 37 | panic!("can't block with web assembly"); 38 | } 39 | 40 | #[inline] 41 | pub unsafe fn destroy(&self) { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/env.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub mod os { 12 | pub const FAMILY: &'static str = ""; 13 | pub const OS: &'static str = ""; 14 | pub const DLL_PREFIX: &'static str = ""; 15 | pub const DLL_SUFFIX: &'static str = ".wasm"; 16 | pub const DLL_EXTENSION: &'static str = "wasm"; 17 | pub const EXE_SUFFIX: &'static str = ".wasm"; 18 | pub const EXE_EXTENSION: &'static str = "wasm"; 19 | } 20 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/memchr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub use core::slice::memchr::{memchr, memrchr}; 12 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/mutex.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::UnsafeCell; 12 | 13 | pub struct Mutex { 14 | locked: UnsafeCell, 15 | } 16 | 17 | unsafe impl Send for Mutex {} 18 | unsafe impl Sync for Mutex {} // no threads on wasm 19 | 20 | impl Mutex { 21 | pub const fn new() -> Mutex { 22 | Mutex { locked: UnsafeCell::new(false) } 23 | } 24 | 25 | #[inline] 26 | pub unsafe fn init(&mut self) { 27 | } 28 | 29 | #[inline] 30 | pub unsafe fn lock(&self) { 31 | let locked = self.locked.get(); 32 | assert!(!*locked, "cannot recursively acquire mutex"); 33 | *locked = true; 34 | } 35 | 36 | #[inline] 37 | pub unsafe fn unlock(&self) { 38 | *self.locked.get() = false; 39 | } 40 | 41 | #[inline] 42 | pub unsafe fn try_lock(&self) -> bool { 43 | let locked = self.locked.get(); 44 | if *locked { 45 | false 46 | } else { 47 | *locked = true; 48 | true 49 | } 50 | } 51 | 52 | #[inline] 53 | pub unsafe fn destroy(&self) { 54 | } 55 | } 56 | 57 | // All empty stubs because wasm has no threads yet, so lock acquisition always 58 | // succeeds. 59 | pub struct ReentrantMutex { 60 | } 61 | 62 | impl ReentrantMutex { 63 | pub unsafe fn uninitialized() -> ReentrantMutex { 64 | ReentrantMutex { } 65 | } 66 | 67 | pub unsafe fn init(&mut self) {} 68 | 69 | pub unsafe fn lock(&self) {} 70 | 71 | #[inline] 72 | pub unsafe fn try_lock(&self) -> bool { 73 | true 74 | } 75 | 76 | pub unsafe fn unlock(&self) {} 77 | 78 | pub unsafe fn destroy(&self) {} 79 | } 80 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/path.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use path::Prefix; 12 | use ffi::OsStr; 13 | 14 | #[inline] 15 | pub fn is_sep_byte(b: u8) -> bool { 16 | b == b'/' 17 | } 18 | 19 | #[inline] 20 | pub fn is_verbatim_sep(b: u8) -> bool { 21 | b == b'/' 22 | } 23 | 24 | pub fn parse_prefix(_: &OsStr) -> Option { 25 | None 26 | } 27 | 28 | pub const MAIN_SEP_STR: &'static str = "/"; 29 | pub const MAIN_SEP: char = '/'; 30 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/pipe.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::Void; 13 | 14 | pub struct AnonPipe(Void); 15 | 16 | impl AnonPipe { 17 | pub fn read(&self, _buf: &mut [u8]) -> io::Result { 18 | match self.0 {} 19 | } 20 | 21 | pub fn write(&self, _buf: &[u8]) -> io::Result { 22 | match self.0 {} 23 | } 24 | 25 | pub fn diverge(&self) -> ! { 26 | match self.0 {} 27 | } 28 | } 29 | 30 | pub fn read2(p1: AnonPipe, 31 | _v1: &mut Vec, 32 | _p2: AnonPipe, 33 | _v2: &mut Vec) -> io::Result<()> { 34 | match p1.0 {} 35 | } 36 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/rwlock.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::UnsafeCell; 12 | 13 | pub struct RWLock { 14 | mode: UnsafeCell, 15 | } 16 | 17 | unsafe impl Send for RWLock {} 18 | unsafe impl Sync for RWLock {} // no threads on wasm 19 | 20 | impl RWLock { 21 | pub const fn new() -> RWLock { 22 | RWLock { 23 | mode: UnsafeCell::new(0), 24 | } 25 | } 26 | 27 | #[inline] 28 | pub unsafe fn read(&self) { 29 | let mode = self.mode.get(); 30 | if *mode >= 0 { 31 | *mode += 1; 32 | } else { 33 | rtabort!("rwlock locked for writing"); 34 | } 35 | } 36 | 37 | #[inline] 38 | pub unsafe fn try_read(&self) -> bool { 39 | let mode = self.mode.get(); 40 | if *mode >= 0 { 41 | *mode += 1; 42 | true 43 | } else { 44 | false 45 | } 46 | } 47 | 48 | #[inline] 49 | pub unsafe fn write(&self) { 50 | let mode = self.mode.get(); 51 | if *mode == 0 { 52 | *mode = -1; 53 | } else { 54 | rtabort!("rwlock locked for reading") 55 | } 56 | } 57 | 58 | #[inline] 59 | pub unsafe fn try_write(&self) -> bool { 60 | let mode = self.mode.get(); 61 | if *mode == 0 { 62 | *mode = -1; 63 | true 64 | } else { 65 | false 66 | } 67 | } 68 | 69 | #[inline] 70 | pub unsafe fn read_unlock(&self) { 71 | *self.mode.get() -= 1; 72 | } 73 | 74 | #[inline] 75 | pub unsafe fn write_unlock(&self) { 76 | *self.mode.get() += 1; 77 | } 78 | 79 | #[inline] 80 | pub unsafe fn destroy(&self) { 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/stack_overflow.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub struct Handler; 12 | 13 | impl Handler { 14 | pub unsafe fn new() -> Handler { 15 | Handler 16 | } 17 | } 18 | 19 | pub unsafe fn init() { 20 | } 21 | 22 | pub unsafe fn cleanup() { 23 | } 24 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/stdio.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::{ReadSysCall, WriteSysCall}; 13 | 14 | pub struct Stdin; 15 | pub struct Stdout; 16 | pub struct Stderr; 17 | 18 | impl Stdin { 19 | pub fn new() -> io::Result { 20 | Ok(Stdin) 21 | } 22 | 23 | pub fn read(&self, data: &mut [u8]) -> io::Result { 24 | Ok(ReadSysCall::perform(0, data)) 25 | } 26 | } 27 | 28 | impl Stdout { 29 | pub fn new() -> io::Result { 30 | Ok(Stdout) 31 | } 32 | 33 | pub fn write(&self, data: &[u8]) -> io::Result { 34 | WriteSysCall::perform(1, data); 35 | Ok(data.len()) 36 | } 37 | 38 | pub fn flush(&self) -> io::Result<()> { 39 | Ok(()) 40 | } 41 | } 42 | 43 | impl Stderr { 44 | pub fn new() -> io::Result { 45 | Ok(Stderr) 46 | } 47 | 48 | pub fn write(&self, data: &[u8]) -> io::Result { 49 | WriteSysCall::perform(2, data); 50 | Ok(data.len()) 51 | } 52 | 53 | pub fn flush(&self) -> io::Result<()> { 54 | Ok(()) 55 | } 56 | } 57 | 58 | impl io::Write for Stderr { 59 | fn write(&mut self, data: &[u8]) -> io::Result { 60 | (&*self).write(data) 61 | } 62 | fn flush(&mut self) -> io::Result<()> { 63 | (&*self).flush() 64 | } 65 | } 66 | 67 | pub const STDIN_BUF_SIZE: usize = 0; 68 | 69 | pub fn is_ebadf(_err: &io::Error) -> bool { 70 | true 71 | } 72 | 73 | pub fn stderr_prints_nothing() -> bool { 74 | !cfg!(feature = "wasm_syscall") 75 | } 76 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/thread.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use boxed::FnBox; 12 | use ffi::CStr; 13 | use io; 14 | use sys::{unsupported, Void}; 15 | use time::Duration; 16 | 17 | pub struct Thread(Void); 18 | 19 | pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; 20 | 21 | impl Thread { 22 | pub unsafe fn new<'a>(_stack: usize, _p: Box) 23 | -> io::Result 24 | { 25 | unsupported() 26 | } 27 | 28 | pub fn yield_now() { 29 | // do nothing 30 | } 31 | 32 | pub fn set_name(_name: &CStr) { 33 | // nope 34 | } 35 | 36 | pub fn sleep(_dur: Duration) { 37 | panic!("can't sleep"); 38 | } 39 | 40 | pub fn join(self) { 41 | match self.0 {} 42 | } 43 | } 44 | 45 | pub mod guard { 46 | pub type Guard = !; 47 | pub unsafe fn current() -> Option { None } 48 | pub unsafe fn init() -> Option { None } 49 | pub unsafe fn deinit() {} 50 | } 51 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/thread_local.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use boxed::Box; 12 | use ptr; 13 | 14 | pub type Key = usize; 15 | 16 | struct Allocated { 17 | value: *mut u8, 18 | dtor: Option, 19 | } 20 | 21 | #[inline] 22 | pub unsafe fn create(dtor: Option) -> Key { 23 | Box::into_raw(Box::new(Allocated { 24 | value: ptr::null_mut(), 25 | dtor, 26 | })) as usize 27 | } 28 | 29 | #[inline] 30 | pub unsafe fn set(key: Key, value: *mut u8) { 31 | (*(key as *mut Allocated)).value = value; 32 | } 33 | 34 | #[inline] 35 | pub unsafe fn get(key: Key) -> *mut u8 { 36 | (*(key as *mut Allocated)).value 37 | } 38 | 39 | #[inline] 40 | pub unsafe fn destroy(key: Key) { 41 | let key = Box::from_raw(key as *mut Allocated); 42 | if let Some(f) = key.dtor { 43 | f(key.value); 44 | } 45 | } 46 | 47 | #[inline] 48 | pub fn requires_synchronized_create() -> bool { 49 | false 50 | } 51 | -------------------------------------------------------------------------------- /ctr-std/src/sys/wasm/time.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use time::Duration; 12 | use sys::{TimeSysCall, TimeClock}; 13 | 14 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] 15 | pub struct Instant(Duration); 16 | 17 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] 18 | pub struct SystemTime(Duration); 19 | 20 | pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); 21 | 22 | impl Instant { 23 | pub fn now() -> Instant { 24 | Instant(TimeSysCall::perform(TimeClock::Monotonic)) 25 | } 26 | 27 | pub fn sub_instant(&self, other: &Instant) -> Duration { 28 | self.0 - other.0 29 | } 30 | 31 | pub fn add_duration(&self, other: &Duration) -> Instant { 32 | Instant(self.0 + *other) 33 | } 34 | 35 | pub fn sub_duration(&self, other: &Duration) -> Instant { 36 | Instant(self.0 - *other) 37 | } 38 | } 39 | 40 | impl SystemTime { 41 | pub fn now() -> SystemTime { 42 | SystemTime(TimeSysCall::perform(TimeClock::System)) 43 | } 44 | 45 | pub fn sub_time(&self, other: &SystemTime) 46 | -> Result { 47 | self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) 48 | } 49 | 50 | pub fn add_duration(&self, other: &Duration) -> SystemTime { 51 | SystemTime(self.0 + *other) 52 | } 53 | 54 | pub fn sub_duration(&self, other: &Duration) -> SystemTime { 55 | SystemTime(self.0 - *other) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/backtrace/backtrace_gnu.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use sys::c; 13 | use libc::c_char; 14 | use path::PathBuf; 15 | use fs::{OpenOptions, File}; 16 | use sys::ext::fs::OpenOptionsExt; 17 | use sys::handle::Handle; 18 | use super::super::{fill_utf16_buf, os2path, to_u16s, wide_char_to_multi_byte}; 19 | 20 | fn query_full_process_image_name() -> io::Result { 21 | unsafe { 22 | let process_handle = Handle::new(c::OpenProcess(c::PROCESS_QUERY_INFORMATION, 23 | c::FALSE, 24 | c::GetCurrentProcessId())); 25 | fill_utf16_buf(|buf, mut sz| { 26 | if c::QueryFullProcessImageNameW(process_handle.raw(), 0, buf, &mut sz) == 0 { 27 | 0 28 | } else { 29 | sz 30 | } 31 | }, os2path) 32 | } 33 | } 34 | 35 | fn lock_and_get_executable_filename() -> io::Result<(PathBuf, File)> { 36 | // We query the current image name, open the file without FILE_SHARE_DELETE so it 37 | // can't be moved and then get the current image name again. If the names are the 38 | // same than we have successfully locked the file 39 | let image_name1 = query_full_process_image_name()?; 40 | let file = OpenOptions::new() 41 | .read(true) 42 | .share_mode(c::FILE_SHARE_READ | c::FILE_SHARE_WRITE) 43 | .open(&image_name1)?; 44 | let image_name2 = query_full_process_image_name()?; 45 | 46 | if image_name1 != image_name2 { 47 | return Err(io::Error::new(io::ErrorKind::Other, 48 | "executable moved while trying to lock it")); 49 | } 50 | 51 | Ok((image_name1, file)) 52 | } 53 | 54 | // Get the executable filename for libbacktrace 55 | // This returns the path in the ANSI code page and a File which should remain open 56 | // for as long as the path should remain valid 57 | pub fn get_executable_filename() -> io::Result<(Vec, File)> { 58 | let (executable, file) = lock_and_get_executable_filename()?; 59 | let u16_executable = to_u16s(executable.into_os_string())?; 60 | Ok((wide_char_to_multi_byte(c::CP_ACP, c::WC_NO_BEST_FIT_CHARS, 61 | &u16_executable, true)?, file)) 62 | } 63 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/backtrace/printing/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #[cfg(target_env = "msvc")] 12 | #[path = "msvc.rs"] 13 | mod printing; 14 | 15 | #[cfg(target_env = "gnu")] 16 | mod printing { 17 | pub use sys_common::gnu::libbacktrace::{foreach_symbol_fileline, resolve_symname}; 18 | 19 | // dummy functions to mirror those present in msvc version. 20 | use sys::dynamic_lib::DynamicLibrary; 21 | use io; 22 | pub struct PrintingFnsEx {} 23 | pub struct PrintingFns64 {} 24 | pub fn load_printing_fns_ex(_: &DynamicLibrary) -> io::Result { 25 | Ok(PrintingFnsEx{}) 26 | } 27 | pub fn load_printing_fns_64(_: &DynamicLibrary) -> io::Result { 28 | Ok(PrintingFns64{}) 29 | } 30 | } 31 | 32 | pub use self::printing::{foreach_symbol_fileline, resolve_symname}; 33 | pub use self::printing::{load_printing_fns_ex, load_printing_fns_64, 34 | PrintingFnsEx, PrintingFns64}; 35 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/condvar.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::UnsafeCell; 12 | use sys::c; 13 | use sys::mutex::{self, Mutex}; 14 | use sys::os; 15 | use time::Duration; 16 | 17 | pub struct Condvar { inner: UnsafeCell } 18 | 19 | unsafe impl Send for Condvar {} 20 | unsafe impl Sync for Condvar {} 21 | 22 | impl Condvar { 23 | pub const fn new() -> Condvar { 24 | Condvar { inner: UnsafeCell::new(c::CONDITION_VARIABLE_INIT) } 25 | } 26 | 27 | #[inline] 28 | pub unsafe fn init(&mut self) {} 29 | 30 | #[inline] 31 | pub unsafe fn wait(&self, mutex: &Mutex) { 32 | let r = c::SleepConditionVariableSRW(self.inner.get(), 33 | mutex::raw(mutex), 34 | c::INFINITE, 35 | 0); 36 | debug_assert!(r != 0); 37 | } 38 | 39 | pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool { 40 | let r = c::SleepConditionVariableSRW(self.inner.get(), 41 | mutex::raw(mutex), 42 | super::dur2timeout(dur), 43 | 0); 44 | if r == 0 { 45 | debug_assert_eq!(os::errno() as usize, c::ERROR_TIMEOUT as usize); 46 | false 47 | } else { 48 | true 49 | } 50 | } 51 | 52 | #[inline] 53 | pub unsafe fn notify_one(&self) { 54 | c::WakeConditionVariable(self.inner.get()) 55 | } 56 | 57 | #[inline] 58 | pub unsafe fn notify_all(&self) { 59 | c::WakeAllConditionVariable(self.inner.get()) 60 | } 61 | 62 | pub unsafe fn destroy(&self) { 63 | // ... 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/dynamic_lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use os::windows::prelude::*; 12 | 13 | use ffi::{CString, OsStr}; 14 | use io; 15 | use sys::c; 16 | 17 | pub struct DynamicLibrary { 18 | handle: c::HMODULE, 19 | } 20 | 21 | impl DynamicLibrary { 22 | pub fn open(filename: &str) -> io::Result { 23 | let filename = OsStr::new(filename) 24 | .encode_wide() 25 | .chain(Some(0)) 26 | .collect::>(); 27 | let result = unsafe { 28 | c::LoadLibraryW(filename.as_ptr()) 29 | }; 30 | if result.is_null() { 31 | Err(io::Error::last_os_error()) 32 | } else { 33 | Ok(DynamicLibrary { handle: result }) 34 | } 35 | } 36 | 37 | pub fn symbol(&self, symbol: &str) -> io::Result { 38 | let symbol = CString::new(symbol)?; 39 | unsafe { 40 | match c::GetProcAddress(self.handle, symbol.as_ptr()) as usize { 41 | 0 => Err(io::Error::last_os_error()), 42 | n => Ok(n), 43 | } 44 | } 45 | } 46 | } 47 | 48 | impl Drop for DynamicLibrary { 49 | fn drop(&mut self) { 50 | unsafe { 51 | c::FreeLibrary(self.handle); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/env.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | pub mod os { 12 | pub const FAMILY: &'static str = "windows"; 13 | pub const OS: &'static str = "windows"; 14 | pub const DLL_PREFIX: &'static str = ""; 15 | pub const DLL_SUFFIX: &'static str = ".dll"; 16 | pub const DLL_EXTENSION: &'static str = "dll"; 17 | pub const EXE_SUFFIX: &'static str = ".exe"; 18 | pub const EXE_EXTENSION: &'static str = "exe"; 19 | } 20 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/ext/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Platform-specific extensions to `std` for Windows. 12 | //! 13 | //! Provides access to platform-level information for Windows, and exposes 14 | //! Windows-specific idioms that would otherwise be inappropriate as part 15 | //! the core `std` library. These extensions allow developers to use 16 | //! `std` types and idioms with Windows in a way that the normal 17 | //! platform-agnostic idioms would not normally support. 18 | 19 | #![stable(feature = "rust1", since = "1.0.0")] 20 | #![doc(cfg(windows))] 21 | #![allow(missing_docs)] 22 | 23 | pub mod ffi; 24 | pub mod fs; 25 | pub mod io; 26 | pub mod raw; 27 | pub mod process; 28 | pub mod thread; 29 | 30 | /// A prelude for conveniently writing platform-specific code. 31 | /// 32 | /// Includes all extension traits, and some important type definitions. 33 | #[stable(feature = "rust1", since = "1.0.0")] 34 | pub mod prelude { 35 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 36 | pub use super::io::{RawSocket, RawHandle, AsRawSocket, AsRawHandle}; 37 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 38 | pub use super::io::{FromRawSocket, FromRawHandle, IntoRawSocket, IntoRawHandle}; 39 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 40 | pub use super::ffi::{OsStrExt, OsStringExt}; 41 | #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] 42 | pub use super::fs::{OpenOptionsExt, MetadataExt}; 43 | #[doc(no_inline)] #[stable(feature = "file_offset", since = "1.15.0")] 44 | pub use super::fs::FileExt; 45 | } 46 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/ext/raw.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Windows-specific primitives 12 | 13 | #![stable(feature = "raw_ext", since = "1.1.0")] 14 | 15 | use os::raw::c_void; 16 | 17 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type HANDLE = *mut c_void; 18 | #[cfg(target_pointer_width = "32")] 19 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type SOCKET = u32; 20 | #[cfg(target_pointer_width = "64")] 21 | #[stable(feature = "raw_ext", since = "1.1.0")] pub type SOCKET = u64; 22 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/ext/thread.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | //! Extensions to `std::thread` for Windows. 12 | 13 | #![stable(feature = "thread_extensions", since = "1.9.0")] 14 | 15 | use os::windows::io::{RawHandle, AsRawHandle, IntoRawHandle}; 16 | use thread; 17 | use sys_common::{AsInner, IntoInner}; 18 | 19 | #[stable(feature = "thread_extensions", since = "1.9.0")] 20 | impl AsRawHandle for thread::JoinHandle { 21 | fn as_raw_handle(&self) -> RawHandle { 22 | self.as_inner().handle().raw() as *mut _ 23 | } 24 | } 25 | 26 | #[stable(feature = "thread_extensions", since = "1.9.0")] 27 | impl IntoRawHandle for thread::JoinHandle { 28 | fn into_raw_handle(self) -> RawHandle { 29 | self.into_inner().into_handle().into_raw() as *mut _ 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/fast_thread_local.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![unstable(feature = "thread_local_internals", issue = "0")] 12 | #![cfg(target_thread_local)] 13 | 14 | pub use sys_common::thread_local::register_dtor_fallback as register_dtor; 15 | 16 | pub fn requires_move_before_drop() -> bool { 17 | false 18 | } 19 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/memchr.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | // 11 | // Original implementation taken from rust-memchr 12 | // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch 13 | 14 | // Fallback memchr is fastest on windows 15 | pub use core::slice::memchr::{memchr, memrchr}; 16 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/rand.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use io; 12 | use mem; 13 | use sys::c; 14 | 15 | pub fn hashmap_random_keys() -> (u64, u64) { 16 | let mut v = (0, 0); 17 | let ret = unsafe { 18 | c::RtlGenRandom(&mut v as *mut _ as *mut u8, 19 | mem::size_of_val(&v) as c::ULONG) 20 | }; 21 | if ret == 0 { 22 | panic!("couldn't generate random bytes: {}", 23 | io::Error::last_os_error()); 24 | } 25 | return v 26 | } 27 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/rwlock.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use cell::UnsafeCell; 12 | use sys::c; 13 | 14 | pub struct RWLock { inner: UnsafeCell } 15 | 16 | unsafe impl Send for RWLock {} 17 | unsafe impl Sync for RWLock {} 18 | 19 | impl RWLock { 20 | pub const fn new() -> RWLock { 21 | RWLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) } 22 | } 23 | #[inline] 24 | pub unsafe fn read(&self) { 25 | c::AcquireSRWLockShared(self.inner.get()) 26 | } 27 | #[inline] 28 | pub unsafe fn try_read(&self) -> bool { 29 | c::TryAcquireSRWLockShared(self.inner.get()) != 0 30 | } 31 | #[inline] 32 | pub unsafe fn write(&self) { 33 | c::AcquireSRWLockExclusive(self.inner.get()) 34 | } 35 | #[inline] 36 | pub unsafe fn try_write(&self) -> bool { 37 | c::TryAcquireSRWLockExclusive(self.inner.get()) != 0 38 | } 39 | #[inline] 40 | pub unsafe fn read_unlock(&self) { 41 | c::ReleaseSRWLockShared(self.inner.get()) 42 | } 43 | #[inline] 44 | pub unsafe fn write_unlock(&self) { 45 | c::ReleaseSRWLockExclusive(self.inner.get()) 46 | } 47 | 48 | #[inline] 49 | pub unsafe fn destroy(&self) { 50 | // ... 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ctr-std/src/sys/windows/stack_overflow.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![cfg_attr(test, allow(dead_code))] 12 | 13 | use sys_common::util::report_overflow; 14 | use sys::c; 15 | 16 | pub struct Handler; 17 | 18 | impl Handler { 19 | pub unsafe fn new() -> Handler { 20 | // This API isn't available on XP, so don't panic in that case and just 21 | // pray it works out ok. 22 | if c::SetThreadStackGuarantee(&mut 0x5000) == 0 { 23 | if c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32 { 24 | panic!("failed to reserve stack space for exception handling"); 25 | } 26 | } 27 | Handler 28 | } 29 | } 30 | 31 | extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) 32 | -> c::LONG { 33 | unsafe { 34 | let rec = &(*(*ExceptionInfo).ExceptionRecord); 35 | let code = rec.ExceptionCode; 36 | 37 | if code == c::EXCEPTION_STACK_OVERFLOW { 38 | report_overflow(); 39 | } 40 | c::EXCEPTION_CONTINUE_SEARCH 41 | } 42 | } 43 | 44 | pub unsafe fn init() { 45 | if c::AddVectoredExceptionHandler(0, vectored_handler).is_null() { 46 | panic!("failed to install exception handler"); 47 | } 48 | // Set the thread stack guarantee for the main thread. 49 | let _h = Handler::new(); 50 | } 51 | 52 | pub unsafe fn cleanup() {} 53 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/bytestring.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code)] 12 | 13 | use fmt::{Formatter, Result, Write}; 14 | use core::str::lossy::{Utf8Lossy, Utf8LossyChunk}; 15 | 16 | pub fn debug_fmt_bytestring(slice: &[u8], f: &mut Formatter) -> Result { 17 | // Writes out a valid unicode string with the correct escape sequences 18 | fn write_str_escaped(f: &mut Formatter, s: &str) -> Result { 19 | for c in s.chars().flat_map(|c| c.escape_debug()) { 20 | f.write_char(c)? 21 | } 22 | Ok(()) 23 | } 24 | 25 | f.write_str("\"")?; 26 | for Utf8LossyChunk { valid, broken } in Utf8Lossy::from_bytes(slice).chunks() { 27 | write_str_escaped(f, valid)?; 28 | for b in broken { 29 | write!(f, "\\x{:02X}", b)?; 30 | } 31 | } 32 | f.write_str("\"") 33 | } 34 | 35 | #[cfg(test)] 36 | mod tests { 37 | use super::*; 38 | use fmt::{Formatter, Result, Debug}; 39 | 40 | #[test] 41 | fn smoke() { 42 | struct Helper<'a>(&'a [u8]); 43 | 44 | impl<'a> Debug for Helper<'a> { 45 | fn fmt(&self, f: &mut Formatter) -> Result { 46 | debug_fmt_bytestring(self.0, f) 47 | } 48 | } 49 | 50 | let input = b"\xF0hello,\tworld"; 51 | let expected = r#""\xF0hello,\tworld""#; 52 | let output = format!("{:?}", Helper(input)); 53 | 54 | assert!(output == expected); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/gnu/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(missing_docs)] 12 | #![allow(non_camel_case_types)] 13 | #![allow(non_snake_case)] 14 | 15 | pub mod libbacktrace; 16 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/io.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; 11 | 12 | #[cfg(test)] 13 | #[allow(dead_code)] // not used on emscripten 14 | pub mod test { 15 | use path::{Path, PathBuf}; 16 | use env; 17 | use rand::{self, Rng}; 18 | use fs; 19 | 20 | pub struct TempDir(PathBuf); 21 | 22 | impl TempDir { 23 | pub fn join(&self, path: &str) -> PathBuf { 24 | let TempDir(ref p) = *self; 25 | p.join(path) 26 | } 27 | 28 | pub fn path<'a>(&'a self) -> &'a Path { 29 | let TempDir(ref p) = *self; 30 | p 31 | } 32 | } 33 | 34 | impl Drop for TempDir { 35 | fn drop(&mut self) { 36 | // Gee, seeing how we're testing the fs module I sure hope that we 37 | // at least implement this correctly! 38 | let TempDir(ref p) = *self; 39 | fs::remove_dir_all(p).unwrap(); 40 | } 41 | } 42 | 43 | pub fn tmpdir() -> TempDir { 44 | let p = env::temp_dir(); 45 | let mut r = rand::thread_rng(); 46 | let ret = p.join(&format!("rust-{}", r.next_u32())); 47 | fs::create_dir(&ret).unwrap(); 48 | TempDir(ret) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/thread.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use boxed::FnBox; 12 | use env; 13 | use sync::atomic::{self, Ordering}; 14 | use sys::stack_overflow; 15 | use sys::thread as imp; 16 | 17 | #[allow(dead_code)] 18 | pub unsafe fn start_thread(main: *mut u8) { 19 | // Next, set up our stack overflow handler which may get triggered if we run 20 | // out of stack. 21 | let _handler = stack_overflow::Handler::new(); 22 | 23 | // Finally, let's run some code. 24 | Box::from_raw(main as *mut Box)() 25 | } 26 | 27 | pub fn min_stack() -> usize { 28 | static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); 29 | match MIN.load(Ordering::SeqCst) { 30 | 0 => {} 31 | n => return n - 1, 32 | } 33 | let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok()); 34 | let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE); 35 | 36 | // 0 is our sentinel value, so ensure that we'll never see 0 after 37 | // initialization has run 38 | MIN.store(amt + 1, Ordering::SeqCst); 39 | amt 40 | } 41 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/thread_info.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | #![allow(dead_code)] // stack_guard isn't used right now on all platforms 12 | 13 | use cell::RefCell; 14 | use thread::Thread; 15 | 16 | struct ThreadInfo { 17 | stack_guard: Option, 18 | thread: Thread, 19 | } 20 | 21 | thread_local! { static THREAD_INFO: RefCell> = RefCell::new(None) } 22 | 23 | impl ThreadInfo { 24 | fn with(f: F) -> Option where F: FnOnce(&mut ThreadInfo) -> R { 25 | THREAD_INFO.try_with(move |c| { 26 | if c.borrow().is_none() { 27 | *c.borrow_mut() = Some(ThreadInfo { 28 | stack_guard: None, 29 | thread: Thread::new(None), 30 | }) 31 | } 32 | f(c.borrow_mut().as_mut().unwrap()) 33 | }).ok() 34 | } 35 | } 36 | 37 | pub fn current_thread() -> Option { 38 | ThreadInfo::with(|info| info.thread.clone()) 39 | } 40 | 41 | pub fn stack_guard() -> Option { 42 | ThreadInfo::with(|info| info.stack_guard).and_then(|o| o) 43 | } 44 | 45 | pub fn set(stack_guard: Option, thread: Thread) { 46 | THREAD_INFO.with(|c| assert!(c.borrow().is_none())); 47 | THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ 48 | stack_guard, 49 | thread, 50 | })); 51 | } 52 | -------------------------------------------------------------------------------- /ctr-std/src/sys_common/util.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | use fmt; 12 | use io::prelude::*; 13 | use sys::stdio::{Stderr, stderr_prints_nothing}; 14 | use thread; 15 | 16 | pub fn dumb_print(args: fmt::Arguments) { 17 | if stderr_prints_nothing() { 18 | return 19 | } 20 | let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args)); 21 | } 22 | 23 | // Other platforms should use the appropriate platform-specific mechanism for 24 | // aborting the process. If no platform-specific mechanism is available, 25 | // ::intrinsics::abort() may be used instead. The above implementations cover 26 | // all targets currently supported by libstd. 27 | 28 | pub fn abort(args: fmt::Arguments) -> ! { 29 | dumb_print(format_args!("fatal runtime error: {}\n", args)); 30 | unsafe { ::sys::abort_internal(); } 31 | } 32 | 33 | #[allow(dead_code)] // stack overflow detection not enabled on all platforms 34 | pub unsafe fn report_overflow() { 35 | dumb_print(format_args!("\nthread '{}' has overflowed its stack\n", 36 | thread::current().name().unwrap_or(""))); 37 | } 38 | -------------------------------------------------------------------------------- /ctr-std/src/tests/env.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Rust Project Developers. See the COPYRIGHT 2 | // file at the top-level directory of this distribution and at 3 | // http://rust-lang.org/COPYRIGHT. 4 | // 5 | // Licensed under the Apache License, Version 2.0 or the MIT license 7 | // , at your 8 | // option. This file may not be copied, modified, or distributed 9 | // except according to those terms. 10 | 11 | extern crate rand; 12 | 13 | use std::env::*; 14 | use std::ffi::{OsString, OsStr}; 15 | 16 | use rand::Rng; 17 | 18 | fn make_rand_name() -> OsString { 19 | let mut rng = rand::thread_rng(); 20 | let n = format!("TEST{}", rng.gen_ascii_chars().take(10) 21 | .collect::()); 22 | let n = OsString::from(n); 23 | assert!(var_os(&n).is_none()); 24 | n 25 | } 26 | 27 | fn eq(a: Option, b: Option<&str>) { 28 | assert_eq!(a.as_ref().map(|s| &**s), b.map(OsStr::new).map(|s| &*s)); 29 | } 30 | 31 | #[test] 32 | fn test_set_var() { 33 | let n = make_rand_name(); 34 | set_var(&n, "VALUE"); 35 | eq(var_os(&n), Some("VALUE")); 36 | } 37 | 38 | #[test] 39 | fn test_remove_var() { 40 | let n = make_rand_name(); 41 | set_var(&n, "VALUE"); 42 | remove_var(&n); 43 | eq(var_os(&n), None); 44 | } 45 | 46 | #[test] 47 | fn test_set_var_overwrite() { 48 | let n = make_rand_name(); 49 | set_var(&n, "1"); 50 | set_var(&n, "2"); 51 | eq(var_os(&n), Some("2")); 52 | set_var(&n, ""); 53 | eq(var_os(&n), Some("")); 54 | } 55 | 56 | #[test] 57 | #[cfg_attr(target_os = "emscripten", ignore)] 58 | fn test_var_big() { 59 | let mut s = "".to_string(); 60 | let mut i = 0; 61 | while i < 100 { 62 | s.push_str("aaaaaaaaaa"); 63 | i += 1; 64 | } 65 | let n = make_rand_name(); 66 | set_var(&n, &s); 67 | eq(var_os(&n), Some(&s)); 68 | } 69 | 70 | #[test] 71 | #[cfg_attr(target_os = "emscripten", ignore)] 72 | fn test_env_set_get_huge() { 73 | let n = make_rand_name(); 74 | let s = "x".repeat(10000); 75 | set_var(&n, &s); 76 | eq(var_os(&n), Some(&s)); 77 | remove_var(&n); 78 | eq(var_os(&n), None); 79 | } 80 | 81 | #[test] 82 | fn test_env_set_var() { 83 | let n = make_rand_name(); 84 | 85 | let mut e = vars_os(); 86 | set_var(&n, "VALUE"); 87 | assert!(!e.any(|(k, v)| { 88 | &*k == &*n && &*v == "VALUE" 89 | })); 90 | 91 | assert!(vars_os().any(|(k, v)| { 92 | &*k == &*n && &*v == "VALUE" 93 | })); 94 | } 95 | -------------------------------------------------------------------------------- /ctru-rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Ronald Kinard "] 3 | description = "A safe wrapper around smealum's ctrulib." 4 | license = "https://en.wikipedia.org/wiki/Zlib_License" 5 | name = "ctru-rs" 6 | version = "0.7.1" 7 | 8 | [lib] 9 | crate-type = ["rlib"] 10 | name = "ctru" 11 | 12 | [dependencies.ctru-sys] 13 | path = "../ctru-sys" 14 | version = "0.4" 15 | 16 | [dependencies.libc] 17 | version = "0.2" 18 | 19 | [dependencies.bitflags] 20 | version = "1.0.0" 21 | 22 | [dependencies.widestring] 23 | version = "0.2.2" 24 | -------------------------------------------------------------------------------- /ctru-rs/README.md: -------------------------------------------------------------------------------- 1 | # ctru-rs 2 | 3 | A Rust wrapper library for smealum's 4 | [ctrulib](https://github.com/smealum/ctrulib). 5 | 6 | See the [3DS project template](https://github.com/rust3ds/rust3ds-template) for instructions on how to use this library. 7 | 8 | ## Structure 9 | 10 | This library is meant to expose 3DS-specific functionality. Common functionality is implemented in `ctr-std` when possible. 11 | 12 | ## Contributing 13 | 14 | PR's are welcome. Organization of rust specific features and wrapper functionality are still being decided on. 15 | 16 | ## License 17 | 18 | Copyright (C) Rust 3DS Project authors, 2015-2016 19 | 20 | See AUTHORS.md. 21 | 22 | As with the original ctrulib, this library is licensed under zlib. This 23 | applies to every file in the tree, unless otherwise noted. 24 | 25 | This software is provided 'as-is', without any express or implied 26 | warranty. In no event will the authors be held liable for any 27 | damages arising from the use of this software. 28 | 29 | Permission is granted to anyone to use this software for any 30 | purpose, including commercial applications, and to alter it and 31 | redistribute it freely, subject to the following restrictions: 32 | 33 | 1. The origin of this software must not be misrepresented; you 34 | must not claim that you wrote the original software. If you use 35 | this software in a product, an acknowledgment in the product 36 | documentation would be appreciated but is not required. 37 | 2. Altered source versions must be plainly marked as such, and 38 | must not be misrepresented as being the original software. 39 | 3. This notice may not be removed or altered from any source 40 | distribution. 41 | 42 | Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses. 43 | 44 | See [LICENSE-APACHE](https://github.com/rust-lang/rust/blob/master/LICENSE-APACHE), [LICENSE-MIT](https://github.com/rust-lang/rust/blob/master/LICENSE-MIT), and [COPYRIGHT](https://github.com/rust-lang/rust/blob/master/COPYRIGHT) for details. 45 | -------------------------------------------------------------------------------- /ctru-rs/src/applets/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod swkbd; 2 | -------------------------------------------------------------------------------- /ctru-rs/src/console.rs: -------------------------------------------------------------------------------- 1 | use std::default::Default; 2 | use std::mem; 3 | 4 | use libctru::{PrintConsole, consoleInit, consoleSelect, consoleClear, consoleSetWindow}; 5 | 6 | use gfx::Screen; 7 | 8 | pub struct Console { 9 | context: Box, 10 | } 11 | 12 | impl Console { 13 | /// Initialize a console on the chosen screen, overwriting whatever was on the screen 14 | /// previously (including other consoles). The new console is automatically selected for 15 | /// printing. 16 | pub fn init(screen: Screen) -> Self { 17 | unsafe { 18 | let mut context = Box::new(mem::uninitialized::()); 19 | consoleInit(screen.into(), context.as_mut()); 20 | Console { context, } 21 | } 22 | } 23 | 24 | /// Select this console as the current target for stdout 25 | pub fn select(&self) { 26 | unsafe { consoleSelect(self.context.as_ref() as *const _ as *mut _); } 27 | } 28 | 29 | /// Clears all text from the console 30 | pub fn clear(&self) { 31 | unsafe { consoleClear() } 32 | } 33 | 34 | /// Resizes the active console to fit in a smaller portion of the screen. 35 | /// 36 | /// The first two arguments are the desired coordinates of the top-left corner 37 | /// of the console, and the second pair is the new width and height 38 | /// 39 | /// This function is unsafe because it does not validate that the input will produce 40 | /// a console that actually fits on the screen 41 | pub unsafe fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { 42 | consoleSetWindow(self.context.as_mut(), x, y, width, height); 43 | } 44 | } 45 | 46 | impl Default for Console { 47 | fn default() -> Self { 48 | Console::init(Screen::Top) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ctru-rs/src/error.rs: -------------------------------------------------------------------------------- 1 | use std::error; 2 | use std::fmt; 3 | 4 | pub type Result = ::std::result::Result; 5 | 6 | /// The error type returned by all libctru functions. 7 | pub enum Error { 8 | Os(i32), 9 | } 10 | 11 | impl From for Error { 12 | fn from(err: i32) -> Self { 13 | Error::Os(err) 14 | } 15 | } 16 | 17 | impl fmt::Debug for Error { 18 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 19 | match *self { 20 | Error::Os(err) => write!(f, "libctru result code: {:08X}", err), 21 | } 22 | } 23 | } 24 | 25 | // TODO: Expand libctru result code into human-readable error message 26 | impl fmt::Display for Error { 27 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 28 | match *self { 29 | Error::Os(err) => write!(f, "libctru result code: 0x{:08X}", err), 30 | } 31 | } 32 | } 33 | 34 | impl error::Error for Error { 35 | fn description(&self) -> &str { 36 | "error originating from a libctru function" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ctru-rs/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![crate_type = "rlib"] 2 | #![crate_name = "ctru"] 3 | 4 | #![feature(fnbox)] 5 | 6 | #[macro_use] 7 | extern crate bitflags; 8 | extern crate libc; 9 | extern crate widestring; 10 | 11 | extern crate ctru_sys as libctru; 12 | 13 | pub mod applets; 14 | pub mod console; 15 | pub mod error; 16 | pub mod srv; 17 | pub mod gfx; 18 | pub mod services; 19 | pub mod sdmc; 20 | pub mod thread; 21 | 22 | pub use error::{Result, Error}; 23 | 24 | pub use srv::Srv; 25 | pub use gfx::Gfx; 26 | pub use sdmc::Sdmc; 27 | -------------------------------------------------------------------------------- /ctru-rs/src/sdmc.rs: -------------------------------------------------------------------------------- 1 | pub struct Sdmc(()); 2 | 3 | impl Sdmc { 4 | pub fn init() -> ::Result { 5 | unsafe { 6 | let r = ::libctru::sdmcInit(); 7 | if r < 0 { 8 | Err(r.into()) 9 | } else { 10 | Ok(Sdmc(())) 11 | } 12 | } 13 | } 14 | } 15 | 16 | impl Drop for Sdmc { 17 | fn drop(&mut self) { 18 | unsafe { ::libctru::sdmcExit() }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ctru-rs/src/services/apt.rs: -------------------------------------------------------------------------------- 1 | pub struct Apt(()); 2 | 3 | impl Apt { 4 | pub fn init() -> ::Result { 5 | unsafe { 6 | let r = ::libctru::aptInit(); 7 | if r < 0 { 8 | Err(r.into()) 9 | } else { 10 | Ok(Apt(())) 11 | } 12 | } 13 | } 14 | 15 | pub fn main_loop(&self) -> bool { 16 | unsafe { 17 | ::libctru::aptMainLoop() 18 | } 19 | } 20 | 21 | pub fn set_app_cpu_time_limit(&self, percent: u32) -> ::Result<()> { 22 | unsafe { 23 | let r = ::libctru::APT_SetAppCpuTimeLimit(percent); 24 | if r < 0 { 25 | Err(r.into()) 26 | } else { 27 | Ok(()) 28 | } 29 | } 30 | } 31 | } 32 | 33 | impl Drop for Apt { 34 | fn drop(&mut self) { 35 | unsafe { ::libctru::aptExit() }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ctru-rs/src/services/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod apt; 2 | pub mod fs; 3 | pub mod hid; 4 | pub mod gspgpu; 5 | pub mod soc; 6 | pub mod sslc; 7 | 8 | pub use self::hid::Hid; 9 | pub use self::apt::Apt; 10 | pub use self::sslc::SslC; 11 | -------------------------------------------------------------------------------- /ctru-rs/src/services/soc.rs: -------------------------------------------------------------------------------- 1 | use libctru::{socInit, socExit}; 2 | 3 | use libc::{memalign, free}; 4 | 5 | /// Soc service. Initializing this service will enable the use of network sockets and utilities 6 | /// such as those found in `std::net`. The service will be closed when this struct is is dropped. 7 | pub struct Soc { 8 | soc_mem: *mut u32, 9 | } 10 | 11 | impl Soc { 12 | /// Initialize the Soc service with a default buffer size of 0x100000 bytes 13 | /// 14 | /// # Errors 15 | /// 16 | /// This function will return an error if the `Soc` service is already initialized 17 | pub fn init() -> ::Result { 18 | Soc::init_with_buffer_size(0x100000) 19 | } 20 | 21 | /// Initialize the Soc service with a custom buffer size in bytes. The size should be 22 | /// 0x100000 bytes or greater. 23 | /// 24 | /// # Errors 25 | /// 26 | /// This function will return an error if the `Soc` service is already initialized 27 | pub fn init_with_buffer_size(num_bytes: usize) -> ::Result { 28 | unsafe { 29 | let soc_mem = memalign(0x1000, num_bytes) as *mut u32; 30 | 31 | let r = socInit(soc_mem, num_bytes as u32); 32 | if r < 0 { 33 | free(soc_mem as *mut _); 34 | Err(r.into()) 35 | } else { 36 | Ok(Soc { soc_mem, }) 37 | } 38 | } 39 | } 40 | } 41 | 42 | impl Drop for Soc { 43 | fn drop(&mut self) { 44 | unsafe { 45 | socExit(); 46 | free(self.soc_mem as *mut _); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ctru-rs/src/services/sslc.rs: -------------------------------------------------------------------------------- 1 | // TODO: Implement remaining functions 2 | 3 | pub struct SslC(()); 4 | 5 | impl SslC { 6 | /// Initialize sslc 7 | pub fn init() -> ::Result { 8 | unsafe { 9 | let r = ::libctru::sslcInit(0); 10 | if r < 0 { 11 | Err(r.into()) 12 | } else { 13 | Ok(SslC(())) 14 | } 15 | } 16 | } 17 | 18 | /// Fill `buf` with `buf.len()` random bytes 19 | pub fn generate_random_data(&self, buf: &mut [u8]) -> ::Result<()> { 20 | unsafe { 21 | let r = ::libctru::sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32); 22 | if r < 0 { 23 | Err(r.into()) 24 | } else { 25 | Ok(()) 26 | } 27 | } 28 | } 29 | } 30 | 31 | impl Drop for SslC { 32 | fn drop(&mut self) { 33 | unsafe { ::libctru::sslcExit() }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ctru-rs/src/srv.rs: -------------------------------------------------------------------------------- 1 | pub struct Srv(()); 2 | 3 | impl Srv { 4 | pub fn init() -> ::Result { 5 | unsafe { 6 | let r = ::libctru::srvInit(); 7 | if r < 0 { 8 | Err(r.into()) 9 | } else { 10 | Ok(Srv(())) 11 | } 12 | } 13 | } 14 | } 15 | 16 | impl Drop for Srv { 17 | fn drop(&mut self) { 18 | unsafe { ::libctru::srvExit() }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ctru-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ctru-sys" 3 | version = "0.4.0" 4 | authors = ["Ronald Kinard "] 5 | license = "https://en.wikipedia.org/wiki/Zlib_License" 6 | 7 | [dependencies.libc] 8 | version = "0.2" 9 | default-features = false 10 | optional = true 11 | 12 | [features] 13 | default = ["libc"] 14 | 15 | # This is a dummy feature that only exists to work around a Xargo issue. 16 | # User code should not enable it. 17 | stdbuild = [] 18 | -------------------------------------------------------------------------------- /ctru-sys/bindgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | clang_version=$1 4 | 5 | if [ -z "$clang_version" ]; then 6 | echo " usage: ./bindgen.sh " 7 | echo "example: ./bindgen.sh 5.0.0" 8 | echo "Check your current version with \`clang -v\`." 9 | exit 1 10 | fi 11 | 12 | set -euxo pipefail 13 | 14 | bindgen "$DEVKITPRO/libctru/include/3ds.h" \ 15 | --rust-target nightly \ 16 | --use-core \ 17 | --distrust-clang-mangling \ 18 | --no-doc-comments \ 19 | --no-layout-tests \ 20 | --ctypes-prefix "::libc" \ 21 | --no-prepend-enum-name \ 22 | --generate "functions,types,vars" \ 23 | --blacklist-type "u(8|16|32|64)" \ 24 | --blacklist-type "__builtin_va_list" \ 25 | --blacklist-type "__va_list" \ 26 | -- \ 27 | --target=arm-none-eabi \ 28 | --sysroot=$DEVKITARM/arm-none-eabi \ 29 | -isystem$DEVKITARM/arm-none-eabi/include \ 30 | -isystem/usr/lib/clang/$clang_version/include \ 31 | -I$DEVKITPRO/libctru/include \ 32 | -mfloat-abi=hard \ 33 | -march=armv6k \ 34 | -mtune=mpcore \ 35 | -mfpu=vfp \ 36 | -DARM11 \ 37 | -D_3DS \ 38 | > src/bindings.rs 39 | -------------------------------------------------------------------------------- /ctru-sys/build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | fn main() { 4 | let dkp_path = env::var("DEVKITPRO").unwrap(); 5 | 6 | println!("cargo:rustc-link-search=native={}/libctru/lib", dkp_path); 7 | println!("cargo:rustc-link-lib=static={}", match env::var("PROFILE").unwrap().as_str() { 8 | "debug" => "ctrud", 9 | _ => "ctru", 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /ctru-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_camel_case_types)] 3 | #![allow(non_snake_case)] 4 | 5 | #![feature(const_fn)] 6 | 7 | #![no_std] 8 | 9 | #![cfg_attr(feature = "stdbuild", feature(libc))] 10 | 11 | extern crate libc; 12 | 13 | include!("bindings.rs"); 14 | -------------------------------------------------------------------------------- /examples/.cargo/config: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "3ds" 3 | 4 | [target.3ds] 5 | linker = "arm-none-eabi-gcc" 6 | rustflags = [ 7 | "-Clink-arg=-specs=3dsx.specs", 8 | "-Clink-arg=-mfloat-abi=hard", 9 | "-Clink-arg=-march=armv6k", 10 | "-Clink-arg=-mtune=mpcore", 11 | "-Clink-arg=-mfpu=vfp", 12 | "-Clink-arg=-mtp=soft", 13 | "-Clink-arg=-z", 14 | "-Clink-arg=muldefs", 15 | "-Clink-arg=-lgcc", 16 | "-Clink-arg=-lsysbase", 17 | "-Clink-arg=-lc" 18 | ] 19 | -------------------------------------------------------------------------------- /examples/3ds.json: -------------------------------------------------------------------------------- 1 | { 2 | "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", 3 | "llvm-target": "arm-none-eabihf", 4 | "linker": "arm-none-eabi-gcc", 5 | "ar": "arm-none-eabi-ar", 6 | "target-endian": "little", 7 | "target-pointer-width": "32", 8 | "target-c-int-width": "32", 9 | "target-family": "unix", 10 | "arch": "arm", 11 | "os": "horizon", 12 | "env": "newlib", 13 | "cpu": "mpcore", 14 | "features": "+vfp2", 15 | "relocation-model": "static", 16 | "executables": true, 17 | "exe-suffix": ".elf", 18 | "linker-flavor": "gcc" 19 | } 20 | -------------------------------------------------------------------------------- /examples/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "examples" 3 | version = "0.1.0" 4 | 5 | [dependencies] 6 | ctru-rs = { path = "../ctru-rs" } 7 | 8 | [profile.dev] 9 | 10 | [profile.release] 11 | lto = true 12 | -------------------------------------------------------------------------------- /examples/Xargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies.alloc] 2 | [dependencies.panic_abort] 3 | [dependencies.panic_unwind] 4 | 5 | [dependencies.std] 6 | path = "../ctr-std" 7 | stage = 1 8 | -------------------------------------------------------------------------------- /examples/src/bin/buttons.rs: -------------------------------------------------------------------------------- 1 | extern crate ctru; 2 | 3 | use ctru::gfx::Gfx; 4 | use ctru::console::Console; 5 | use ctru::services::apt::Apt; 6 | use ctru::services::hid::{Hid, KeyPad}; 7 | 8 | fn main() { 9 | // Setup services 10 | let apt = Apt::init().unwrap(); 11 | let hid = Hid::init().unwrap(); 12 | let gfx = Gfx::default(); 13 | let console = Console::default(); 14 | 15 | println!("Hi there! Try pressing a button"); 16 | println!("\x1b[29;16HPress Start to exit"); 17 | 18 | // This struct will contain the keys that we held on the previous frame 19 | let mut old_keys = KeyPad::empty(); 20 | 21 | while apt.main_loop() { 22 | // Scan for user input on the current frame. 23 | hid.scan_input(); 24 | 25 | // Get information about which keys were held down on this frame 26 | let keys = hid.keys_held(); 27 | 28 | // We only want to print when the keys we're holding now are different 29 | // from what they were on the previous frame 30 | if keys != old_keys { 31 | 32 | // Clear the screen 33 | console.clear(); 34 | 35 | // We print these again because we just cleared the screen above 36 | println!("Hi there! Try pressing a button"); 37 | println!("\x1b[29;16HPress Start to exit"); 38 | 39 | // Move the cursor back to the top of the screen 40 | println!("\x1b[3;0H"); 41 | 42 | // Print to the screen depending on which keys were held. 43 | // 44 | // The .contains() method checks for all of the provided keys, 45 | // and the .intersects() method checks for any of the provided keys. 46 | // 47 | // You can also use the .bits() method to do direct comparisons on 48 | // the underlying bits 49 | 50 | if keys.contains(KeyPad::KEY_A) { 51 | println!("You held A!"); 52 | } 53 | if keys.bits() & KeyPad::KEY_B.bits() != 0 { 54 | println!("You held B!"); 55 | } 56 | if keys.contains(KeyPad::KEY_X | KeyPad::KEY_Y) { 57 | println!("You held X and Y!"); 58 | } 59 | if keys.intersects(KeyPad::KEY_L | KeyPad::KEY_R | KeyPad::KEY_ZL | KeyPad::KEY_ZR) { 60 | println!("You held a shoulder button!"); 61 | } 62 | if keys.intersects(KeyPad::KEY_START) { 63 | println!("See ya!"); 64 | break 65 | } 66 | } 67 | 68 | // Save our current key presses for the next frame 69 | old_keys = keys; 70 | 71 | // Flush and swap framebuffers 72 | gfx.flush_buffers(); 73 | gfx.swap_buffers(); 74 | gfx.wait_for_vblank(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/src/bin/hello-both-screens.rs: -------------------------------------------------------------------------------- 1 | extern crate ctru; 2 | 3 | use ctru::gfx::{Gfx, Screen}; 4 | use ctru::console::Console; 5 | use ctru::services::apt::Apt; 6 | use ctru::services::hid::{Hid, KeyPad}; 7 | 8 | fn main() { 9 | // Initialize services 10 | let apt = Apt::init().unwrap(); 11 | let hid = Hid::init().unwrap(); 12 | let gfx = Gfx::default(); 13 | 14 | // Start a console on the top screen 15 | let top_screen = Console::init(Screen::Top); 16 | 17 | // Start a console on the bottom screen. 18 | // The most recently initialized console will be active by default 19 | let bottom_screen = Console::init(Screen::Bottom); 20 | 21 | // Let's print on the top screen first 22 | top_screen.select(); 23 | println!("This is the top screen! We have a lot of space up here!"); 24 | 25 | // Now let's print something on the bottom screen 26 | bottom_screen.select(); 27 | println!("\x1b[14;00HThis is the bottom screen."); 28 | println!("There's not as much space down here, but that's okay."); 29 | 30 | top_screen.select(); 31 | println!("\x1b[29;16HPress Start to exit"); 32 | 33 | while apt.main_loop() { 34 | gfx.flush_buffers(); 35 | gfx.swap_buffers(); 36 | gfx.wait_for_vblank(); 37 | 38 | hid.scan_input(); 39 | if hid.keys_down().contains(KeyPad::KEY_START) { 40 | break; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/src/bin/hello-world.rs: -------------------------------------------------------------------------------- 1 | extern crate ctru; 2 | 3 | use ctru::gfx::Gfx; 4 | use ctru::console::Console; 5 | use ctru::services::apt::Apt; 6 | use ctru::services::hid::{Hid, KeyPad}; 7 | 8 | fn main() { 9 | // Initialize ctrulib service handles. 10 | // Service handles are internally reference-counted. When all instances of a 11 | // service handle go out of scope, the service will be closed. 12 | 13 | // The APT service handles application management functions, such as enabling sleep 14 | // mode and jumping to the home menu or to other applications 15 | let apt = Apt::init().unwrap(); 16 | 17 | // The HID service handles button and touch screen inputs. 18 | let hid = Hid::init().unwrap(); 19 | 20 | // The GFX service manages the framebuffers for the top and bottom screens. 21 | let gfx = Gfx::default(); 22 | 23 | // Initialize a ctrulib console and direct standard output to it. 24 | // Consoles can be initialized on both the top and bottom screens. 25 | // The top screen is initialized by default. 26 | let _console = Console::default(); 27 | 28 | // Now we can print to stdout! 29 | println!("Hello, world!"); 30 | 31 | // We can use escape sequences to move the cursor around the terminal. 32 | // The following text will be moved down 29 rows and right 16 characters 33 | // before printing begins. 34 | println!("\x1b[29;16HPress Start to exit"); 35 | 36 | // Main application loop. 37 | while apt.main_loop() { 38 | 39 | // Flushes and swaps the framebuffers when double-buffering 40 | // is enabled 41 | gfx.flush_buffers(); 42 | gfx.swap_buffers(); 43 | 44 | // Wait for the next frame to begin 45 | gfx.wait_for_vblank(); 46 | 47 | // Scan for user input. 48 | hid.scan_input(); 49 | 50 | // Check if the user has pressed the given button on this frame. 51 | // If so, break out of the loop. 52 | if hid.keys_down().contains(KeyPad::KEY_START) { 53 | break; 54 | } 55 | } 56 | 57 | // All of our service handles will drop out of scope at this point, 58 | // triggering the end of our application. 59 | } 60 | -------------------------------------------------------------------------------- /examples/src/bin/software-keyboard.rs: -------------------------------------------------------------------------------- 1 | extern crate ctru; 2 | 3 | use ctru::gfx::Gfx; 4 | use ctru::console::Console; 5 | use ctru::services::apt::Apt; 6 | use ctru::services::hid::{Hid, KeyPad}; 7 | use ctru::applets::swkbd::{Swkbd, Button}; 8 | 9 | fn main() { 10 | let apt = Apt::init().unwrap(); 11 | let hid = Hid::init().unwrap(); 12 | let gfx = Gfx::default(); 13 | let _console = Console::default(); 14 | 15 | println!("Press A to enter some text or press Start to quit"); 16 | 17 | while apt.main_loop() { 18 | gfx.flush_buffers(); 19 | gfx.swap_buffers(); 20 | gfx.wait_for_vblank(); 21 | 22 | hid.scan_input(); 23 | 24 | if hid.keys_down().contains(KeyPad::KEY_A) { 25 | // Prepares a software keyboard with two buttons: One to cancel input and one 26 | // to accept it. You can also use `Swkbd::init()` to launch the keyboard in different 27 | // configurations. 28 | let mut keyboard = Swkbd::default(); 29 | 30 | // String used to store text received from the keyboard 31 | let mut text = String::new(); 32 | 33 | // Raise the software keyboard. You can perform different actions depending on which 34 | // software button the user pressed 35 | match keyboard.get_utf8(&mut text) { 36 | Ok(Button::Right) => println!("You entered: {}", text), 37 | Ok(Button::Left) => println!("Cancelled"), 38 | Ok(Button::Middle) => println!("How did you even press this?"), 39 | Err(_) => println!("Oh noes, an error happened!"), 40 | } 41 | } 42 | 43 | if hid.keys_down().contains(KeyPad::KEY_START) { 44 | break; 45 | } 46 | } 47 | } 48 | --------------------------------------------------------------------------------