├── make_lrs.sh ├── tests ├── gdb.conf ├── hash │ ├── testfile │ └── mod.rs ├── box │ └── mod.rs ├── clone │ └── mod.rs ├── dev │ └── mod.rs ├── dir │ └── mod.rs ├── env │ └── mod.rs ├── event │ └── mod.rs ├── fd │ └── mod.rs ├── file │ └── mod.rs ├── fs │ └── mod.rs ├── int │ └── mod.rs ├── iter │ └── mod.rs ├── kernel │ └── mod.rs ├── libc │ └── mod.rs ├── lock │ └── mod.rs ├── mem │ └── mod.rs ├── mqueue │ └── mod.rs ├── queue │ └── mod.rs ├── rc │ └── mod.rs ├── rmo │ └── mod.rs ├── rt │ └── mod.rs ├── rv │ └── mod.rs ├── socket │ └── mod.rs ├── swap │ └── mod.rs ├── sys │ └── mod.rs ├── thread │ └── mod.rs ├── tty │ └── mod.rs ├── arch_fns │ └── mod.rs ├── buf_reader │ └── mod.rs ├── c_ptr_ptr │ └── mod.rs ├── cty_base │ └── mod.rs ├── hashmap │ └── mod.rs ├── inotify │ └── mod.rs ├── netlink │ └── mod.rs ├── process │ └── mod.rs ├── r_syscall │ └── mod.rs ├── ringbuf │ └── mod.rs ├── str_three │ └── mod.rs ├── str_two │ └── mod.rs ├── time_base │ └── mod.rs ├── time_ext │ └── mod.rs ├── user_group │ └── mod.rs ├── str_one │ ├── no_null_str.rs │ ├── mod.rs │ ├── byte_str.rs │ └── c_str.rs ├── cell │ ├── mod.rs │ ├── cell.rs │ └── ref_cell.rs ├── poll │ └── mod.rs ├── alloc │ ├── mod.rs │ ├── no.rs │ ├── align.rs │ └── ta.rs ├── Makefile ├── fmt │ ├── mod.rs │ ├── tuple.rs │ ├── boolean.rs │ ├── option.rs │ ├── result.rs │ ├── str.rs │ └── num.rs ├── base │ ├── mod.rs │ ├── default.rs │ ├── result.rs │ ├── into.rs │ └── rmo.rs ├── core │ ├── mod.rs │ ├── array.rs │ ├── repr.rs │ ├── bool.rs │ ├── tuple.rs │ ├── cmp.rs │ ├── char.rs │ └── option.rs ├── cty │ └── mod.rs ├── signal │ ├── sigset.rs │ └── mod.rs ├── lib.rs └── getopt │ └── mod.rs ├── make_asm.sh ├── etc └── aarch64-lkern-kernel.json ├── assets ├── logo.png └── doc_style.css ├── obj ├── i686-unknown-linux-gnu │ ├── liblrs_asm.a │ └── liblrs_crt.a ├── x86_64-unknown-linux-gnu │ ├── liblrs_asm.a │ └── liblrs_crt.a ├── aarch64-unknown-linux-gnu │ ├── liblrs_asm.a │ └── liblrs_crt.a └── arm-unknown-linux-gnueabi │ ├── liblrs_asm.a │ └── liblrs_crt.a ├── .gitignore ├── asm ├── aarch64-unknown-linux-gnu │ └── src │ │ ├── restore.s │ │ ├── start.s │ │ ├── stop_thread.s │ │ └── start_thread.s ├── x86_64-unknown-linux-gnu │ └── src │ │ ├── restore.s │ │ ├── start.s │ │ ├── stop_thread.s │ │ └── start_thread.s ├── armv6-unknown-linux-gnueabi │ └── src │ │ ├── restore.s │ │ ├── start.s │ │ ├── stop_thread.s │ │ └── start_thread.s ├── i686-unknown-linux-gnu │ └── src │ │ ├── restore.s │ │ ├── start.s │ │ ├── stop_thread.s │ │ └── start_thread.s └── Makefile ├── make_docs.sh ├── make_libtest.sh ├── src ├── lrs │ ├── cty.rs │ ├── bool.rs │ ├── undef.rs │ ├── varargs.rs │ ├── tree.rs │ ├── ringbuf.rs │ ├── vec.rs │ ├── rmo.rs │ ├── result.rs │ ├── rc.rs │ ├── hashmap.rs │ ├── getopt.rs │ ├── option.rs │ ├── util.rs │ ├── slice.rs │ ├── stdio.rs │ ├── fmt.rs │ ├── io.rs │ ├── repr.rs │ ├── marker.rs │ ├── dir.rs │ ├── string.rs │ ├── iter.rs │ ├── rand.rs │ ├── msg_queue.rs │ ├── user.rs │ ├── num.rs │ ├── env.rs │ ├── swap.rs │ ├── event.rs │ ├── parse.rs │ ├── poll.rs │ ├── bx.rs │ ├── group.rs │ ├── sync.rs │ ├── cmp.rs │ ├── conv.rs │ ├── cfg.rs │ ├── hash.rs │ ├── ptr.rs │ ├── pipe.rs │ ├── ops.rs │ ├── intrinsics.rs │ ├── share.rs │ ├── fd.rs │ ├── mem_map.rs │ ├── sys.rs │ ├── inotify.rs │ ├── mem.rs │ ├── process.rs │ ├── tty.rs │ └── atomic.rs ├── parse │ └── impls │ │ └── float.rs ├── rt │ ├── no_libc │ │ ├── mod.rs │ │ ├── tls │ │ │ ├── x86_64.rs │ │ │ ├── aarch64.rs │ │ │ └── arm.rs │ │ └── crt.rs │ ├── libc │ │ └── mod.rs │ └── aux.rs ├── arch_fns │ └── libc.rs ├── libc │ ├── arm.rs │ ├── x86.rs │ ├── x86_64.rs │ ├── aarch64.rs │ └── x32.rs ├── fmt │ └── impls │ │ ├── unit.rs │ │ ├── tuple.rs │ │ ├── errno.rs │ │ ├── boolean.rs │ │ ├── option.rs │ │ ├── result.rs │ │ ├── float.rs │ │ └── range.rs ├── r_syscall │ └── x86_64 │ │ ├── x64.rs │ │ └── x32.rs ├── hash │ └── impls │ │ ├── bool.rs │ │ ├── errno.rs │ │ ├── option.rs │ │ ├── result.rs │ │ ├── char.rs │ │ ├── slice.rs │ │ └── ptr.rs ├── base │ ├── conv │ │ ├── into.rs │ │ ├── default.rs │ │ ├── to.rs │ │ └── clone.rs │ └── lib.rs ├── cell │ └── lib.rs ├── rmo │ └── impls │ │ ├── byte_string.rs │ │ ├── no_null_string.rs │ │ └── slice.rs ├── varargs │ ├── x86.rs │ ├── arm.rs │ ├── aarch64.rs │ ├── lib.rs │ └── x86_64.rs ├── cty_base │ ├── lib.rs │ ├── arm.rs │ ├── x86.rs │ ├── aarch64.rs │ └── x86_64.rs ├── slice │ └── lib.rs ├── str_two │ ├── lib.rs │ └── cmp.rs ├── str_one │ ├── lib.rs │ ├── c_str │ │ └── index.rs │ └── no_null_str │ │ └── index.rs ├── rc │ └── lib.rs ├── rand │ ├── getrandom.rs │ ├── impls.rs │ └── devrandom.rs ├── core │ ├── thread_local.rs │ ├── array.rs │ ├── panicking.rs │ ├── non_zero.rs │ ├── repr.rs │ ├── sort.rs │ ├── data.rs │ ├── bool.rs │ └── lib.rs ├── vec │ └── cmp_.rs ├── cfg │ └── lib.rs ├── alloc │ ├── no.rs │ ├── tl.rs │ └── libc.rs ├── clone │ ├── libc │ │ └── mod.rs │ └── no_libc │ │ └── mod.rs ├── tree │ ├── test.rs │ ├── debug.rs │ └── path.rs ├── tlalc │ ├── p.rs │ ├── util.rs │ └── lib.rs ├── thread │ └── no_libc │ │ ├── arm.rs │ │ ├── x86_64.rs │ │ ├── aarch64.rs │ │ └── x86.rs ├── rv │ └── lib.rs ├── core_plugin │ └── lrs_ext │ │ └── mod.rs ├── netlink │ └── kind.rs ├── socket │ └── lib.rs ├── tty │ ├── key.rs │ └── disc.rs ├── hashmap │ └── lib.rs ├── lock │ ├── lib.rs │ └── once.rs └── process │ └── res_user.rs ├── VERSION.adoc ├── Documentation ├── Makefile ├── README.adoc └── adoc │ ├── index.adoc │ └── undefined_operations.adoc ├── make_plugin.sh └── targets.sh /make_lrs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | make 4 | -------------------------------------------------------------------------------- /tests/gdb.conf: -------------------------------------------------------------------------------- 1 | set follow-fork-mode child 2 | -------------------------------------------------------------------------------- /make_asm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd asm 4 | make 5 | -------------------------------------------------------------------------------- /etc/aarch64-lkern-kernel.json: -------------------------------------------------------------------------------- 1 | /home/julian/lkern/aarch64-lkern-kernel.json -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrs-lang/lib/HEAD/assets/logo.png -------------------------------------------------------------------------------- /obj/i686-unknown-linux-gnu/liblrs_asm.a: -------------------------------------------------------------------------------- 1 | ../../asm/i686-unknown-linux-gnu/obj/liblrs_asm.a -------------------------------------------------------------------------------- /obj/i686-unknown-linux-gnu/liblrs_crt.a: -------------------------------------------------------------------------------- 1 | ../../asm/i686-unknown-linux-gnu/obj/liblrs_crt.a -------------------------------------------------------------------------------- /tests/hash/testfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrs-lang/lib/HEAD/tests/hash/testfile -------------------------------------------------------------------------------- /obj/x86_64-unknown-linux-gnu/liblrs_asm.a: -------------------------------------------------------------------------------- 1 | ../../asm/x86_64-unknown-linux-gnu/obj/liblrs_asm.a -------------------------------------------------------------------------------- /obj/x86_64-unknown-linux-gnu/liblrs_crt.a: -------------------------------------------------------------------------------- 1 | ../../asm/x86_64-unknown-linux-gnu/obj/liblrs_crt.a -------------------------------------------------------------------------------- /obj/aarch64-unknown-linux-gnu/liblrs_asm.a: -------------------------------------------------------------------------------- 1 | ../../asm/aarch64-unknown-linux-gnu/obj/liblrs_asm.a -------------------------------------------------------------------------------- /obj/aarch64-unknown-linux-gnu/liblrs_crt.a: -------------------------------------------------------------------------------- 1 | ../../asm/aarch64-unknown-linux-gnu/obj/liblrs_crt.a -------------------------------------------------------------------------------- /obj/arm-unknown-linux-gnueabi/liblrs_asm.a: -------------------------------------------------------------------------------- 1 | ../../asm/armv6-unknown-linux-gnueabi/obj/liblrs_asm.a -------------------------------------------------------------------------------- /obj/arm-unknown-linux-gnueabi/liblrs_crt.a: -------------------------------------------------------------------------------- 1 | ../../asm/armv6-unknown-linux-gnueabi/obj/liblrs_crt.a -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | obj 3 | tests/tests 4 | doc.json 5 | target 6 | dragons 7 | .* 8 | *.d 9 | *.html 10 | !.gitignore 11 | config.mk 12 | -------------------------------------------------------------------------------- /asm/aarch64-unknown-linux-gnu/src/restore.s: -------------------------------------------------------------------------------- 1 | .global lrs_restore 2 | .type lrs_restore,%function 3 | lrs_restore: 4 | mov x8, #139 5 | svc 0 6 | -------------------------------------------------------------------------------- /asm/x86_64-unknown-linux-gnu/src/restore.s: -------------------------------------------------------------------------------- 1 | .global lrs_restore 2 | .type lrs_restore,@function 3 | lrs_restore: 4 | movl $15, %eax 5 | syscall 6 | -------------------------------------------------------------------------------- /asm/armv6-unknown-linux-gnueabi/src/restore.s: -------------------------------------------------------------------------------- 1 | .global lrs_restore 2 | .type lrs_restore,%function 3 | lrs_restore: 4 | mov r7, #173 5 | swi 0x0 6 | -------------------------------------------------------------------------------- /asm/i686-unknown-linux-gnu/src/restore.s: -------------------------------------------------------------------------------- 1 | .global lrs_restore 2 | .type lrs_restore,@function 3 | lrs_restore: 4 | movl $173, %eax 5 | int $0x80 6 | -------------------------------------------------------------------------------- /asm/x86_64-unknown-linux-gnu/src/start.s: -------------------------------------------------------------------------------- 1 | .global _start 2 | .type _start,@function 3 | _start: 4 | xor %rbp,%rbp 5 | mov %rsp,%rdi 6 | call lrs_start_main 7 | -------------------------------------------------------------------------------- /asm/armv6-unknown-linux-gnueabi/src/start.s: -------------------------------------------------------------------------------- 1 | .global _start 2 | .type _start,%function 3 | _start: 4 | mov fp,#0 5 | mov lr,#0 6 | mov a1,sp 7 | bl lrs_start_main 8 | -------------------------------------------------------------------------------- /asm/aarch64-unknown-linux-gnu/src/start.s: -------------------------------------------------------------------------------- 1 | .global _start 2 | .type _start,%function 3 | _start: 4 | mov x29,#0 5 | mov x30,#0 6 | mov x0,sp 7 | bl lrs_start_main 8 | -------------------------------------------------------------------------------- /make_docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | target="$(./targets.sh native)" 6 | 7 | rustdoc -w json -L obj/$target src/lrs/lib.rs 8 | lrs_doc 9 | cp assets/doc_style.css doc/style.css 10 | -------------------------------------------------------------------------------- /tests/box/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/clone/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/dev/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/dir/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/env/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/event/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/fd/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/file/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/fs/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/int/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/iter/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/kernel/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/libc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/lock/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/mem/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/mqueue/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/queue/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/rc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/rmo/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/rt/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/rv/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/socket/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/swap/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/sys/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/thread/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/tty/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/arch_fns/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/buf_reader/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/c_ptr_ptr/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/cty_base/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/hashmap/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/inotify/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/netlink/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/process/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/r_syscall/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/ringbuf/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/str_three/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/str_two/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/time_base/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/time_ext/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /tests/user_group/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -------------------------------------------------------------------------------- /make_libtest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ $# -eq 0 ]]; then 4 | target="$(./targets.sh native)" 5 | else 6 | target="$(./targets.sh trans $1)" 7 | fi 8 | 9 | lrsc --out-dir obj/$target --target $target src/test/lib.rs 10 | -------------------------------------------------------------------------------- /tests/hash/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod xx_hash; 6 | -------------------------------------------------------------------------------- /src/lrs/cty.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_cty::*; 6 | -------------------------------------------------------------------------------- /src/parse/impls/float.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | // todo 6 | -------------------------------------------------------------------------------- /tests/str_one/no_null_str.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | // TODO 6 | -------------------------------------------------------------------------------- /tests/cell/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod cell; 6 | mod ref_cell; 7 | -------------------------------------------------------------------------------- /src/lrs/bool.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_core::bool::{BoolExt}; 6 | -------------------------------------------------------------------------------- /tests/poll/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn test() { 7 | } 8 | -------------------------------------------------------------------------------- /VERSION.adoc: -------------------------------------------------------------------------------- 1 | :VERSION: abf60b20a 2 | :DATE: 2015-12-20 3 | :X86_64_NIGHTLY: http://static.rust-lang.org/dist/2015-12-20/rust-nightly-x86_64-unknown-linux-gnu.tar.gz 4 | :I686_NIGHTLY: http://static.rust-lang.org/dist/2015-12-20/rust-nightly-i686-unknown-linux-gnu.tar.gz 5 | -------------------------------------------------------------------------------- /src/lrs/undef.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_base::undef::{UndefState}; 6 | -------------------------------------------------------------------------------- /src/rt/no_libc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod tls; 6 | pub mod crt; 7 | -------------------------------------------------------------------------------- /src/lrs/varargs.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_varargs::{VarArgs, VarArg}; 6 | -------------------------------------------------------------------------------- /src/lrs/tree.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_tree::{Tree, Node, Entree, GetNode}; 6 | -------------------------------------------------------------------------------- /src/lrs/ringbuf.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_ringbuf::{DynRingBuf, RingBufIter}; 6 | -------------------------------------------------------------------------------- /src/lrs/vec.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Vector handling. 6 | 7 | pub use lrs_vec::{Vec}; 8 | -------------------------------------------------------------------------------- /tests/alloc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod no; 6 | mod bda; 7 | mod align; 8 | mod ta; 9 | -------------------------------------------------------------------------------- /tests/str_one/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod byte_str; 6 | mod no_null_str; 7 | mod c_str; 8 | -------------------------------------------------------------------------------- /src/lrs/rmo.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Ref/Mut/Owned types. 6 | 7 | pub use lrs_base::rmo::*; 8 | -------------------------------------------------------------------------------- /asm/i686-unknown-linux-gnu/src/start.s: -------------------------------------------------------------------------------- 1 | .global _start 2 | .text 3 | _start: 4 | xor %ebp,%ebp 5 | mov %esp,%eax 6 | and $-16,%esp # GCC ABI requires 16 bytes alignment before the call instruction 7 | push %eax 8 | push %eax 9 | push %eax 10 | push %eax 11 | call lrs_start_main 12 | -------------------------------------------------------------------------------- /src/arch_fns/libc.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use libc::{memchr, memrchr, memcmp, memset, strlen}; 6 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean gdb 2 | 3 | -include config.mk 4 | 5 | all: tests 6 | 7 | -include tests.d 8 | 9 | tests: 10 | lrsc --test --emit=link,dep-info $(RFLAGS) lib.rs 11 | 12 | gdb: tests 13 | gdb -x gdb.conf --args tests $(test) 14 | 15 | clean: 16 | rm -f tests tests.d 17 | -------------------------------------------------------------------------------- /src/lrs/result.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Results of operations. 6 | 7 | pub use lrs_base::result::{Result}; 8 | -------------------------------------------------------------------------------- /src/lrs/rc.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Reference-counted objects. 6 | 7 | pub use lrs_rc::{Rc, RcBuf, Arc, ArcBuf}; 8 | -------------------------------------------------------------------------------- /src/lrs/hashmap.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_hashmap::{CompactMap, HashMap, Entry, VacantEntry, OccupiedEntry}; 6 | -------------------------------------------------------------------------------- /src/lrs/getopt.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! A simple non-allocating argument parser. 6 | 7 | pub use lrs_getopt::{Getopt}; 8 | -------------------------------------------------------------------------------- /Documentation/Makefile: -------------------------------------------------------------------------------- 1 | adocs := $(shell find adoc/ -name "*.adoc") 2 | htmls := $(patsubst adoc/%.adoc, html/%.html, $(adocs)) 3 | 4 | .PHONY: all clean 5 | 6 | all: $(htmls) 7 | 8 | html: 9 | mkdir html 10 | 11 | html/%.html: adoc/%.adoc | html 12 | asciidoctor "$<" -o "$@" 13 | 14 | clean: 15 | rm -r html 16 | -------------------------------------------------------------------------------- /src/lrs/option.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Optional values 6 | 7 | pub use lrs_core::option::{ 8 | Option, 9 | }; 10 | -------------------------------------------------------------------------------- /tests/fmt/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod num; 6 | mod str; 7 | mod option; 8 | mod boolean; 9 | mod result; 10 | mod tuple; 11 | -------------------------------------------------------------------------------- /src/lrs/util.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Utility functions. 6 | 7 | pub use lrs_arch_fns::{memchr, memrchr, equal, all_bytes, strlen, spin}; 8 | -------------------------------------------------------------------------------- /tests/base/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod result; 6 | // mod error; 7 | mod rmo; 8 | mod into; 9 | mod undef; 10 | mod default; 11 | -------------------------------------------------------------------------------- /src/lrs/slice.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Slice manipulation. 6 | 7 | pub use lrs_core::slice::{ 8 | from_ptr, Items, Split, 9 | }; 10 | -------------------------------------------------------------------------------- /src/lrs/stdio.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Standard input/output. 6 | 7 | pub mod raw { 8 | pub use lrs_base::raw_stdio::*; 9 | } 10 | -------------------------------------------------------------------------------- /make_plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | target="$(./targets.sh native)" 4 | 5 | rustc -o obj/$target/liblrs_core_plugin.so src/core_plugin/lib.rs 6 | 7 | for t in $(./targets.sh all); do 8 | if [[ ! -e obj/$t/liblrs_core_plugin.so ]]; then 9 | ln -s ../$target/liblrs_core_plugin.so obj/$t/liblrs_core_plugin.so 10 | fi 11 | done 12 | -------------------------------------------------------------------------------- /src/lrs/fmt.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Object formatting 6 | 7 | pub use lrs_fmt::{ 8 | Write, LowerHex, UpperHex, Debug, Display, 9 | }; 10 | -------------------------------------------------------------------------------- /src/lrs/io.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! I/O handling. 6 | 7 | pub use lrs_io::{Read, Write, BufRead, BufWrite}; 8 | pub use lrs_buf_reader::{BufReader}; 9 | -------------------------------------------------------------------------------- /src/lrs/repr.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Representations of built-in types. 6 | 7 | pub use lrs_core::repr::{ 8 | Slice, TraitObject, Repr, 9 | }; 10 | -------------------------------------------------------------------------------- /src/libc/arm.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub struct pthread_t { 6 | _data: [u32; 1], 7 | } 8 | 9 | pub struct pthread_attr_t { 10 | _data: [u32; 9], 11 | } 12 | -------------------------------------------------------------------------------- /src/libc/x86.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub struct pthread_t { 6 | _data: [u32; 1], 7 | } 8 | 9 | pub struct pthread_attr_t { 10 | _data: [u32; 9], 11 | } 12 | -------------------------------------------------------------------------------- /src/libc/x86_64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub struct pthread_t { 6 | _data: [u64; 1], 7 | } 8 | 9 | pub struct pthread_attr_t { 10 | _data: [u64; 7], 11 | } 12 | -------------------------------------------------------------------------------- /src/lrs/marker.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Type markers 6 | 7 | pub use lrs_core::marker::{ 8 | Sized, Pod, Copy, Sync, NoSync, Send, NoSend, Leak, PhantomData, Unsize, 9 | }; 10 | -------------------------------------------------------------------------------- /src/lrs/dir.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Operations for reading the entries in a directory and walking through a directory 6 | //! tree. 7 | 8 | pub use lrs_dir::{Entry, Iter, DEFAULT_BUF_SIZE, iter}; 9 | -------------------------------------------------------------------------------- /src/libc/aarch64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub struct pthread_t { 6 | _data: [u64; 1], 7 | } 8 | 9 | pub struct pthread_attr_t { 10 | _data: [u64; 8], // 7 with musl, 8 with glibc 11 | } 12 | -------------------------------------------------------------------------------- /src/lrs/string.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! String types. 6 | 7 | pub use lrs_str_one::{ByteStr, NoNullStr, CStr}; 8 | pub use lrs_str_two::{CString, String}; 9 | pub use lrs_c_ptr_ptr::{CPtrPtr}; 10 | -------------------------------------------------------------------------------- /src/lrs/iter.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Iterators 6 | 7 | pub use lrs_core::iter::{ 8 | Iterator, Empty, IntoIterator, 9 | }; 10 | pub use lrs_iter::{ 11 | repeat, Repeat, IteratorExt, Map, 12 | }; 13 | -------------------------------------------------------------------------------- /tests/core/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | mod array; 6 | mod bool; 7 | mod char; 8 | mod cmp; 9 | mod tuple; 10 | mod mem; 11 | mod num; 12 | mod option; 13 | mod ptr; 14 | mod repr; 15 | mod slice; 16 | mod str; 17 | -------------------------------------------------------------------------------- /src/lrs/rand.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_rand::{Gen, Rng, Xorshift}; 6 | #[cfg(not(freestanding))] pub use lrs_rand::{GetRandom, GetUrandom}; 7 | #[cfg(not(freestanding))] pub use lrs_rand::{DevRandom, DevUrandom}; 8 | -------------------------------------------------------------------------------- /tests/core/array.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn eq() { 7 | test!([0] == [0]); 8 | test!([0, 1] == [0, 1]); 9 | test!([0, 1, 2] == [0, 1, 2]); 10 | test!([0, 1, 2, 3] != [0, 1, 2, 4]); 11 | } 12 | -------------------------------------------------------------------------------- /src/lrs/msg_queue.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_mqueue::{MqAttr, MsgQueue, remove}; 6 | pub use lrs_mqueue::flags::{MqFlags}; 7 | 8 | pub mod flags { 9 | pub use lrs_mqueue::flags::{MQ_NONE, MQ_DONT_BLOCK}; 10 | } 11 | -------------------------------------------------------------------------------- /tests/core/repr.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::repr::{Repr}; 6 | 7 | #[test] 8 | fn slice() { 9 | let x: &[u8] = &[1, 2]; 10 | let y = x.repr(); 11 | test!(y.len == 2); 12 | test!(y.ptr == &x[0]); 13 | } 14 | -------------------------------------------------------------------------------- /src/fmt/impls/unit.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Debug, Write}; 7 | 8 | impl Debug for () { 9 | fn fmt(&self, w: &mut W) -> Result { 10 | w.write(b"()").ignore_ok() 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/lrs/user.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! User handling. 6 | 7 | pub use lrs_cty::alias::{UserId}; 8 | pub use lrs_user_group::user::{Info, InfoIter, Information, InformationIter, 9 | INFO_BUF_SIZE, UserInfo, iter, iter_buf}; 10 | -------------------------------------------------------------------------------- /src/lrs/num.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Number types 6 | 7 | pub use lrs_int::{ 8 | Int, UnsignedInt, SignedInt, 9 | }; 10 | pub use lrs_saturating::{ 11 | SaturatingCast, 12 | }; 13 | pub use lrs_wrapping::{W8, W16, W32, W64, Wsize}; 14 | -------------------------------------------------------------------------------- /src/r_syscall/x86_64/x64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_long}; 6 | 7 | pub use ::arch::common::{ 8 | syscall0, syscall1, syscall2, syscall3, syscall4, syscall5, syscall6, 9 | }; 10 | 11 | /// Syscall type 12 | pub type SCT = c_long; 13 | -------------------------------------------------------------------------------- /src/lrs/env.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Process environment. 6 | 7 | pub use lrs_rt::{args, arg_count, env}; 8 | pub use lrs_env::{var, path, get_cwd, get_cwd_pool, set_cwd}; 9 | 10 | pub mod aux { 11 | pub use lrs_rt::aux::{page_size}; 12 | } 13 | -------------------------------------------------------------------------------- /src/lrs/swap.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_swap::{swap_on, swap_off}; 6 | pub use lrs_swap::flags::{SwapFlags}; 7 | 8 | pub mod flags { 9 | pub use lrs_swap::flags::{ 10 | SWAP_NONE, SWAP_PREFER, SWAP_DISCARD, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /tests/cty/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | // TODO: cty includes many hairy details that could probably be tested here. But 6 | // unfortunately this testing system was set up only after cty was mostly done. Many of 7 | // those details are documented with comments, though. 8 | -------------------------------------------------------------------------------- /asm/aarch64-unknown-linux-gnu/src/stop_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(stack_base, stack_size, tmp_stack) -> ! 4 | # 5 | # x0 = stack_base 6 | # x1 = stack_size 7 | # x2 = tmp_stack 8 | 9 | .global __stop_thread 10 | .type __stop_thread,@function 11 | __stop_thread: 12 | and x2,x2,#-16 13 | mov sp,x2 14 | 15 | mov x8,#215 // __NR_munmap 16 | svc #0 17 | 18 | mov x0,#0 19 | mov x8,#93 // __NR_exit 20 | svc #0 21 | -------------------------------------------------------------------------------- /asm/armv6-unknown-linux-gnueabi/src/stop_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(stack_base, stack_size, tmp_stack) -> ! 4 | # 5 | # r0 = stack_base 6 | # r1 = stack_size 7 | # r2 = tmp_stack 8 | 9 | .global __stop_thread 10 | .type __stop_thread,%function 11 | __stop_thread: 12 | and r2,r2,#-16 13 | mov sp,r2 14 | 15 | mov r7,#91 // __NR_munmap 16 | svc #0 17 | 18 | mov r0,#0 19 | mov r7,#1 // __NR_exit 20 | svc #0 21 | -------------------------------------------------------------------------------- /src/lrs/event.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_event::{Eventfd}; 6 | pub use lrs_event::flags::{EventfdFlags}; 7 | 8 | pub mod flags { 9 | pub use lrs_event::flags::{ 10 | EFD_NONE, EFD_CLOSE_ON_EXEC, EFD_DONT_BLOCK, EFD_SEMAPHORE, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /src/lrs/parse.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Byte parsing. 6 | 7 | pub use lrs_parse::{ 8 | Parse, Parsable, 9 | 10 | HexU8, HexU16, HexU32, HexU64, HexUsize, OctU8, OctU16, OctU32, OctU64, OctUsize, 11 | BinU8, BinU16, BinU32, BinU64, BinUsize, 12 | }; 13 | -------------------------------------------------------------------------------- /src/lrs/poll.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! File descriptor polling. 6 | 7 | pub use lrs_poll::{ 8 | PollFlags, Event, Epoll, EMPTY_EVENT, POLL_READ, POLL_WRITE, POLL_READ_HANG_UP, 9 | POLL_PRIORITY, POLL_EDGE_TRIGGERED, POLL_ONE_SHOT, POLL_WAKE_UP, 10 | }; 11 | -------------------------------------------------------------------------------- /src/fmt/impls/tuple.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Debug, Write}; 7 | 8 | impl Debug for (T1, T2) { 9 | fn fmt(&self, mut w: &mut W) -> Result { 10 | write!(w, "({:?}, {:?})", self.0, self.1) 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/lrs/bx.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! An allocated container. 6 | //! 7 | //! = Description 8 | //! 9 | //! :box: link:lrs::bx::Box[Box] 10 | //! 11 | //! This module contains the {box} structure which is a simple heap allocated container. 12 | 13 | pub use lrs_box::{Box, BoxBuf}; 14 | -------------------------------------------------------------------------------- /tests/fmt/tuple.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | #[test] 8 | fn debug() { 9 | let mut buf = [0; 20]; 10 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 11 | write!(&mut buf, "{:?}", (1, 1)); 12 | test!(&*buf == "(1, 1)"); 13 | } 14 | -------------------------------------------------------------------------------- /src/lrs/group.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Group handling. 6 | 7 | pub use lrs_cty::alias::{GroupId}; 8 | pub use lrs_user_group::group::{ 9 | Info, InfoIter, InfoMemberIter, Information, InformationIter, InformationMemberIter, 10 | INFO_BUF_SIZE, GroupInfo, iter, iter_buf, 11 | }; 12 | -------------------------------------------------------------------------------- /asm/x86_64-unknown-linux-gnu/src/stop_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(stack_base, stack_size, tmp_stack) -> ! 4 | # 5 | # %rdi = stack_base 6 | # %rsi = stack_size 7 | # %rdx = tmp_stack 8 | 9 | .global __stop_thread 10 | .type __stop_thread,@function 11 | __stop_thread: 12 | mov %rdx,%rsp # kernel might want to use our stack a bit 13 | and $-16,%rsp 14 | 15 | mov $11,%rax # __NR_munmap 16 | syscall 17 | 18 | xor %rdi,%rdi 19 | mov $60,%rax # __NR_exit 20 | syscall 21 | -------------------------------------------------------------------------------- /src/lrs/sync.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Multi-threaded communication and synchronization. 6 | 7 | pub use lrs_lock::{ 8 | RawCondvar, Lock, LockGuard, DUMMY, Mutex, 9 | MutexGuard, Condvar, LockStatus, Once, 10 | SpinLock, SpinLockGuard, SpinLockStatus, 11 | }; 12 | pub use lrs_queue::{ 13 | Queue, 14 | }; 15 | -------------------------------------------------------------------------------- /tests/core/bool.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::bool::{BoolExt}; 6 | 7 | #[test] 8 | fn map() { 9 | test!(true.map(|| 1u8) == Some(1)); 10 | test!(false.map(|| 1u8) == None); 11 | } 12 | 13 | #[test] 14 | fn eq() { 15 | test!(true == true); 16 | test!(false == false); 17 | test!(false != true); 18 | } 19 | -------------------------------------------------------------------------------- /tests/core/tuple.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn eq() { 7 | test!((1, 2) == (1, 2)); 8 | test!((1, 2) != (1, 3)); 9 | test!((1, 2, 3) == (1, 2, 3)); 10 | test!((1, 2, 3) != (1, 3, 3)); 11 | } 12 | 13 | #[test] 14 | fn ord() { 15 | test!((1, 2) < (1, 3)); 16 | test!((1, 2, 3) < (1, 3, 3)); 17 | } 18 | -------------------------------------------------------------------------------- /src/libc/x32.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub struct pthread_t { 6 | _data: [u32; 1], 7 | } 8 | 9 | // XXX: This has size 32 in glibc but 36 in musl. We'll just waste some bytes to be 10 | // compatible with both. Note that this is never embedded in another libc structure. 11 | pub struct pthread_attr_t { 12 | _data: [u32; 9], 13 | } 14 | -------------------------------------------------------------------------------- /src/lrs/cmp.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Ordering comparisons 6 | //! 7 | //! = Description 8 | //! 9 | //! This module provides structures and functions that operate on objects in a partial or 10 | //! total order. 11 | 12 | pub use lrs_core::cmp::{ 13 | PartialOrd, Ord, Ordering, min, min_ref, min_mut, max, max_ref, max_mut, 14 | }; 15 | -------------------------------------------------------------------------------- /src/lrs/conv.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_base::conv::as_ref::{AsRef, AsMut, TryAsRef, TryAsMut}; 6 | pub use lrs_base::conv::from::{From, TryFrom}; 7 | pub use lrs_base::conv::to::{To, TryTo}; 8 | pub use lrs_base::conv::out_of::{OutOf}; 9 | pub use lrs_base::conv::into::{Into}; 10 | pub use lrs_base::conv::clone::{Clone, TryClone}; 11 | -------------------------------------------------------------------------------- /tests/cell/cell.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::share::{Cell}; 6 | 7 | #[test] 8 | fn test() { 9 | let cell = Cell::new(1); 10 | unsafe { 11 | test!(cell.get() == 1); 12 | test!(*cell.ptr() == 1); 13 | *cell.ptr() = 2; 14 | test!(cell.get() == 2); 15 | test!(*cell.ptr() == 2); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/lrs/cfg.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! lrs configuration options. 6 | //! 7 | //! = Remarks 8 | //! 9 | //! The constants in this module allow the user to query the state of various 10 | //! configuration options that were used during the lrs compilation. 11 | 12 | pub use lrs_cfg::{NO_LIBC, RETRY, NO_LINK_ARGS, JEMALLOC, DEVICE_PATHS, TRY_ABORT}; 13 | -------------------------------------------------------------------------------- /src/hash/impls/bool.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | impl Hash for bool { 9 | fn stateful_hash(&self, h: &mut H) { 10 | h.write_u8(*self as u8); 11 | } 12 | 13 | fn hash>(&self, seed: S) -> H::Digest { 14 | H::hash_u8(*self as u8, seed) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/base/conv/into.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use prelude::*; 6 | 7 | /// Objects that can be turned into other objects. 8 | pub trait Into { 9 | /// Turns the object into another object. 10 | fn into(self) -> T; 11 | } 12 | 13 | impl Into for U 14 | where T: OutOf 15 | { 16 | fn into(self) -> T { 17 | T::out_of(self) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/lrs/hash.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_hash::{Hash, Hasher}; 6 | 7 | pub mod xx_hash { 8 | pub use lrs_hash::xx_hash::{ 9 | u32hash_bytes, u64hash_bytes, u32hash_u8, u32hash_u16, u32hash_u32, u32hash_u64, 10 | u32hash_usize, u64hash_u8, u64hash_u16, u64hash_u32, u64hash_u64, u64hash_usize, 11 | XxHash32, XxHash64, 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /src/fmt/impls/errno.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use base::error::{Errno}; 7 | use {Write, Debug}; 8 | 9 | impl Debug for Errno { 10 | fn fmt(&self, mut w: &mut W) -> Result { 11 | match self.name() { 12 | Some(n) => w.write_str(n).ignore_ok(), 13 | _ => write!(w, "Unknown({})", self.0), 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/hash/impls/errno.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | use base::error::{Errno}; 8 | 9 | impl Hash for Errno { 10 | fn stateful_hash(&self, h: &mut H) { 11 | h.write_i32(self.0) 12 | } 13 | 14 | fn hash>(&self, seed: S) -> H::Digest { 15 | H::hash_i32(self.0, seed) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/lrs/ptr.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Pointer manipulation. 6 | 7 | pub use lrs_core::ptr::{ 8 | read, write, drop, memcpy, memmove, NonZeroPtr, volatile_load, volatile_store, 9 | NoAliasMemPtr, AliasMemPtr, NoAliasObjPtr, AliasObjPtr, NoAliasMutObjPtr, 10 | AliasMutObjPtr, 11 | }; 12 | 13 | pub use lrs_arch_fns::{ 14 | memcpy_aligned_16_64, memcpy_aligned_16_16, 15 | }; 16 | -------------------------------------------------------------------------------- /asm/aarch64-unknown-linux-gnu/src/start_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(flags, stack, ptid, tp, ctid, func, arg) -> c_long 4 | # 5 | # x0 = flags 6 | # x1 = stack 7 | # x2 = ptid 8 | # x3 = tp 9 | # x4 = ctid 10 | # x5 = func 11 | # x6 = arg 12 | 13 | .global __start_thread 14 | .type __start_thread,@function 15 | __start_thread: 16 | stp x5,x6,[x1,#-16]! // push func and arg on stack 17 | 18 | mov x8,#220 // __NR_clone 19 | svc #0 20 | 21 | cbz x0, 1f // child thread 22 | ret 23 | 24 | 1: ldp x1,x0,[sp],#16 // load func and arg from stack 25 | blr x1 26 | -------------------------------------------------------------------------------- /src/lrs/pipe.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Kernel pipes. 6 | 7 | pub use lrs_pipe::{Pipe}; 8 | pub use lrs_pipe::flags::{PipeFlags, TeeFlags, SpliceFlags}; 9 | 10 | pub mod flags { 11 | pub use lrs_pipe::flags::{ 12 | PIPE_NONE, PIPE_CLOSE_ON_EXEC, PIPE_DONT_BLOCK, PIPE_PACKETS, 13 | TEE_NONE, TEE_DONT_BLOCK, 14 | SPLICE_NONE, SPLICE_DONT_BLOCK, SPLICE_MORE, 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /asm/i686-unknown-linux-gnu/src/stop_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(stack_base, stack_size, tmp_stack) -> ! 4 | # 5 | # 4(%esp) = stack_base 6 | # 8(%esp) = stack_size 7 | # 12(%esp) = tmp_stack 8 | 9 | .global __stop_thread 10 | .type __stop_thread,@function 11 | __stop_thread: 12 | mov 4(%esp),%ebx # %ebx = stack_base 13 | mov 8(%esp),%ecx # %ecx = stack_size 14 | 15 | mov 12(%esp),%esp # %esp = tmp_stack 16 | and $-16,%esp 17 | 18 | mov $91,%eax # __NR_munmap 19 | int $0x80 20 | 21 | xor %ebx,%ebx 22 | mov $1,%eax # __NR_exit 23 | int $0x80 24 | -------------------------------------------------------------------------------- /src/base/conv/default.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::marker::{Sized}; 6 | use conv::out_of::{OutOf}; 7 | 8 | /// Types that have a default value. 9 | pub trait Default: OutOf+Sized { 10 | /// Returns the default value of this type. 11 | fn default() -> Self; 12 | } 13 | 14 | impl Default for T 15 | where T: OutOf 16 | { 17 | fn default() -> T { 18 | T::out_of(()) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Documentation/README.adoc: -------------------------------------------------------------------------------- 1 | = Documentation 2 | 3 | This directory contains general documentation surrounding lrs. 4 | 5 | If you're reading this on github, you can go to link:adoc/index.adoc[] to see 6 | the index. But you can also generate a much more beautiful html version by 7 | running the provided makefile. Note that you first have to install the 8 | `asciidoctor` program. 9 | 10 | :manual: http://asciidoctor.org/docs/user-manual/ 11 | 12 | This documentation is written in the Asciidoctor dialect of Asciidoc. See the 13 | {manual}[manual] if you want to edit the documentation or add new documentation. 14 | -------------------------------------------------------------------------------- /src/cell/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_cell"] 6 | #![crate_type = "lib"] 7 | #![feature(lang_items, optin_builtin_traits, const_fn)] 8 | #![no_std] 9 | 10 | extern crate lrs_base as base; 11 | 12 | pub use ref_cell::{RefCell, RefCellStatus, RefCellBorrow, RefCellBorrowMut}; 13 | pub use cell::{Cell}; 14 | 15 | pub mod std { pub use ::base::std::*; } 16 | 17 | pub mod ref_cell; 18 | pub mod cell; 19 | -------------------------------------------------------------------------------- /src/rt/libc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod tls { 6 | use {AtExit}; 7 | use lock::{SingleThreadMutex}; 8 | 9 | pub unsafe fn init() { 10 | // Managed by libc 11 | } 12 | 13 | thread_local! { 14 | static AT_EXIT: SingleThreadMutex = SingleThreadMutex::new(AtExit::new()); 15 | } 16 | 17 | pub fn at_exit() -> &'static SingleThreadMutex { 18 | &AT_EXIT 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/lrs/ops.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Operator traits 6 | //! 7 | //! = Description 8 | //! 9 | //! This module contains traits and structures that are used via special symbols, e.g., 10 | //! `+`, `==`, or `..`. 11 | 12 | pub use lrs_core::ops::{ 13 | Drop, Add, Sub, Mul, Div, Rem, Neg, Not, BitAnd, BitOr, Shl, Shr, Index, IndexMut, 14 | RangeFull, Range, RangeFrom, RangeTo, Deref, DerefMut, Eq, PartialOrd, Fn, FnMut, 15 | FnOnce, CoerceUnsized, 16 | }; 17 | -------------------------------------------------------------------------------- /src/rmo/impls/byte_string.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use str_one::byte_str::{ByteStr}; 7 | use str_two::byte_string::{ByteString}; 8 | use {ToOwned}; 9 | use alloc::{MemPool}; 10 | 11 | impl ToOwned for ByteStr 12 | where H: MemPool, 13 | { 14 | type Owned = ByteString; 15 | fn to_owned_with_pool(&self, pool: H) -> Result> { 16 | self.as_ref().to_owned_with_pool(pool).map(|o| ByteString::from_vec(o)) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /asm/x86_64-unknown-linux-gnu/src/start_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(flags, stack, ptid, arg, tp, func, ctid) -> c_long 4 | # 5 | # %rdi = flags 6 | # %rsi = stack 7 | # %rdx = ptid 8 | # %rcx = arg 9 | # %r8 = tp 10 | # %r9 = func 11 | # 8(%rsp) = ctid 12 | 13 | .global __start_thread 14 | .type __start_thread,@function 15 | __start_thread: 16 | sub $8,%rsi 17 | mov %rcx,(%rsi) # top of child stack = arg 18 | 19 | mov 8(%rsp),%r10 # %r10 = ctid 20 | mov $56,%rax # __NR_clone 21 | syscall 22 | 23 | test %eax,%eax 24 | jnz 1f # parent thread 25 | 26 | pop %rdi # %rdi = arg 27 | call *%r9 # does not return 28 | 29 | 1: ret 30 | -------------------------------------------------------------------------------- /src/varargs/x86.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {VarArg}; 6 | use core::{ptr, mem}; 7 | 8 | #[repr(C)] 9 | pub struct VarArgs { 10 | stack: *mut u8, 11 | } 12 | 13 | impl VarArgs { 14 | pub unsafe fn get(&mut self) -> T { 15 | let val = ptr::read(self.stack as *mut T); 16 | match mem::size_of::() { 17 | 0...4 => self.stack = self.stack.add(4), 18 | l => self.stack = self.stack.add(l), 19 | } 20 | val 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/lrs/intrinsics.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Compiler intrinsics 6 | //! 7 | //! = Description 8 | //! 9 | //! This module provides direct access to compiler built-in functions. They are all unsafe 10 | //! and have safe wrappers in other modules. 11 | 12 | pub use lrs_core::intrinsics::{ 13 | discriminant_value, abort, breakpoint, size_of, move_val_init, min_align_of, 14 | init_dropped, init, uninit, forget, transmute, needs_drop, offset, copy, 15 | copy_nonoverlapping, lrs_abort, unreachable, 16 | }; 17 | -------------------------------------------------------------------------------- /src/lrs/share.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Single-threaded interior mutability 6 | //! 7 | //! = Description 8 | //! 9 | //! This module provides structures that allow data-modification through immutable 10 | //! references. None of the objects are safe to use from multiple threads. 11 | 12 | pub use lrs_core::thread_local::{__ThreadLocal}; 13 | pub use lrs_cell::{ 14 | Cell, RefCellStatus, RefCell, RefCellBorrow, RefCellBorrowMut, 15 | }; 16 | pub use lrs_lock::{ 17 | SingleThreadLock, SingleThreadMutex, 18 | }; 19 | -------------------------------------------------------------------------------- /src/fmt/impls/boolean.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Write, Debug, Display}; 7 | 8 | impl Debug for bool { 9 | fn fmt(&self, w: &mut W) -> Result { 10 | let s = if *self { "true" } else { "false" }; 11 | w.write_all(s.as_bytes()).ignore_ok() 12 | } 13 | } 14 | 15 | impl Display for bool { 16 | fn fmt(&self, w: &mut W) -> Result { 17 | let s = if *self { "true" } else { "false" }; 18 | w.write_all(s.as_bytes()).ignore_ok() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/lrs/fd.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Raw file descriptor handling. 6 | 7 | pub use lrs_fd::{STDIN, STDOUT, STDERR, FdIo, FdContainer}; 8 | pub use lrs_fd::flags::{DescriptionFlags}; 9 | 10 | /// File description flags. 11 | pub mod flags { 12 | pub use lrs_fd::flags::{ 13 | FD_ACCESS_MASK, 14 | FD_NONE, FD_READ_ONLY, FD_WRITE_ONLY, FD_READ_WRITE, FD_BYPASS_BUFFER, 15 | FD_NO_ACCESS_TIME_UPDATE, FD_APPEND, FD_SIGNAL_IO, FD_SYNC, FD_DATA_SYNC, 16 | FD_DONT_BLOCK, FD_PATH, 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /tests/alloc/no.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{self, Dummy, MemPool}; 6 | 7 | #[test] 8 | fn allocate_raw() { 9 | unsafe { 10 | test!(Dummy::out_of(()).alloc(1, 1).is_err()); 11 | } 12 | } 13 | 14 | #[test] 15 | fn allocate() { 16 | unsafe { 17 | test!(alloc::alloc::(&mut Dummy::out_of(())).is_err()); 18 | } 19 | } 20 | 21 | #[test] 22 | fn allocate_array() { 23 | unsafe { 24 | test!(alloc::alloc_array::(&mut Dummy::out_of(()), 1).is_err()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/base/conv/to.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use prelude::*; 6 | 7 | pub trait To: TryTo { 8 | fn to(&self) -> T; 9 | } 10 | 11 | impl To for U 12 | where T: From 13 | { 14 | fn to(&self) -> T { 15 | T::from(self) 16 | } 17 | } 18 | 19 | pub trait TryTo { 20 | fn try_to(&self) -> Result; 21 | } 22 | 23 | impl TryTo for U 24 | where T: TryFrom 25 | { 26 | fn try_to(&self) -> Result { 27 | T::try_from(self) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/base/default.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn zero() { 7 | test!(u8::out_of(()) == 0); 8 | test!(u16::out_of(()) == 0); 9 | test!(u32::out_of(()) == 0); 10 | test!(u64::out_of(()) == 0); 11 | test!(usize::out_of(()) == 0); 12 | test!(i8::out_of(()) == 0); 13 | test!(i16::out_of(()) == 0); 14 | test!(i32::out_of(()) == 0); 15 | test!(i64::out_of(()) == 0); 16 | test!(isize::out_of(()) == 0); 17 | } 18 | 19 | #[test] 20 | fn option() { 21 | test!(Option::::out_of(()) == None); 22 | } 23 | -------------------------------------------------------------------------------- /src/cty_base/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_cty_base"] 6 | #![crate_type = "lib"] 7 | #![no_std] 8 | #![allow(non_upper_case_globals, non_camel_case_types)] 9 | 10 | pub use arch::{errno, types}; 11 | 12 | mod gen; 13 | 14 | #[cfg(target_arch = "x86_64")] 15 | #[path = "x86_64.rs"] 16 | mod arch; 17 | 18 | #[cfg(target_arch = "x86")] 19 | #[path = "x86.rs"] 20 | mod arch; 21 | 22 | #[cfg(target_arch = "arm")] 23 | #[path = "arm.rs"] 24 | mod arch; 25 | 26 | #[cfg(target_arch = "aarch64")] 27 | #[path = "aarch64.rs"] 28 | mod arch; 29 | -------------------------------------------------------------------------------- /asm/armv6-unknown-linux-gnueabi/src/start_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(flags, stack, ptid, tp, ctid, func, arg) -> c_long 4 | # 5 | # r0 = flags 6 | # r1 = stack 7 | # r2 = ptid 8 | # r3 = tp 9 | # [sp,#16] = ctid 10 | # [sp,#20] = func 11 | # [sp,#24] = arg 12 | 13 | .global __start_thread 14 | .type __start_thread,%function 15 | __start_thread: 16 | stmfd sp!,{r4,r5,r6,r7} // save registers 17 | 18 | ldr r4,[sp,#16] // r4 = ctid 19 | ldr r5,[sp,#20] // r5 = func 20 | ldr r6,[sp,#24] // r6 = arg 21 | mov r7,#120 // __NR_clone 22 | svc #0 23 | 24 | tst r0,r0 25 | beq 1f // child thread 26 | 27 | ldmfd sp!,{r4,r5,r6,r7} 28 | bx lr 29 | 30 | 1: mov r0,r6 31 | bx r5 // does not return 32 | -------------------------------------------------------------------------------- /src/hash/impls/option.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | impl Hash for Option { 9 | fn hash>(&self, seed: S) -> H::Digest { 10 | match *self { 11 | Some(ref o) => H::hash(o, seed), 12 | _ => H::hash_u8(0, seed), 13 | } 14 | } 15 | 16 | fn stateful_hash(&self, h: &mut H) { 17 | match *self { 18 | Some(ref o) => o.stateful_hash(h), 19 | _ => h.write_u8(0), 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/rmo/impls/no_null_string.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use str_one::no_null_str::{NoNullStr}; 7 | use str_two::no_null_string::{NoNullString}; 8 | use {ToOwned}; 9 | use alloc::{MemPool}; 10 | 11 | impl ToOwned for NoNullStr 12 | where H: MemPool, 13 | { 14 | type Owned = NoNullString; 15 | fn to_owned_with_pool(&self, pool: H) -> Result> { 16 | (self.as_ref():&[u8]).to_owned_with_pool(pool).map(|o| unsafe { 17 | NoNullString::from_bytes_unchecked(o) 18 | }) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/alloc/align.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{AlignAlloc, TaPool, MemPool}; 6 | use std::{mem}; 7 | 8 | #[test] 9 | fn allocate_raw() { 10 | unsafe { 11 | let mut buf = [0u32; 4]; 12 | let addr = mem::addr(&buf); 13 | let mut buf = buf.as_mut(); 14 | let mut aa = AlignAlloc::::new(TaPool::new(&mut buf)); 15 | let alloc = aa.alloc(1, 1).unwrap(); 16 | test!(alloc as usize == addr); 17 | let alloc = aa.alloc(1, 1).unwrap(); 18 | test!(alloc as usize == addr + 4); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/hash/impls/result.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | impl Hash for Result { 9 | fn hash>(&self, seed: S) -> H::Digest { 10 | match *self { 11 | Ok(ref o) => H::hash(o, seed), 12 | Err(ref e) => H::hash(e, seed), 13 | } 14 | } 15 | 16 | fn stateful_hash(&self, h: &mut H) { 17 | match *self { 18 | Ok(ref o) => o.stateful_hash(h), 19 | Err(ref e) => e.stateful_hash(h), 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/fmt/boolean.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | macro_rules! tt { 8 | ($fmt:expr, $name:ident) => { 9 | #[test] 10 | fn $name() { 11 | let mut buf = [0; 10]; 12 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 13 | write!(&mut buf, $fmt, true).unwrap(); 14 | test!(&*buf == "true"); 15 | 16 | buf.truncate(0); 17 | write!(&mut buf, $fmt, false).unwrap(); 18 | test!(&*buf == "false"); 19 | } 20 | } 21 | } 22 | 23 | tt!("{:?}", debug); 24 | tt!("{}", display); 25 | -------------------------------------------------------------------------------- /src/slice/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_slice"] 6 | #![crate_type = "lib"] 7 | #![feature(optin_builtin_traits)] 8 | #![no_std] 9 | 10 | extern crate lrs_base as base; 11 | 12 | use base::prelude::*; 13 | 14 | /// Extensions for slices. 15 | pub trait SliceExt { 16 | fn last_to(&self) -> Option 17 | where T: To; 18 | } 19 | 20 | impl SliceExt for [T] { 21 | fn last_to(&self) -> Option 22 | where T: To, 23 | { 24 | match self.last() { 25 | Some(r) => Some(r.to()), 26 | _ => None, 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Documentation/adoc/index.adoc: -------------------------------------------------------------------------------- 1 | = lrs Documentation 2 | ifdef::env-github[:outfilesuffix: .adoc] 3 | 4 | <>:: Explains in detail how to 5 | build and use lrs. 6 | <>:: Explains how to compile lrs+musl programs. 7 | <>:: Explains how to cross-compile lrs 8 | programs. 9 | <>:: Describes the markup language used in lrs 10 | documentation. 11 | <>:: A brief discussion of the `unsafe` keyword. 12 | <>:: Very short descriptions of the lrs crates. 13 | <>:: Very short descriptions of Linux syscalls. 14 | <>:: An incomplete list of 15 | undefined operations in lrs. 16 | -------------------------------------------------------------------------------- /src/str_two/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_str_two"] 6 | #![crate_type = "lib"] 7 | #![feature(type_ascription)] 8 | #![no_std] 9 | 10 | extern crate lrs_arch_fns as arch_fns; 11 | extern crate lrs_base as base; 12 | extern crate lrs_str_one as str_one; 13 | extern crate lrs_alloc as alloc; 14 | extern crate lrs_fmt as fmt; 15 | extern crate lrs_vec as vec; 16 | extern crate lrs_box as bx; 17 | 18 | pub use c_string::{CString}; 19 | pub use string::{String}; 20 | 21 | mod std { pub use fmt::std::*; } 22 | 23 | pub mod c_string; 24 | pub mod string; 25 | mod cmp; 26 | mod conv; 27 | -------------------------------------------------------------------------------- /src/str_one/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_str_one"] 6 | #![crate_type = "lib"] 7 | #![feature(type_ascription)] 8 | #![allow(mutable_transmutes)] 9 | #![no_std] 10 | 11 | extern crate lrs_cty_base as cty_base; 12 | extern crate lrs_base as base; 13 | extern crate lrs_arch_fns as arch_fns; 14 | extern crate lrs_parse as parse; 15 | extern crate lrs_fmt as fmt; 16 | 17 | pub use byte_str::{ByteStr}; 18 | pub use no_null_str::{NoNullStr}; 19 | pub use c_str::{CStr}; 20 | 21 | mod std { pub use ::base::std::*; } 22 | 23 | mod byte_str; 24 | mod no_null_str; 25 | mod c_str; 26 | 27 | mod cmp; 28 | mod conv; 29 | -------------------------------------------------------------------------------- /src/rc/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_rc"] 6 | #![crate_type = "lib"] 7 | #![feature(optin_builtin_traits, associated_consts, thread_local)] 8 | #![no_std] 9 | 10 | extern crate lrs_base as base; 11 | extern crate lrs_fmt as fmt; 12 | extern crate lrs_cell as cell; 13 | extern crate lrs_alloc as alloc; 14 | extern crate lrs_atomic as atomic; 15 | 16 | pub use rc::{Rc, RcBuf}; 17 | pub use arc::{Arc, ArcBuf}; 18 | 19 | pub mod std { pub use ::fmt::std::*; } 20 | 21 | pub mod rc; 22 | pub mod arc; 23 | 24 | // TODO: Arc is actually just an Rc with some atomic operations. Maybe Arc should just 25 | // wrap an Rc? 26 | -------------------------------------------------------------------------------- /src/varargs/arm.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {VarArg}; 6 | use core::{mem, ptr}; 7 | 8 | #[repr(C)] 9 | pub struct VarArgs { 10 | stack: *mut u8, 11 | } 12 | 13 | impl VarArgs { 14 | pub unsafe fn get(&mut self) -> T { 15 | if mem::align_of::() > 4 { 16 | self.stack = align!(self.stack as usize, [%] mem::align_of::()) as *mut u8; 17 | } 18 | let val = ptr::read(self.stack as *mut T); 19 | match mem::size_of::() { 20 | 0...4 => self.stack = self.stack.add(4), 21 | l => self.stack = self.stack.add(l), 22 | } 23 | val 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/hash/impls/char.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | impl Hash for char { 9 | fn stateful_hash(&self, h: &mut H) { 10 | h.write_u32(*self as u32); 11 | } 12 | 13 | fn stateful_hash_slice(val: &[Self], h: &mut H) { 14 | h.write_bytes(val.as_ref()); 15 | } 16 | 17 | fn hash>(&self, seed: S) -> H::Digest { 18 | H::hash_u32(*self as u32, seed) 19 | } 20 | 21 | fn hash_slice>(val: &[Self], seed: S) -> H::Digest { 22 | H::hash_bytes(val.as_ref(), seed) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/lrs/mem_map.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_mem::{MemMap}; 6 | pub use lrs_mem::flags::{MemMapFlags, MemProtFlags, MemReMapFlags, MemSyncFlags}; 7 | 8 | pub mod flags { 9 | // pub use lrs_mem::flags::{ 10 | // MMAP_32BIT, MMAP_HUGE_2MB, MMAP_HUGE_1GB, 11 | // }; 12 | pub use lrs_mem::flags::{ 13 | MMAP_NONE, MMAP_ANON, MMAP_FIXED, MMAP_HUGE_PAGES, 14 | MMAP_LOCKED, MMAP_DONT_BLOCK, MMAP_DONT_RESERVE, MMAP_POPULATE, 15 | MMAP_UNINITIALIZED, PROT_NONE, PROT_EXEC, PROT_READ, PROT_WRITE, MREMAP_NONE, 16 | MREMAP_MAY_MOVE, MREMAP_FIXED, MSYNC_ASYNC, MSYNC_SYNC, MSYNC_INVALIDATE, 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/hash/impls/slice.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | impl Hash for [T] { 9 | fn stateful_hash(&self, h: &mut H) { 10 | T::stateful_hash_slice(self, h); 11 | } 12 | 13 | fn hash>(&self, seed: S) -> H::Digest { 14 | T::hash_slice::(self, seed) 15 | } 16 | } 17 | 18 | impl Hash for str { 19 | fn stateful_hash(&self, h: &mut H) { 20 | self.as_bytes().stateful_hash(h); 21 | } 22 | 23 | fn hash>(&self, seed: S) -> H::Digest { 24 | H::hash(self.as_bytes(), seed) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/rand/getrandom.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Rng, syscall, cty}; 7 | use io::{Read}; 8 | use rv::{retry}; 9 | 10 | pub struct GetRandom; 11 | 12 | impl Rng for GetRandom { } 13 | 14 | impl Read for GetRandom { 15 | fn scatter_read(&mut self, buf: &mut [&mut [d8]]) -> Result { 16 | retry(|| syscall::getrandom(buf[0], cty::GRND_RANDOM)).map(|r| r as usize) 17 | } 18 | } 19 | 20 | pub struct GetUrandom; 21 | 22 | impl Rng for GetUrandom { } 23 | 24 | impl Read for GetUrandom { 25 | fn scatter_read(&mut self, buf: &mut [&mut [d8]]) -> Result { 26 | retry(|| syscall::getrandom(buf[0], 0)).map(|r| r as usize) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/core/thread_local.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use marker::{Interrupt, NoSync, Sync}; 6 | use ops::{Deref}; 7 | 8 | /// [hidden] 9 | pub struct __ThreadLocal 10 | where T: Interrupt 11 | { 12 | val: T, 13 | _marker: NoSync, 14 | } 15 | 16 | impl __ThreadLocal 17 | where T: Interrupt 18 | { 19 | pub const fn new(val: T) -> __ThreadLocal { 20 | __ThreadLocal { 21 | val: val, 22 | _marker: NoSync, 23 | } 24 | } 25 | } 26 | 27 | impl Deref for __ThreadLocal 28 | where T: Interrupt 29 | { 30 | type Target = T; 31 | fn deref(&self) -> &T { 32 | &self.val 33 | } 34 | } 35 | 36 | unsafe impl Sync for __ThreadLocal where T: Interrupt { } 37 | -------------------------------------------------------------------------------- /src/core/array.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use ops::{Eq}; 6 | use marker::{Pod}; 7 | 8 | macro_rules! array_impl { 9 | ($($size:expr)+) => { 10 | $( 11 | impl Eq for [T; $size] { 12 | fn eq(&self, other: &[T; $size]) -> bool { 13 | for i in 0usize..$size { 14 | if self[i] != other[i] { 15 | return false; 16 | } 17 | } 18 | true 19 | } 20 | } 21 | 22 | unsafe impl Pod for [T; $size] { } 23 | )+ 24 | } 25 | } 26 | 27 | array_impl!(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 28 | 29 30 31 32); 29 | -------------------------------------------------------------------------------- /src/fmt/impls/option.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Write, LowerHex, UpperHex, Debug, Display}; 7 | 8 | macro_rules! imp { 9 | ($ty:ident) => { 10 | impl $ty for Option { 11 | fn fmt(&self, w: &mut W) -> Result { 12 | match *self { 13 | Some(ref t) => { 14 | try!(w.write_all(b"Some(").ignore_ok()); 15 | try!(t.fmt(w)); 16 | w.write_all(b")").ignore_ok() 17 | }, 18 | _ => w.write_all(b"None").ignore_ok() 19 | } 20 | } 21 | } 22 | } 23 | } 24 | 25 | imp!(LowerHex); 26 | imp!(UpperHex); 27 | imp!(Debug); 28 | imp!(Display); 29 | -------------------------------------------------------------------------------- /targets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function trans { 4 | case "$1" in 5 | i686) echo "i686-unknown-linux-gnu" ;; 6 | x86_64) echo "x86_64-unknown-linux-gnu" ;; 7 | aarch64) echo "aarch64-unknown-linux-gnu" ;; 8 | arm) echo "arm-unknown-linux-gnueabi" ;; 9 | lkern-kernel) echo "aarch64-lkern-kernel" ;; 10 | *) 11 | echo "unknown target" 12 | exit 1 13 | ;; 14 | esac 15 | } 16 | 17 | function native { 18 | rustc -V -v | grep "^host" | cut -d' ' -f 2 19 | } 20 | 21 | function all { 22 | trans i686 23 | trans x86_64 24 | trans aarch64 25 | trans arm 26 | trans lkern-kernel 27 | } 28 | 29 | if [[ $# -eq 0 ]]; then 30 | echo "Usage: $0 " 31 | exit 1 32 | fi 33 | 34 | case "$1" in 35 | native) native;; 36 | all) all;; 37 | trans) trans $2;; 38 | *) 39 | echo "unknown command" 40 | exit 1 41 | ;; 42 | esac 43 | -------------------------------------------------------------------------------- /src/vec/cmp_.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Vec}; 7 | use alloc::{MemPool}; 8 | use core::cmp::{Eq}; 9 | 10 | impl Eq> for Vec 11 | where T: Eq, 12 | H1: MemPool, 13 | H2: MemPool, 14 | { 15 | fn eq(&self, other: &Vec) -> bool { 16 | self.deref().eq(other.deref()) 17 | } 18 | fn ne(&self, other: &Vec) -> bool { 19 | self.deref().ne(other.deref()) 20 | } 21 | } 22 | 23 | impl Eq<[T]> for Vec 24 | where T: Eq, 25 | H: MemPool, 26 | { 27 | fn eq(&self, other: &[T]) -> bool { 28 | self.deref().eq(other) 29 | } 30 | fn ne(&self, other: &[T]) -> bool { 31 | self.deref().ne(other) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/fmt/option.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | macro_rules! tt { 8 | ($fmt:expr, $name:ident, $some:expr, $e1:expr, $e2:expr) => { 9 | #[test] 10 | fn $name() { 11 | let mut buf = [0; 20]; 12 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 13 | write!(buf, $fmt, $some); 14 | test!(&*buf == $e1); 15 | buf.truncate(0); 16 | write!(buf, $fmt, None::); 17 | test!(&*buf == $e2); 18 | } 19 | } 20 | } 21 | 22 | tt!("{:?}", debug, Some("ä"), "Some(\"\\u{e4}\")", "None"); 23 | tt!("{}", display, Some("ä"), "Some(ä)", "None"); 24 | tt!("{:x}", lower_hex, Some(255u8), "Some(ff)", "None"); 25 | tt!("{:X}", upper_hex, Some(255u8), "Some(FF)", "None"); 26 | -------------------------------------------------------------------------------- /src/core/panicking.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[lang = "stack_exhausted"] 6 | extern fn stack_exhausted() { 7 | abort!(); 8 | } 9 | 10 | // #[inline(always)] 11 | #[lang = "panic_bounds_check"] 12 | fn panic_bounds_check(_: &(&'static str, u32), _: usize, _: usize) -> ! { 13 | unsafe { ::intrinsics::breakpoint(); } 14 | abort!(); 15 | } 16 | 17 | // #[inline(always)] 18 | #[lang = "panic"] 19 | pub fn panic(_: &(&'static str, &'static str, u32)) -> ! { 20 | unsafe { ::intrinsics::breakpoint(); } 21 | abort!(); 22 | } 23 | 24 | #[lang="eh_personality"] 25 | #[no_mangle] 26 | #[allow(private_no_mangle_fns)] 27 | extern fn rust_eh_personality() { 28 | abort!(); 29 | } 30 | 31 | #[no_mangle] 32 | #[allow(non_snake_case)] 33 | pub extern fn _Unwind_Resume() { 34 | abort!(); 35 | } 36 | -------------------------------------------------------------------------------- /tests/fmt/result.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | macro_rules! tt { 8 | ($fmt:expr, $name:ident, $val:expr, $e1:expr, $e2:expr) => { 9 | #[test] 10 | fn $name() { 11 | let mut buf = [0; 20]; 12 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 13 | write!(buf, $fmt, Ok::<_, u8>($val)); 14 | test!(&*buf == $e1); 15 | buf.truncate(0); 16 | write!(buf, $fmt, Err::($val)); 17 | test!(&*buf == $e2); 18 | } 19 | } 20 | } 21 | 22 | tt!("{:?}", debug, "ä", "Ok(\"\\u{e4}\")", "Err(\"\\u{e4}\")"); 23 | tt!("{}", display, "ä", "Ok(ä)", "Err(ä)"); 24 | tt!("{:x}", lower_hex, 255u8, "Ok(ff)", "Err(ff)"); 25 | tt!("{:X}", upper_hex, 255u8, "Ok(FF)", "Err(FF)"); 26 | -------------------------------------------------------------------------------- /asm/Makefile: -------------------------------------------------------------------------------- 1 | asm_files := restore.o 2 | crt_files := start.o start_thread.o stop_thread.o 3 | 4 | cc ?= clang 5 | 6 | .PHONY: all clean 7 | 8 | define GEN 9 | 10 | all: $(1)/obj/liblrs_asm.a $(1)/obj/liblrs_crt.a 11 | 12 | $(1)_asm_paths := $$(patsubst %, $(1)/obj/%, $(asm_files)) 13 | $(1)_crt_paths := $$(patsubst %, $(1)/obj/%, $(crt_files)) 14 | 15 | $(1)/obj: 16 | mkdir $(1)/obj 17 | 18 | $(1)/obj/%.o: $(1)/src/%.s | $(1)/obj 19 | $(cc) --target=$(1) -c -o "$$@" "$$<" 20 | 21 | $(1)/obj/liblrs_asm.a: $$($(1)_asm_paths) 22 | ar rcs $(1)/obj/liblrs_asm.a $$($(1)_asm_paths) 23 | 24 | $(1)/obj/liblrs_crt.a: $$($(1)_crt_paths) 25 | ar rcs $(1)/obj/liblrs_crt.a $$($(1)_crt_paths) 26 | 27 | clean: $(1)_clean 28 | 29 | .PHONY: $(1)_clean 30 | 31 | $(1)_clean: 32 | rm -r $(1)/obj 33 | 34 | endef 35 | 36 | $(eval $(call GEN,x86_64-unknown-linux-gnu)) 37 | $(eval $(call GEN,i686-unknown-linux-gnu)) 38 | $(eval $(call GEN,aarch64-unknown-linux-gnu)) 39 | $(eval $(call GEN,armv6-unknown-linux-gnueabi)) 40 | -------------------------------------------------------------------------------- /src/rand/impls.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Gen, Rng}; 7 | 8 | impl Gen for bool { 9 | fn gen(g: &mut G) -> Result { 10 | let v = try!(u8::gen(g)); 11 | Ok(v & 1 == 0) 12 | } 13 | } 14 | 15 | impl Gen for Option { 16 | fn gen(g: &mut G) -> Result { 17 | if try!(bool::gen(g)) { 18 | Ok(Some(try!(T::gen(g)))) 19 | } else { 20 | Ok(None) 21 | } 22 | } 23 | } 24 | 25 | impl Gen for Result 26 | where T: Gen, 27 | E: Gen, 28 | { 29 | fn gen(g: &mut G) -> Result { 30 | if try!(bool::gen(g)) { 31 | Ok(Ok(try!(T::gen(g)))) 32 | } else { 33 | Ok(Err(try!(E::gen(g)))) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/cfg/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_cfg"] 6 | #![crate_type = "lib"] 7 | #![no_std] 8 | 9 | /// Whether lrs was compiled with the `no_libc` configuration. 10 | pub const NO_LIBC: bool = cfg!(no_libc); 11 | 12 | /// Whether lrs was compiled with the `retry` configuration. 13 | pub const RETRY: bool = cfg!(retry); 14 | 15 | /// Whether lrs was compiled with the `no_link_args` configuration. 16 | pub const NO_LINK_ARGS: bool = cfg!(no_link_args); 17 | 18 | /// Whether lrs was compiled with the `jemalloc` configuration. 19 | pub const JEMALLOC: bool = cfg!(jemalloc); 20 | 21 | /// Whether lrs was compiled with the `device_paths` configuration. 22 | pub const DEVICE_PATHS: bool = cfg!(device_paths); 23 | 24 | /// Whether lrs was compiled with the `try_abort` configuration. 25 | pub const TRY_ABORT: bool = cfg!(try_abort); 26 | -------------------------------------------------------------------------------- /src/rt/no_libc/tls/x86_64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use r_syscall::arch::{arch_prctl}; 6 | use cty::{ARCH_SET_FS, k_ulong}; 7 | use base::prelude::*; 8 | 9 | use super::{Private}; 10 | pub use self::var::{mem_size}; 11 | 12 | #[path = "var2.rs"] mod var; 13 | 14 | #[repr(C)] 15 | pub struct ArchPrivate { 16 | /// Points to itself. Required by the ABI. 17 | tp: *mut u8, 18 | } 19 | 20 | pub unsafe fn place_tls(mem: *mut u8) -> (*mut Private, *mut u8) { 21 | let (private, tp) = var::place_tls(mem); 22 | (*private).arch.tp = tp; 23 | (private, tp) 24 | } 25 | 26 | pub unsafe fn set_tp(tls: *mut u8) -> Result { 27 | rv!(arch_prctl(ARCH_SET_FS, tls as k_ulong)) 28 | } 29 | 30 | pub unsafe fn get_private() -> *mut Private { 31 | let addr; 32 | asm!("mov %fs:0,$0" : "=r"(addr)); 33 | var::get_private(addr) 34 | } 35 | -------------------------------------------------------------------------------- /src/lrs/sys.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! System management. 6 | 7 | pub use lrs_sys::{ 8 | StrInfo, NumInfo, get_random, get_random_non_blocking, enable_accounting, 9 | set_host_name, set_domain_name, enable_ctrl_alt_delete, halt, exec_new_kernel, 10 | power_off, restart, hibernate, 11 | }; 12 | 13 | pub use lrs_kernel::{ 14 | version, 15 | has_bpf, has_execveat, has_finit_module, has_getrandom, has_kcmp, has_kexec_file_load, 16 | has_memfd_create, has_process_vm_readv, has_process_vm_writev, has_renameat2, 17 | has_sched_getattr, has_sched_setattr, has_seccomp, has_o_tmpfile, has_seek_data, 18 | has_seek_hole, has_falloc_fl_collapse_range, has_falloc_fl_zero_range, 19 | has_tfd_ioc_set_ticks, has_epollwakeup, has_pipe_o_direct, has_map_huge_2mb, 20 | has_map_huge_1gb, has_madv_dodump, has_madv_dontdump, 21 | }; 22 | -------------------------------------------------------------------------------- /tests/core/cmp.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::{cmp}; 6 | 7 | #[test] 8 | fn min() { 9 | test!(cmp::min(0, 1) == 0); 10 | test!(cmp::min(0, 0) == 0); 11 | } 12 | 13 | #[test] 14 | fn min_ref() { 15 | test!(cmp::min_ref(&0, &1) == &0); 16 | test!(cmp::min_ref(&0, &0) == &0); 17 | } 18 | 19 | #[test] 20 | fn min_mut() { 21 | test!(cmp::min_mut(&mut 0, &mut 1) == &mut 0); 22 | test!(cmp::min_mut(&mut 0, &mut 0) == &mut 0); 23 | } 24 | 25 | #[test] 26 | fn max() { 27 | test!(cmp::max(0, 1) == 1); 28 | test!(cmp::max(0, 0) == 0); 29 | } 30 | 31 | #[test] 32 | fn max_ref() { 33 | test!(cmp::max_ref(&0, &1) == &1); 34 | test!(cmp::max_ref(&0, &0) == &0); 35 | } 36 | 37 | #[test] 38 | fn max_mut() { 39 | test!(cmp::max_mut(&mut 0, &mut 1) == &mut 1); 40 | test!(cmp::max_mut(&mut 0, &mut 0) == &mut 0); 41 | } 42 | -------------------------------------------------------------------------------- /src/core/non_zero.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use marker::{Copy, Unsize, Sized}; 6 | use ops::{CoerceUnsized}; 7 | 8 | #[lang = "non_zero"] 9 | pub struct NonZero(T); 10 | 11 | impl Copy for NonZero { } 12 | 13 | impl CoerceUnsized> for NonZero<*const T> 14 | where T: Unsize, 15 | {} 16 | 17 | impl CoerceUnsized> for NonZero<*mut T> 18 | where T: Unsize, 19 | {} 20 | 21 | impl NonZero { 22 | pub const unsafe fn new(val: T) -> NonZero { 23 | NonZero(val) 24 | } 25 | 26 | pub fn get(&self) -> T 27 | where T: Copy 28 | { 29 | self.0 30 | } 31 | 32 | pub unsafe fn set(&mut self, val: T) { 33 | self.0 = val 34 | } 35 | 36 | pub const fn into(self) -> T { 37 | self.0 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/base/conv/clone.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use prelude::*; 6 | 7 | /// Objects that can be duplicated. 8 | /// 9 | /// = Remarks 10 | /// 11 | /// Duplication always succeeds. 12 | pub trait Clone: TryClone+To { 13 | /// Clones the value. 14 | fn clone(&self) -> Self; 15 | } 16 | 17 | impl Clone for T 18 | where T: To, 19 | { 20 | fn clone(&self) -> Self { 21 | self.to() 22 | } 23 | } 24 | 25 | /// Objects that can be duplicated. 26 | /// 27 | /// = Remarks 28 | /// 29 | /// Duplication might not succeed (e.g. out of memory) in which case an error is returned. 30 | pub trait TryClone: TryTo+Sized { 31 | /// Clones the value. 32 | fn try_clone(&self) -> Result; 33 | } 34 | 35 | impl TryClone for T 36 | where T: TryTo, 37 | { 38 | fn try_clone(&self) -> Result { 39 | self.try_to() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/str_one/byte_str.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | use std::string::{ByteStr, NoNullStr}; 7 | 8 | #[test] 9 | fn trim() { 10 | let x: &ByteStr = " abc\t ".as_ref(); 11 | test!(x.trim() == "abc"); 12 | } 13 | 14 | #[test] 15 | fn starts_with() { 16 | let x: &ByteStr = "abc".as_ref(); 17 | test!(x.starts_with("ab")); 18 | test!(!x.starts_with("c")); 19 | } 20 | 21 | #[test] 22 | fn as_no_null_str() { 23 | test!(("abc".as_ref():&ByteStr).try_as_ref().unwrap():&NoNullStr == "abc"); 24 | test!((("ab\0c".as_ref():&ByteStr).try_as_ref():Result<&NoNullStr>).is_err()) 25 | } 26 | 27 | #[test] 28 | fn debug() { 29 | let mut buf = [0; 32]; 30 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 31 | write!(&mut buf, "{:?}", b"abc\xff"[..].as_ref():&ByteStr); 32 | test!(&*buf == "\"abc\\xff\""); 33 | } 34 | -------------------------------------------------------------------------------- /tests/str_one/c_str.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::string::{CStr}; 6 | use std::cty::{c_char}; 7 | 8 | #[test] 9 | fn from_ptr() { 10 | let x = b"abc\0"; 11 | let s = unsafe { CStr::from_ptr(x.as_ptr() as *const c_char) }; 12 | test!(s == "abc"); 13 | test!(s.as_ptr() as usize == x.as_ptr() as usize); 14 | test!(s.bytes_with_null() == &x[..]); 15 | test!(&s[1..] == "bc"); 16 | test!(&s[..1] == "a"); 17 | test!(&s[..] == "abc"); 18 | test!(s[1] == b'b'); 19 | } 20 | 21 | #[test] 22 | fn empty() { 23 | test!(CStr::empty() == ""); 24 | } 25 | 26 | #[test] 27 | fn as_cstr() { 28 | test!(("abc".try_as_ref():Result<&CStr>).is_err()); 29 | test!(("abc\0a".try_as_ref():Result<&CStr>).is_err()); 30 | test!(("abc\0\0".try_as_ref():Result<&CStr>).is_err()); 31 | test!("abc\0".try_as_ref().unwrap():&CStr == "abc"); 32 | } 33 | -------------------------------------------------------------------------------- /src/rt/no_libc/tls/aarch64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use super::{Private}; 6 | use base::prelude::*; 7 | 8 | pub use self::var::{mem_size}; 9 | 10 | #[path = "var1.rs"] mod var; 11 | 12 | pub const DTVR_ALIGN: usize = 8; 13 | pub const DTVR_SIZE: usize = 16; 14 | 15 | #[repr(C)] 16 | pub struct ArchPrivate { 17 | } 18 | 19 | pub unsafe fn place_tls(mem: *mut u8) -> (*mut Private, *mut u8) { 20 | var::place_tls(mem) 21 | } 22 | 23 | pub unsafe fn set_tp(tls: *mut u8) -> Result { 24 | // We don't even have to use a syscall on aarch64. The kernel will save this 25 | // register when clone(2) is called or during a context switch. 26 | asm!("msr tpidr_el0,$0" : : "r"(tls) : : "volatile"); 27 | Ok(()) 28 | } 29 | 30 | pub unsafe fn get_private() -> *mut Private { 31 | let addr; 32 | asm!("mrs $0,tpidr_el0" : "=r"(addr)); 33 | var::get_private(addr) 34 | } 35 | -------------------------------------------------------------------------------- /src/alloc/no.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use base::{error}; 7 | use {MemPool}; 8 | 9 | /// Heap without memory backing it 10 | /// 11 | /// = Remarks 12 | /// 13 | /// This allocator does not inspect the arguments passed to it and always returns that no 14 | /// memory is available. 15 | pub struct Dummy<'a>(PhantomData<&'a ()>); 16 | 17 | impl<'a> OutOf for Dummy<'a> { 18 | fn out_of(_: ()) -> Dummy<'a> { 19 | Dummy(PhantomData) 20 | } 21 | } 22 | 23 | impl<'a> MemPool for Dummy<'a> { 24 | unsafe fn alloc(&mut self, _: usize, _: usize) -> Result<*mut d8> { 25 | Err(error::NoMemory) 26 | } 27 | unsafe fn free(&mut self, _: *mut d8, _: usize, _: usize) { } 28 | unsafe fn realloc(&mut self, _: *mut d8, _: usize, _: usize, 29 | _: usize) -> Result<*mut d8> { 30 | Err(error::NoMemory) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/clone/libc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {libc}; 6 | use base::prelude::*; 7 | use base::{error}; 8 | use cty::alias::{ProcessId}; 9 | use syscall::{exit_group}; 10 | 11 | pub fn fork(f: F) -> Result 12 | where F: FnOnce() 13 | { 14 | match unsafe { libc::fork() as ProcessId } { 15 | -1 => { 16 | let error = unsafe { *libc::__errno_location() }; 17 | Err(error::Errno(error)) 18 | }, 19 | 0 => { 20 | f(); 21 | exit_group(0); 22 | }, 23 | n => Ok(n), 24 | } 25 | } 26 | 27 | pub fn fork_continue() -> Result> { 28 | match unsafe { libc::fork() as ProcessId } { 29 | -1 => { 30 | let error = unsafe { *libc::__errno_location() }; 31 | Err(error::Errno(error)) 32 | }, 33 | 0 => Ok(None), 34 | n => Ok(Some(n)), 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/lrs/inotify.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_inotify::{Inotify, InodeWatch, InodeData, InodeDataIter}; 6 | pub use lrs_inotify::flags::{WatchFlags, InotifyFlags}; 7 | pub use lrs_inotify::event::{InodeEvents}; 8 | 9 | pub mod flags { 10 | pub use lrs_inotify::flags::{ 11 | WATCH_NONE, INOTIFY_NONE, 12 | WATCH_DONT_FOLLOW_LINKS, WATCH_NO_UNLINKED, WATCH_OR_EVENTS, WATCH_ONE_SHOT, 13 | WATCH_ONLY_DIRECTORY, INOTIFY_DONT_BLOCK, INOTIFY_CLOSE_ON_EXEC, 14 | }; 15 | } 16 | 17 | pub mod events { 18 | pub use lrs_inotify::event::{ 19 | INEV_ALL, INEV_CLOSE, INEV_MOVE, 20 | INEV_NONE, INEV_ACCESS, INEV_MODIFY, INEV_ATTRIB, INEV_CLOSE_WRITE, 21 | INEV_CLOSE_READ, INEV_OPEN, INEV_MOVED_FROM, INEV_MOVED_TO, INEV_CREATE, 22 | INEV_DELETE, INEV_DELETE_SELF, INEV_MOVE_SELF, INEV_UNMOUNT, INEV_OVERFLOW, 23 | INEV_IGNORED, INEV_DIR, 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /src/rand/devrandom.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Rng}; 7 | use io::{Read}; 8 | use file::{File}; 9 | 10 | pub struct DevRandom(File); 11 | 12 | impl DevRandom { 13 | pub fn new() -> Result { 14 | Ok(DevRandom(try!(File::open_read("/dev/random\0")))) 15 | } 16 | } 17 | 18 | impl Rng for DevRandom { } 19 | 20 | impl Read for DevRandom { 21 | fn scatter_read(&mut self, buf: &mut [&mut [d8]]) -> Result { 22 | self.0.scatter_read(buf) 23 | } 24 | } 25 | 26 | pub struct DevUrandom(File); 27 | 28 | impl DevUrandom { 29 | pub fn new() -> Result { 30 | Ok(DevUrandom(try!(File::open_read("/dev/urandom\0")))) 31 | } 32 | } 33 | 34 | impl Rng for DevUrandom { } 35 | 36 | impl Read for DevUrandom { 37 | fn scatter_read(&mut self, buf: &mut [&mut [d8]]) -> Result { 38 | self.0.scatter_read(buf) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/rmo/impls/slice.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use vec::{Vec}; 7 | use {ToOwned}; 8 | use alloc::{MemPool}; 9 | use str_two::{String}; 10 | 11 | impl ToOwned for [T] 12 | where T: Copy, 13 | H: MemPool, 14 | { 15 | type Owned = Vec; 16 | fn to_owned_with_pool(&self, pool: H) -> Result> { 17 | let mut vec = Vec::with_pool(pool); 18 | try!(vec.reserve(self.len())); 19 | vec.push_all(self); 20 | Ok(vec) 21 | } 22 | } 23 | 24 | impl ToOwned for str 25 | where H: MemPool, 26 | { 27 | type Owned = String; 28 | fn to_owned_with_pool(&self, pool: H) -> Result> { 29 | let mut vec = Vec::with_pool(pool); 30 | try!(vec.reserve(self.len())); 31 | vec.push_all(self.as_bytes()); 32 | unsafe { 33 | Ok(String::from_bytes_unchecked(vec)) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/tree/test.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {Node}; 6 | 7 | /// Tests that the node has various properties: 8 | /// 9 | /// * If the node is red, the left child is not red. 10 | /// * The right child is not red. 11 | /// * The number of black left children equals the number of black right children. 12 | /// 13 | /// Returns the number of black children including itself. 14 | pub fn test(node: &Node) -> usize { 15 | let is_red = node.is_red.get(); 16 | 17 | let left_depth = if let Some(left) = node.left() { 18 | if is_red { 19 | assert!(!left.is_red.get()); 20 | } 21 | test(left) 22 | } else { 23 | 0 24 | }; 25 | 26 | let right_depth = if let Some(right) = node.right() { 27 | assert!(!right.is_red.get()); 28 | test(right) 29 | } else { 30 | 0 31 | }; 32 | 33 | assert!(left_depth == right_depth); 34 | left_depth + (!is_red as usize) 35 | } 36 | -------------------------------------------------------------------------------- /src/hash/impls/ptr.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Hash, Hasher}; 7 | 8 | macro_rules! impl_ptr { 9 | ($t:ty) => { 10 | impl Hash for $t { 11 | fn stateful_hash(&self, h: &mut H) { 12 | h.write_usize(*self as usize) 13 | } 14 | 15 | fn stateful_hash_slice(val: &[Self], h: &mut H) { 16 | h.write_bytes(val.as_ref()); 17 | } 18 | 19 | fn hash>(&self, seed: S) -> H::Digest { 20 | H::hash_usize(*self as usize, seed) 21 | } 22 | 23 | fn hash_slice>(val: &[Self], 24 | seed: S) -> H::Digest { 25 | H::hash_bytes(val.as_ref(), seed) 26 | } 27 | } 28 | } 29 | } 30 | 31 | impl_ptr!(*const T); 32 | impl_ptr!(*mut T); 33 | -------------------------------------------------------------------------------- /src/fmt/impls/result.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use {Write, LowerHex, UpperHex, Debug, Display}; 7 | 8 | macro_rules! imp { 9 | ($ty:ident) => { 10 | impl $ty for Result { 11 | fn fmt(&self, w: &mut W) -> Result { 12 | match *self { 13 | Ok(ref t) => { 14 | try!(w.write_all(b"Ok(").ignore_ok()); 15 | try!(t.fmt(w)); 16 | w.write_all(b")").ignore_ok() 17 | }, 18 | Err(ref e) => { 19 | try!(w.write_all(b"Err(").ignore_ok()); 20 | try!(e.fmt(w)); 21 | w.write_all(b")").ignore_ok() 22 | }, 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | imp!(LowerHex); 30 | imp!(UpperHex); 31 | imp!(Debug); 32 | imp!(Display); 33 | -------------------------------------------------------------------------------- /tests/base/result.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn unwrap() { 7 | test!(Ok::<_, ()>(1).unwrap() == 1); 8 | } 9 | 10 | #[test] 11 | #[should_panic] 12 | fn unwrap_err() { 13 | Err::<(), _>(()).unwrap(); 14 | } 15 | 16 | #[test] 17 | fn map() { 18 | test!(Ok::<_, ()>(0).map(|x| x+1) == Ok(1)); 19 | test!(Err::<(), _>(()).map(|_| abort!()) == Err(())); 20 | } 21 | 22 | #[test] 23 | fn chain() { 24 | test!(Ok::<_, ()>(0).chain(|x| Ok(x+1)) == Ok(1)); 25 | test!(Err::<(), _>(()).chain::<(), _>(|_| abort!()) == Err(())); 26 | } 27 | 28 | #[test] 29 | fn is_ok() { 30 | test!(Ok::<_, ()>(0).is_ok()); 31 | test!(!Err::<(), _>(()).is_ok()); 32 | } 33 | 34 | #[test] 35 | fn is_err() { 36 | test!(!Ok::<_, ()>(0).is_err()); 37 | test!(Err::<(), _>(()).is_err()); 38 | } 39 | 40 | #[test] 41 | fn ignore_ok() { 42 | test!(Ok::<_, ()>(0).ignore_ok() == Ok(())); 43 | test!(Err::<(), _>(0).ignore_ok() == Err(0)); 44 | } 45 | -------------------------------------------------------------------------------- /tests/core/char.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn len() { 7 | test!('a'.len() == 1); 8 | test!('ä'.len() == 2); 9 | test!('ᄌ'.len() == 3); 10 | } 11 | 12 | #[test] 13 | fn to_utf8() { 14 | fn inner(c: char, s: &str) { 15 | let bytes = c.to_utf8(); 16 | let len = c.len(); 17 | test!(&bytes[..len] == s); 18 | } 19 | inner('a', "a"); 20 | inner('ä', "ä"); 21 | inner('ᄌ', "ᄌ"); 22 | } 23 | 24 | #[test] 25 | fn from_u32() { 26 | test!(char::from_u32('a' as u32) == Some('a')); 27 | test!(char::from_u32('ä' as u32) == Some('ä')); 28 | test!(char::from_u32(0x110000) == None); 29 | test!(char::from_u32(0xd800) == None); 30 | } 31 | 32 | #[test] 33 | fn max() { 34 | test!(char::max() == '\u{10ffff}'); 35 | } 36 | 37 | #[test] 38 | fn eq() { 39 | test!('a' == 'a'); 40 | test!('a' != 'b'); 41 | } 42 | 43 | #[test] 44 | fn ord() { 45 | test!('a' < 'b'); 46 | test!('a' < 'ä'); 47 | } 48 | -------------------------------------------------------------------------------- /src/rt/no_libc/crt.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty_base::types::{c_char, c_int}; 6 | use syscall::{self}; 7 | use core::{mem}; 8 | 9 | #[cfg(no_libc)] 10 | #[link(name = "lrs_crt")] 11 | extern { } 12 | 13 | 14 | #[no_mangle] 15 | pub unsafe extern fn lrs_start_main(stack: *const usize) { 16 | extern { 17 | fn main(argc: c_int, argv: *const *const c_char); 18 | #[linkage = "extern_weak"] static __init_array_start: *const usize; 19 | #[linkage = "extern_weak"] static __init_array_end: *const usize; 20 | } 21 | 22 | let mut init_fn = __init_array_start; 23 | while init_fn != __init_array_end { 24 | if *init_fn != 0 && *init_fn != !0 { 25 | let f: extern fn() = mem::cast(*init_fn); 26 | f(); 27 | } 28 | init_fn = init_fn.add(1); 29 | } 30 | 31 | let argc = *stack; 32 | let argv = stack.add(1); 33 | main(argc as c_int, argv as *const _); 34 | 35 | syscall::exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /src/tlalc/p.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use core::ptr::{AliasMutObjPtr}; 7 | use core::{mem}; 8 | 9 | /// An aliasing raw pointer wrapper. 10 | pub struct P(AliasMutObjPtr); 11 | 12 | impl Copy for P { } 13 | 14 | impl P { 15 | /// Creates a new `P`. 16 | /// 17 | /// [argument, ptr] 18 | /// The pointer that will be wrapped. Must be a valid pointer. 19 | pub const unsafe fn new(ptr: *const T) -> P { 20 | P(AliasMutObjPtr::new(ptr as *mut T)) 21 | } 22 | 23 | pub fn ptr(self) -> *mut T { 24 | unsafe { mem::cast(self) } 25 | } 26 | 27 | pub fn to_opt(self) -> Option> { 28 | unsafe { mem::cast(self) } 29 | } 30 | } 31 | 32 | impl Deref for P { 33 | type Target = T; 34 | fn deref(&self) -> &T { 35 | &self.0 36 | } 37 | } 38 | 39 | impl DerefMut for P { 40 | fn deref_mut(&mut self) -> &mut T { 41 | &mut self.0 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/thread/no_libc/arm.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int, c_long}; 6 | use atomic::{AtomicCInt}; 7 | 8 | pub unsafe fn start_thread(func: unsafe extern fn(*mut u8) -> !, arg: *mut u8, 9 | flags: c_int, stack: *mut u8, ctid: &AtomicCInt, 10 | tp: *mut u8) -> c_long { 11 | extern { 12 | fn __start_thread(flags: c_int, stack: *mut u8, ptid: *mut c_int, tp: *mut u8, 13 | ctid: *mut c_int, func: unsafe extern fn(*mut u8) -> !, 14 | arg: *mut u8) -> c_long; 15 | } 16 | __start_thread(flags, stack, 0 as *mut _, tp, ctid.as_ptr(), func, arg) 17 | } 18 | 19 | pub unsafe fn stop_thread(stack_base: *mut u8, stack_size: usize, 20 | tmp_stack: *mut u8) -> ! { 21 | extern { 22 | fn __stop_thread(stack_base: *mut u8, stack_size: usize, tmp_stack: *mut u8) -> !; 23 | } 24 | __stop_thread(stack_base, stack_size, tmp_stack) 25 | } 26 | -------------------------------------------------------------------------------- /src/fmt/impls/float.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use io::{Write}; 7 | use {Debug, Display}; 8 | 9 | impl Debug for f32 { 10 | fn fmt(&self, w: &mut W) -> Result { 11 | Debug::fmt(&(*self as f64), w) 12 | } 13 | } 14 | 15 | impl Display for f32 { 16 | fn fmt(&self, w: &mut W) -> Result { 17 | Debug::fmt(self, w) 18 | } 19 | } 20 | 21 | impl Display for f64 { 22 | fn fmt(&self, w: &mut W) -> Result { 23 | Debug::fmt(self, w) 24 | } 25 | } 26 | 27 | impl Debug for f64 { 28 | fn fmt(&self, w: &mut W) -> Result { 29 | let mut val = *self; 30 | if val < 0.0 { 31 | try!(w.write_all(b"-")); 32 | val = val.abs(); 33 | } 34 | try!(Debug::fmt(&(val as u64), w)); 35 | try!(w.write_all(b".")); 36 | val -= val as u64 as f64; 37 | val *= 1_000_000_000_000.0; 38 | Debug::fmt(&(val as u64), w) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/thread/no_libc/x86_64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int, c_long}; 6 | use atomic::{AtomicCInt}; 7 | 8 | pub unsafe fn start_thread(func: unsafe extern fn(*mut u8) -> !, arg: *mut u8, 9 | flags: c_int, stack: *mut u8, ctid: &AtomicCInt, 10 | tp: *mut u8) -> c_long { 11 | extern { 12 | fn __start_thread(flags: c_int, stack: *mut u8, ptid: *mut c_int, arg: *mut u8, 13 | tp: *mut u8, func: unsafe extern fn(*mut u8) -> !, 14 | ctid: *mut c_int) -> c_long; 15 | } 16 | __start_thread(flags, stack, 0 as *mut _, arg, tp, func, ctid.as_ptr()) 17 | } 18 | 19 | pub unsafe fn stop_thread(stack_base: *mut u8, stack_size: usize, 20 | tmp_stack: *mut u8) -> ! { 21 | extern { 22 | fn __stop_thread(stack_base: *mut u8, stack_size: usize, tmp_stack: *mut u8) -> !; 23 | } 24 | __stop_thread(stack_base, stack_size, tmp_stack) 25 | } 26 | -------------------------------------------------------------------------------- /src/rv/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_rv"] 6 | #![crate_type = "lib"] 7 | #![no_std] 8 | 9 | extern crate lrs_base as base; 10 | extern crate lrs_int as int; 11 | 12 | use base::prelude::*; 13 | 14 | use int::{SignedInt, Int}; 15 | use base::error::{Errno, c_int}; 16 | 17 | #[cfg(retry)] 18 | pub fn retry T>(mut f: F) -> Result { 19 | use base::{error}; 20 | 21 | loop { 22 | let ret = f(); 23 | if ret.negative() { 24 | let err = Errno(-ret.cast_i64() as c_int); 25 | if err != error::Interrupted { 26 | return Err(err); 27 | } 28 | } else { 29 | return Ok(ret); 30 | } 31 | } 32 | } 33 | 34 | #[cfg(not(retry))] 35 | pub fn retry T>(mut f: F) -> Result { 36 | let ret = f(); 37 | if ret.negative() { 38 | Err(Errno(-ret.cast_i64() as c_int)) 39 | } else { 40 | Ok(ret) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/thread/no_libc/aarch64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int, c_long}; 6 | use atomic::{AtomicCInt}; 7 | 8 | pub unsafe fn start_thread(func: unsafe extern fn(*mut u8) -> !, arg: *mut u8, 9 | flags: c_int, stack: *mut u8, ctid: &AtomicCInt, 10 | tp: *mut u8) -> c_long { 11 | extern { 12 | fn __start_thread(flags: i64, stack: *mut u8, ptid: *mut c_int, tp: *mut u8, 13 | ctid: *mut c_int, func: unsafe extern fn(*mut u8) -> !, 14 | arg: *mut u8) -> c_long; 15 | } 16 | __start_thread(flags as i64, stack, 0 as *mut _, tp, ctid.as_ptr(), func, arg) 17 | } 18 | 19 | pub unsafe fn stop_thread(stack_base: *mut u8, stack_size: usize, 20 | tmp_stack: *mut u8) -> ! { 21 | extern { 22 | fn __stop_thread(stack_base: *mut u8, stack_size: usize, tmp_stack: *mut u8) -> !; 23 | } 24 | __stop_thread(stack_base, stack_size, tmp_stack) 25 | } 26 | -------------------------------------------------------------------------------- /tests/signal/sigset.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::signal::{Sigset}; 6 | use std::util::{all_bytes}; 7 | use std::signal::signals::{Window, Interrupted}; 8 | 9 | #[test] 10 | fn test() { 11 | let mut set = Sigset::new(); 12 | unsafe { test!(all_bytes((set.as_ref():&[d8]).as_bytes(), 0)); } 13 | set.fill(); 14 | unsafe { test!(all_bytes((set.as_ref():&[d8]).as_bytes(), !0)); } 15 | set.clear(); 16 | set.set(Window).unwrap(); 17 | test!(set.is_set(Window).unwrap()); 18 | set.set(Interrupted).unwrap(); 19 | 20 | let mut set2 = Sigset::new(); 21 | set2.set_all(set); 22 | test!(set2.all_set(set)); 23 | test!(set2.is_set(Window).unwrap()); 24 | test!(set2.is_set(Interrupted).unwrap()); 25 | 26 | test!(!set2.disjoint(set)); 27 | set.unset(Window); 28 | set2.unset(Interrupted); 29 | test!(set2.disjoint(set)); 30 | 31 | set2.set(Interrupted); 32 | set2.unset_all(set); 33 | test!(!set2.is_set(Interrupted).unwrap()); 34 | } 35 | -------------------------------------------------------------------------------- /src/fmt/impls/range.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::ops::{Range, RangeTo, RangeFrom, RangeFull}; 6 | use base::result::{Result}; 7 | use {Debug, Write}; 8 | 9 | impl Debug for Range 10 | where T: Debug, 11 | { 12 | fn fmt(&self, mut w: &mut W) -> Result { 13 | try!(self.start.fmt(w)); 14 | try!(w.write_all(b"..")); 15 | self.end.fmt(w) 16 | } 17 | } 18 | 19 | impl Debug for RangeTo 20 | where T: Debug, 21 | { 22 | fn fmt(&self, mut w: &mut W) -> Result { 23 | try!(w.write_all(b"..")); 24 | self.end.fmt(w) 25 | } 26 | } 27 | 28 | impl Debug for RangeFrom 29 | where T: Debug, 30 | { 31 | fn fmt(&self, mut w: &mut W) -> Result { 32 | try!(self.start.fmt(w)); 33 | w.write_all(b"..").ignore_ok() 34 | } 35 | } 36 | 37 | impl Debug for RangeFull { 38 | fn fmt(&self, mut w: &mut W) -> Result { 39 | w.write_all(b"..").ignore_ok() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /asm/i686-unknown-linux-gnu/src/start_thread.s: -------------------------------------------------------------------------------- 1 | # function prototype: 2 | # 3 | # extern fn(flags, stack, ptid, arg, ptp, func, ctid) -> c_long 4 | # 5 | # 8(%ebp) = flags 6 | # 12(%ebp) = stack 7 | # 16(%ebp) = ptid 8 | # 20(%ebp) = arg 9 | # 24(%ebp) = ptp 10 | # 28(%ebp) = func 11 | # 32(%ebp) = ctid 12 | 13 | .global __start_thread 14 | .type __start_thread,@function 15 | __start_thread: 16 | push %ebp 17 | mov %esp,%ebp 18 | push %ebx 19 | push %esi 20 | push %edi 21 | 22 | mov 12(%ebp),%ecx # %ecx = stack 23 | sub $16,%ecx # %ecx = stack - 16 24 | mov 20(%ebp),%edi # %edi = arg 25 | mov %edi,(%ecx) # top value on stack = arg 26 | 27 | mov $120,%eax # __NR_clone 28 | mov 8(%ebp),%ebx # %ebx = flags 29 | mov 16(%ebp),%edx # %edx = ptid 30 | mov 24(%ebp),%esi # %esi = ptp 31 | mov 32(%ebp),%edi # %edi = ctid 32 | mov 28(%ebp),%ebp # %ebp = func 33 | int $0x80 34 | 35 | test %eax,%eax 36 | jnz 1f # parent 37 | 38 | mov %ebp,%eax # %eax = func 39 | xor %ebp,%ebp 40 | call *%eax # does not return 41 | 42 | 1: pop %edi 43 | pop %esi 44 | pop %ebx 45 | pop %ebp 46 | ret 47 | -------------------------------------------------------------------------------- /src/core/repr.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use marker::{Copy}; 6 | use mem::{self}; 7 | 8 | /// The representation of `&[T]` or `&mut [T]`. 9 | #[repr(C)] 10 | pub struct Slice { 11 | /// The pointer to the first element of the slice. 12 | pub ptr: *const T, 13 | /// The number of elements in the slice. 14 | pub len: usize, 15 | } 16 | 17 | impl Copy for Slice {} 18 | 19 | /// The representation of `&Trait`. 20 | #[repr(C)] 21 | pub struct TraitObject { 22 | /// The pointer to the data in the slice. 23 | pub data: *mut u8, 24 | /// The pointer to the vtable of the slice. 25 | pub vtable: *mut u8, 26 | } 27 | 28 | /// Objects that have an alternative representation. 29 | pub trait Repr { 30 | /// Returns the alternative representation fo the object. 31 | fn repr(&self) -> T; 32 | } 33 | 34 | impl Repr> for [T] { 35 | fn repr(&self) -> Slice { unsafe { mem::copy_as(&self) } } 36 | } 37 | 38 | impl Repr> for str { 39 | fn repr(&self) -> Slice { unsafe { mem::copy_as(&self) } } 40 | } 41 | -------------------------------------------------------------------------------- /tests/alloc/ta.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{TaPool, MemPool}; 6 | 7 | #[test] 8 | fn alloc() { 9 | let mut buf = &mut [d8::new(0); 5][..]; 10 | let addr = buf.as_ptr() as usize; 11 | unsafe { 12 | let mut pool1 = TaPool::new(&mut buf); 13 | let mut pool2 = pool1; 14 | 15 | let a1 = pool1.alloc(1, 1).unwrap(); 16 | test!(a1 as usize == addr); 17 | 18 | let a2 = pool2.alloc(2, 1).unwrap(); 19 | test!(a2 as usize == addr + 1); 20 | 21 | let a3 = pool1.alloc(2, 1).unwrap(); 22 | test!(a3 as usize == addr + 3); 23 | } 24 | test!(buf.as_ptr() as usize == addr + 5); 25 | } 26 | 27 | #[test] 28 | fn realloc() { 29 | let mut buf = &mut [d8::new(0); 5][..]; 30 | unsafe { 31 | let mut pool = TaPool::new(&mut buf); 32 | let alloc = pool.alloc(1, 1).unwrap() as *mut u8; 33 | *alloc = 1; 34 | let realloc = pool.realloc(alloc as *mut d8, 1, 2, 1).unwrap() as *mut u8; 35 | test!(*realloc == 1); 36 | } 37 | test!(buf.len() == 3); 38 | } 39 | -------------------------------------------------------------------------------- /src/clone/no_libc/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use base::{error}; 7 | use {r_syscall, cty}; 8 | use cty::alias::{ProcessId}; 9 | use syscall::{exit_group}; 10 | 11 | pub fn fork(f: F) -> Result 12 | where F: FnOnce() 13 | { 14 | let rv = unsafe { 15 | r_syscall::clone(cty::SIGCHLD as cty::k_ulong, 0 as *mut _, 0 as *mut _, 16 | 0 as *mut _, 0 as *mut _) 17 | }; 18 | match rv { 19 | e if e < 0 => Err(error::Errno(-e as cty::c_int)), 20 | 0 => { 21 | f(); 22 | exit_group(0); 23 | }, 24 | n => Ok(n as ProcessId), 25 | } 26 | } 27 | 28 | pub fn fork_continue() -> Result> { 29 | let rv = unsafe { 30 | r_syscall::clone(cty::SIGCHLD as cty::k_ulong, 0 as *mut _, 0 as *mut _, 31 | 0 as *mut _, 0 as *mut _) 32 | }; 33 | match rv { 34 | e if e < 0 => Err(error::Errno(-e as cty::c_int)), 35 | 0 => Ok(None), 36 | n => Ok(Some(n as ProcessId)), 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/core_plugin/lrs_ext/mod.rs: -------------------------------------------------------------------------------- 1 | pub use self::to::{ 2 | derive_to, derive_try_to, derive_to_for_copy, derive_copy_to_for, 3 | }; 4 | pub use self::eq::{derive_eq}; 5 | pub use self::copy::{derive_copy, derive_copy_and_to, derive_pod_copy_and_to}; 6 | pub use self::format::{expand_format_args}; 7 | pub use self::debug::{derive_debug}; 8 | 9 | macro_rules! pathvec { 10 | ($($x:ident)::+) => ( 11 | vec![ $( stringify!($x) ),+ ] 12 | ) 13 | } 14 | 15 | macro_rules! path { 16 | ($($x:tt)*) => ( 17 | ::syntax_ext::deriving::generic::ty::Path::new( pathvec!( $($x)* ) ) 18 | ) 19 | } 20 | 21 | macro_rules! path_local { 22 | ($x:ident) => ( 23 | ::syntax_ext::deriving::generic::ty::Path::new_local(stringify!($x)) 24 | ) 25 | } 26 | 27 | macro_rules! pathvec_std { 28 | ($cx:expr, $first:ident :: $($rest:ident)::+) => ({ 29 | let mut v = pathvec!($($rest)::+); 30 | if let Some(s) = $cx.crate_root { 31 | v.insert(0, s); 32 | } 33 | v 34 | }) 35 | } 36 | 37 | macro_rules! path_std { 38 | ($($x:tt)*) => ( 39 | ::syntax_ext::deriving::generic::ty::Path::new( pathvec_std!( $($x)* ) ) 40 | ) 41 | } 42 | 43 | mod to; 44 | mod eq; 45 | mod copy; 46 | mod format; 47 | mod debug; 48 | -------------------------------------------------------------------------------- /src/lrs/mem.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Memory operations. 6 | 7 | pub use lrs_core::mem::{ 8 | uninit, cast, zeroed, copy_as, forget, unsafe_forget, drop, copy, unsafe_copy, 9 | swap, replace, size_of, align_of, needs_drop, align_for, is_suitable_for, from_bytes, 10 | from_mut_bytes, align_for_mut, addr, as_slice, as_mut_slice, unsafe_zeroed, 11 | as_data, as_mut_data, discriminant_value, 12 | }; 13 | 14 | #[cfg(not(freestanding))] 15 | pub use lrs_mem::{ 16 | advise, protect, lock, unlock, lock_all, unlock_all, Availability, availability, 17 | }; 18 | 19 | #[cfg(not(freestanding))] 20 | pub use lrs_mem::flags::{MemLockFlags}; 21 | 22 | #[cfg(not(freestanding))] 23 | pub mod advice { 24 | pub use lrs_mem::adv::{ 25 | Normal, Random, Sequential, WillNeed, DontNeed, Remove, DontFork, DoFork, 26 | HwPoison, SoftOffline, Mergeable, Unmergeable, HugePage, NoHugePage, DontDump, 27 | DoDump, 28 | }; 29 | } 30 | 31 | #[cfg(not(freestanding))] 32 | pub mod flags { 33 | pub use lrs_mem::flags::{ 34 | MLOCK_CURRENT, MLOCK_FUTURE, 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /tests/signal/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::signal::{self, Sigset}; 6 | use std::signal::signals::{Window, Interrupted}; 7 | 8 | mod sigset; 9 | 10 | #[test] 11 | fn block_signal() { 12 | let mut set = Sigset::new(); 13 | set.set(Window); 14 | 15 | let mut set2 = set; 16 | set2.set(Interrupted); 17 | 18 | test!(signal::block_signal(Window).unwrap() == Sigset::new()); 19 | test!(signal::blocked_signals().unwrap() == set); 20 | test!(signal::unblock_signal(Window).unwrap() == set); 21 | test!(signal::block_signals(set).unwrap() == Sigset::new()); 22 | test!(signal::blocked_signals().unwrap() == set); 23 | test!(signal::unblock_signals(set).unwrap() == set); 24 | test!(signal::blocked_signals().unwrap() == Sigset::new()); 25 | 26 | test!(signal::block_signal(Window).unwrap() == Sigset::new()); 27 | test!(signal::set_blocked_signals(set2).unwrap() == set); 28 | test!(signal::blocked_signals().unwrap() == set2); 29 | 30 | test!(signal::unblock_signal(Interrupted).unwrap() == set2); 31 | test!(signal::blocked_signals().unwrap() == set); 32 | } 33 | -------------------------------------------------------------------------------- /src/thread/no_libc/x86.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int, c_long}; 6 | use atomic::{AtomicCInt}; 7 | use rt::imp::{tls}; 8 | 9 | pub unsafe fn start_thread(func: unsafe extern fn(*mut u8) -> !, arg: *mut u8, 10 | flags: c_int, stack: *mut u8, ctid: &AtomicCInt, 11 | tp: *mut u8) -> c_long { 12 | extern { 13 | fn __start_thread(flags: c_int, stack: *mut u8, ptid: *mut c_int, arg: *mut u8, 14 | ptp: *mut i32, func: unsafe extern fn(*mut u8) -> !, 15 | ctid: *mut c_int) -> c_long; 16 | } 17 | let mut user_desc = tls::arch::magic_array(tp); 18 | __start_thread(flags, stack, 0 as *mut _, arg, user_desc.as_mut_ptr(), func, 19 | ctid.as_ptr()) 20 | } 21 | 22 | pub unsafe fn stop_thread(stack_base: *mut u8, stack_size: usize, 23 | tmp_stack: *mut u8) -> ! { 24 | extern { 25 | fn __stop_thread(stack_base: *mut u8, stack_size: usize, tmp_stack: *mut u8) -> !; 26 | } 27 | __stop_thread(stack_base, stack_size, tmp_stack) 28 | } 29 | -------------------------------------------------------------------------------- /src/netlink/kind.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use cty::{ 7 | NLMSG_NOOP, NLMSG_ERROR, NLMSG_DONE, 8 | }; 9 | use fmt_::{Debug, Write}; 10 | 11 | /// A Netlink message type. 12 | /// 13 | /// [field, 1] 14 | /// The integer constant associated with the type. 15 | /// 16 | /// = Remarks 17 | /// 18 | /// :kinds: link:lrs::netlink::kind 19 | /// 20 | /// See {kinds} for pre-defined constants. 21 | /// 22 | /// = See also 23 | /// 24 | /// * {kinds} 25 | #[repr(C)] 26 | #[derive(Pod, Eq)] 27 | pub struct Kind(pub u16); 28 | 29 | impl Debug for Kind { 30 | fn fmt(&self, mut w: &mut W) -> Result { 31 | match *self { 32 | NoOp => w.write_all(b"NoOp").ignore_ok(), 33 | ErrorAck => w.write_all(b"ErrorAck").ignore_ok(), 34 | Done => w.write_all(b"Done").ignore_ok(), 35 | _ => write!(w, "{}", self.0), 36 | } 37 | } 38 | } 39 | 40 | pub const NoOp : Kind = Kind(NLMSG_NOOP); 41 | pub const ErrorAck : Kind = Kind(NLMSG_ERROR); 42 | pub const Done : Kind = Kind(NLMSG_DONE); 43 | -------------------------------------------------------------------------------- /tests/fmt/str.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | #[test] 8 | fn debug_char() { 9 | let mut buf = [0; 30]; 10 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 11 | write!(&mut buf, "{:?}", 'a'); 12 | write!(&mut buf, "{:?}", 'ä'); 13 | write!(&mut buf, "{:?}", '日'); 14 | test!(&*buf == "'a''\\u{e4}''\\u{65e5}'"); 15 | } 16 | 17 | #[test] 18 | fn display_char() { 19 | let mut buf = [0; 10]; 20 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 21 | write!(&mut buf, "{}", 'a'); 22 | write!(&mut buf, "{}", 'ä'); 23 | write!(&mut buf, "{}", '日'); 24 | test!(&*buf == "aä日"); 25 | } 26 | 27 | #[test] 28 | fn debug_str() { 29 | let mut buf = [0; 30]; 30 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 31 | write!(&mut buf, "{:?}", "aä日"); 32 | test!(&*buf == "\"a\\u{e4}\\u{65e5}\""); 33 | } 34 | 35 | #[test] 36 | fn display_str() { 37 | let mut buf = [0; 30]; 38 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 39 | write!(&mut buf, "{}", "aä日"); 40 | test!(&*buf == "aä日"); 41 | } 42 | -------------------------------------------------------------------------------- /assets/doc_style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 14px; 3 | max-width: 800px; 4 | margin-left: auto; 5 | margin-right: auto; 6 | padding-left: 10px; 7 | padding-right: 10px; 8 | background-color: #fafafa; 9 | } 10 | 11 | a { 12 | text-decoration: none; 13 | color: #229; 14 | font-weight: bold; 15 | } 16 | 17 | table, th, td { 18 | border: 2px solid #BBB; 19 | border-collapse: collapse; 20 | } 21 | 22 | table { 23 | font-size: inherit; 24 | } 25 | 26 | th, td { 27 | padding: 10px 7px; 28 | vertical-align: middle; 29 | } 30 | 31 | body > h1:first-child { 32 | margin-top: 0em; 33 | } 34 | 35 | td > p:first-child { 36 | margin-top: 0em; 37 | } 38 | 39 | td > p:last-child { 40 | margin-bottom: 0em; 41 | } 42 | 43 | th { 44 | background-color: #EEE; 45 | color: #333; 46 | text-align: left; 47 | } 48 | 49 | pre { 50 | border: 1px solid #BBB; 51 | padding: 7px 10px; 52 | background-color: #F8F8F8; 53 | overflow: auto; 54 | display: inline-block; 55 | margin: 0px; 56 | } 57 | 58 | code { 59 | color: #700; 60 | } 61 | 62 | .no_break { 63 | White-space: nowrap; 64 | } 65 | 66 | .info_head { 67 | font-size: 12px; 68 | font-weight: bold; 69 | } 70 | 71 | .informative { 72 | padding: 5pt; 73 | border: 2px solid #BBB; 74 | } 75 | -------------------------------------------------------------------------------- /src/alloc/tl.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use base::{error}; 7 | use {MemPool}; 8 | use lock::{SingleThreadMutex}; 9 | use tlalc::{Cache}; 10 | 11 | /// The tlalc allocator 12 | #[derive(Copy)] 13 | pub struct TlAlc; 14 | 15 | impl !Send for TlAlc { } 16 | 17 | impl OutOf for TlAlc { 18 | fn out_of(_: ()) -> TlAlc { 19 | TlAlc 20 | } 21 | } 22 | 23 | thread_local! { 24 | static CACHE: SingleThreadMutex = unsafe { 25 | SingleThreadMutex::new(Cache::new()) 26 | }; 27 | } 28 | 29 | impl MemPool for TlAlc { 30 | unsafe fn alloc(&mut self, size: usize, _: usize) -> Result<*mut d8> { 31 | if let Some(mut c) = CACHE.try_lock() { 32 | c.alloc(size) 33 | } else { 34 | Err(error::ResourceBusy) 35 | } 36 | } 37 | 38 | unsafe fn free(&mut self, ptr: *mut d8, size: usize, _: usize) { 39 | CACHE.lock().free(ptr, size) 40 | } 41 | 42 | unsafe fn realloc(&mut self, old_ptr: *mut d8, oldsize: usize, newsize: usize, 43 | _: usize) -> Result<*mut d8> { 44 | CACHE.lock().realloc(old_ptr, oldsize, newsize) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/rt/no_libc/tls/arm.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::{mem}; 6 | use r_syscall::arch::{set_tls}; 7 | use base::prelude::*; 8 | use super::{Private}; 9 | 10 | pub use self::var::{mem_size}; 11 | 12 | #[path = "var1.rs"] mod var; 13 | 14 | pub const DTVR_ALIGN: usize = 4; 15 | pub const DTVR_SIZE: usize = 8; 16 | 17 | #[repr(C)] 18 | pub struct ArchPrivate { 19 | } 20 | 21 | pub unsafe fn place_tls(mem: *mut u8) -> (*mut Private, *mut u8) { 22 | var::place_tls(mem) 23 | } 24 | 25 | pub unsafe fn set_tp(tls: *mut u8) -> Result { 26 | // TODO: should only check this once at startup. 27 | let kuser_helper_version = *(0xffff0ffc as *const i32); 28 | assert!(kuser_helper_version > 0); 29 | 30 | rv!(set_tls(tls)) 31 | } 32 | 33 | pub unsafe fn get_tp() -> *mut u8 { 34 | __aeabi_read_tp() 35 | } 36 | 37 | #[no_mangle] 38 | pub unsafe extern fn __aeabi_read_tp() -> *mut u8 { 39 | // Documentation/arm/kernel_user_helpers.txt in the linux source tree. 40 | let kuser_get_tls = mem::cast:: *mut u8>(0xffff0fe0); 41 | kuser_get_tls() 42 | } 43 | 44 | pub unsafe fn get_private() -> *mut Private { 45 | var::get_private(get_tp()) 46 | } 47 | -------------------------------------------------------------------------------- /src/tree/debug.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {get_owner, Node, Entree}; 6 | use base::prelude::*; 7 | use fmt::{Write, Debug}; 8 | 9 | pub fn debug(mut w: &mut W, node: &Node) -> Result 10 | where E::Owner: Debug, 11 | { 12 | try!(write!(w, "digraph tree {{\n")); 13 | let mut n = 0; 14 | try!(debug_::(w, node, &mut n)); 15 | write!(w, "}}\n") 16 | } 17 | 18 | fn debug_(mut w: &mut W, node: &Node, id: &mut usize) -> Result 19 | where E::Owner: Debug, 20 | { 21 | let owner = get_owner::(node); 22 | try!(write!(w, "n{} [label=\"{:?}\"", *id, owner)); 23 | 24 | if node.is_red.get() { 25 | try!(write!(w, ", style=filled, fillcolor=red")); 26 | } 27 | try!(write!(w, "];\n")); 28 | 29 | let my_id = *id; 30 | 31 | if let Some(left) = node.left() { 32 | *id += 1; 33 | try!(write!(w, "n{} -> n{};\n", my_id, *id)); 34 | try!(debug_::(w, left, id)); 35 | } 36 | 37 | if let Some(right) = node.right() { 38 | *id += 1; 39 | try!(write!(w, "n{} -> n{};\n", my_id, *id)); 40 | try!(debug_::(w, right, id)); 41 | } 42 | 43 | Ok(()) 44 | } 45 | -------------------------------------------------------------------------------- /src/socket/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_socket"] 6 | #![crate_type = "lib"] 7 | #![feature(custom_derive, associated_consts, const_fn)] 8 | #![no_std] 9 | #![allow(non_upper_case_globals)] 10 | 11 | extern crate lrs_base as base; 12 | extern crate lrs_cty as cty; 13 | extern crate lrs_arch_fns as arch_fns; 14 | extern crate lrs_str_one as str_one; 15 | extern crate lrs_fmt as fmt; 16 | extern crate lrs_time_base as time_base; 17 | extern crate lrs_rv as rv; 18 | extern crate lrs_fd as fd; 19 | extern crate lrs_alloc as alloc; 20 | extern crate lrs_saturating as saturating; 21 | extern crate lrs_io as io; 22 | extern crate lrs_syscall as syscall; 23 | 24 | pub use addr::{SockAddr, AddrType}; 25 | pub use addr::unix::{UnixSockAddr, UnixAddrType}; 26 | pub use addr::ipv4::{Ipv4Addr, Ipv4SockAddr, IPV4_SOCK_ADDR_SIZE}; 27 | pub use addr::ipv6::{Ipv6Addr, Ipv6SockAddr, IPV6_SOCK_ADDR_SIZE, Ipv6Scope}; 28 | 29 | mod std { pub use fmt::std::*; pub use cty; } 30 | 31 | pub mod cmsg; 32 | pub mod addr; 33 | pub mod socket; 34 | pub mod kind; 35 | pub mod flags; 36 | pub mod ip_proto; 37 | pub mod nl_proto; 38 | pub mod domain; 39 | pub mod msg; 40 | -------------------------------------------------------------------------------- /src/tlalc/util.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {BLOCK_SIZE}; 6 | 7 | extern { 8 | #[link_name = "llvm.expect.i1"] 9 | pub fn expect_bool(b1: bool, b2: bool) -> bool; 10 | } 11 | 12 | #[allow(unused_unsafe)] 13 | macro_rules! likely { 14 | ($e:expr) => { 15 | ::util::expect_bool($e, true) 16 | } 17 | } 18 | 19 | #[allow(unused_unsafe)] 20 | macro_rules! unlikely { 21 | ($e:expr) => { 22 | ::util::expect_bool($e, false) 23 | } 24 | } 25 | 26 | pub unsafe fn slots_per_class(bin: usize) -> usize { 27 | const BS: usize = BLOCK_SIZE; 28 | static SLOTS: [usize; 20] = [ 29 | BS / 0x10, BS / 0x20, BS / 0x30, BS / 0x40, BS / 0x50, BS / 0x60, BS / 0x70, 30 | BS / 0x80, BS / 0x90, BS / 0xA0, BS / 0xB0, BS / 0xC0, BS / 0xD0, BS / 0xE0, 31 | BS / 0xF0, 32 | BS / 0x100, BS / 0x200, BS / 0x400, BS / 0x800, BS / 0x1000, 33 | ]; 34 | *SLOTS.as_ptr().add(bin) 35 | } 36 | 37 | // pub fn check_size(mut cur: POpt, one_size: usize, total_size: usize) { 38 | // let mut real_size = 0; 39 | // while let Some(c) = *cur { 40 | // real_size += one_size; 41 | // cur = c.next; 42 | // } 43 | // assert!(real_size == total_size); 44 | // } 45 | -------------------------------------------------------------------------------- /tests/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_type = "lib"] 6 | #![crate_name = "tests"] 7 | #![feature(custom_derive, type_ascription)] 8 | 9 | macro_rules! test { 10 | ($e:expr) => { 11 | // if !$e { ::std::process::exit(1); } 12 | assert!($e); 13 | } 14 | } 15 | 16 | mod core; 17 | mod libc; 18 | mod int; 19 | mod saturating; 20 | mod wrapping; 21 | mod cty_base; 22 | mod arch_fns; 23 | mod base; 24 | mod hash; 25 | mod rv; 26 | mod parse; 27 | mod io; 28 | mod fmt; 29 | mod cell; 30 | mod str_one; 31 | mod getopt; 32 | mod rt; 33 | mod atomic; 34 | mod cty; 35 | mod r_syscall; 36 | mod syscall; 37 | mod kernel; 38 | mod clone; 39 | mod fd; 40 | mod mem; 41 | mod lock; 42 | mod time_base; 43 | mod event; 44 | mod signal; 45 | mod pipe; 46 | mod alloc; 47 | mod queue; 48 | // mod box; 49 | mod c_ptr_ptr; 50 | mod buf_reader; 51 | mod rc; 52 | mod vec; 53 | mod ringbuf; 54 | mod hashmap; 55 | mod iter; 56 | mod str_two; 57 | mod rmo; 58 | mod str_three; 59 | mod swap; 60 | mod inotify; 61 | mod env; 62 | mod fs; 63 | mod socket; 64 | mod netlink; 65 | mod sys; 66 | mod poll; 67 | mod dev; 68 | mod file; 69 | mod mqueue; 70 | mod tty; 71 | mod thread; 72 | mod process; 73 | mod time_ext; 74 | mod dir; 75 | mod user_group; 76 | -------------------------------------------------------------------------------- /tests/core/option.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | fn take() { 7 | test!(Some(0).take() == Some(0)); 8 | test!(None::.take() == None); 9 | let mut x = Some(0); 10 | x.take(); 11 | test!(x == None); 12 | } 13 | 14 | #[test] 15 | fn map() { 16 | test!(Some(0).map(|x| x+1) == Some(1)); 17 | test!(None::.map(|_| abort!()) == None); 18 | } 19 | 20 | #[test] 21 | fn unwrap() { 22 | test!(Some(0).unwrap() == 0); 23 | } 24 | 25 | #[test] 26 | #[should_panic] 27 | fn unwrap_none() { 28 | None::.unwrap(); 29 | } 30 | 31 | #[test] 32 | fn unwrap_or() { 33 | test!(Some(0).unwrap_or(1) == 0); 34 | test!(None.unwrap_or(1) == 1); 35 | } 36 | 37 | #[test] 38 | fn chain() { 39 | test!(Some(0).chain(|x| Some(x+1)) == Some(1)); 40 | test!(None::.chain(|_| abort!()) == None::); 41 | } 42 | 43 | #[test] 44 | fn as_ref() { 45 | test!(Some(0).as_ref() == Some(&0)); 46 | } 47 | 48 | #[test] 49 | fn as_mut() { 50 | test!(Some(0).as_mut() == Some(&mut 0)); 51 | } 52 | 53 | #[test] 54 | fn is_some() { 55 | test!(Some(0).is_some()); 56 | test!(!None::.is_some()); 57 | } 58 | 59 | #[test] 60 | fn is_none() { 61 | test!(!Some(0).is_none()); 62 | test!(None::.is_none()); 63 | } 64 | -------------------------------------------------------------------------------- /tests/cell/ref_cell.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::share::{RefCell, RefCellStatus}; 6 | 7 | #[test] 8 | fn test() { 9 | let cell = RefCell::new(1); 10 | test!(cell.status() == RefCellStatus::Free); 11 | { 12 | let borrow = cell.borrow(); 13 | test!(cell.status() == RefCellStatus::Borrowed(0)); 14 | test!(*borrow == 1); 15 | } 16 | test!(cell.status() == RefCellStatus::Free); 17 | { 18 | let mut borrow = cell.borrow_mut(); 19 | test!(cell.status() == RefCellStatus::BorrowedMut); 20 | test!(*borrow == 1); 21 | *borrow = 2; 22 | } 23 | { 24 | let borrow = cell.borrow(); 25 | cell.borrow(); 26 | test!(cell.status() == RefCellStatus::Borrowed(0)); 27 | test!(*borrow == 2); 28 | } 29 | } 30 | 31 | #[test] 32 | #[should_panic] 33 | fn fail2() { 34 | let cell = RefCell::new(1); 35 | let _b = cell.borrow(); 36 | cell.borrow_mut(); 37 | } 38 | 39 | #[test] 40 | #[should_panic] 41 | fn fail3() { 42 | let cell = RefCell::new(1); 43 | let _b = cell.borrow_mut(); 44 | cell.borrow_mut(); 45 | } 46 | 47 | #[test] 48 | #[should_panic] 49 | fn fail4() { 50 | let cell = RefCell::new(1); 51 | let _b = cell.borrow_mut(); 52 | cell.borrow(); 53 | } 54 | -------------------------------------------------------------------------------- /src/core/sort.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {mem, slice}; 6 | use ops::{Ordering, FnMut}; 7 | use ops::Ordering::{Greater}; 8 | 9 | pub unsafe fn sort(slice: &mut [T], f: &mut F) 10 | where F: FnMut(&T, &T) -> Ordering, 11 | { 12 | if slice.len() < 2 { 13 | return; 14 | } 15 | 16 | let pivot = &mut slice[0] as *mut T; 17 | let mut start = pivot.add(1); 18 | let mut end = pivot.add(slice.len() - 1); 19 | while start <= end { 20 | while start <= end && f(&*start, &*pivot) != Greater { 21 | start = start.offset(1); 22 | } 23 | while start < end && f(&*end, &*pivot) == Greater { 24 | end = end.offset(-1); 25 | } 26 | if start < end { 27 | mem::swap(&mut *start, &mut *end); 28 | start = start.offset(1); 29 | end = end.offset(-1); 30 | } else { 31 | break; 32 | } 33 | } 34 | start = start.offset(-1); 35 | if pivot < start { 36 | mem::swap(&mut *pivot, &mut *start); 37 | } 38 | let start_len = (start as usize - pivot as usize) / mem::size_of::(); 39 | 40 | sort(slice::from_ptr(pivot , start_len ), &mut *f); 41 | sort(slice::from_ptr(start.offset(1), slice.len() - start_len - 1), &mut *f); 42 | } 43 | -------------------------------------------------------------------------------- /src/r_syscall/x86_64/x32.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{ 6 | c_longlong, __X32_SYSCALL_BIT 7 | }; 8 | 9 | /// Syscall type 10 | pub type SCT = c_longlong; 11 | 12 | #[inline(always)] 13 | pub unsafe fn syscall0(n: SCT) -> SCT { 14 | ::arch::common0(n + __X32_SYSCALL_BIT) 15 | } 16 | 17 | #[inline(always)] 18 | pub unsafe fn syscall1(n: SCT, a1: SCT) -> SCT { 19 | ::arch::common1(n + __X32_SYSCALL_BIT, a1) 20 | } 21 | 22 | #[inline(always)] 23 | pub unsafe fn syscall2(n: SCT, a1: SCT, a2: SCT) -> SCT { 24 | ::arch::common2(n + __X32_SYSCALL_BIT, a1, a2) 25 | } 26 | 27 | #[inline(always)] 28 | pub unsafe fn syscall3(n: SCT, a1: SCT, a2: SCT, a3: SCT) -> SCT { 29 | ::arch::common3(n + __X32_SYSCALL_BIT, a1, a2, a3) 30 | } 31 | 32 | #[inline(always)] 33 | pub unsafe fn syscall4(n: SCT, a1: SCT, a2: SCT, a3: SCT, a4: SCT) -> SCT { 34 | ::arch::common4(n + __X32_SYSCALL_BIT, a1, a2, a3, a4) 35 | } 36 | 37 | #[inline(always)] 38 | pub unsafe fn syscall5(n: SCT, a1: SCT, a2: SCT, a3: SCT, a4: SCT, a5: SCT) -> SCT { 39 | ::arch::common5(n + __X32_SYSCALL_BIT, a1, a2, a3, a4, a5) 40 | } 41 | 42 | #[inline(always)] 43 | pub unsafe fn syscall6(n: SCT, a1: SCT, a2: SCT, a3: SCT, a4: SCT, a5: SCT, 44 | a6: SCT) -> SCT { 45 | ::arch::common6(n + __X32_SYSCALL_BIT, a1, a2, a3, a4, a5, a6) 46 | } 47 | -------------------------------------------------------------------------------- /src/core/data.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {mem}; 6 | use marker::{Copy}; 7 | 8 | #[allow(non_camel_case_types)] 9 | pub struct d8(u8); 10 | 11 | impl Copy for d8 { } 12 | // unsafe impl Pod for d8 { } 13 | // 14 | // #[fundamental] 15 | // pub trait NotD8 { } 16 | // impl NotD8 for .. { } 17 | // impl !NotD8 for d8 { } 18 | 19 | impl d8 { 20 | pub const fn new(byte: u8) -> d8 { 21 | d8(byte) 22 | } 23 | 24 | pub unsafe fn as_byte(&self) -> &u8 { 25 | &self.0 26 | } 27 | 28 | pub unsafe fn as_mut_byte(&mut self) -> &mut u8 { 29 | &mut self.0 30 | } 31 | } 32 | 33 | pub trait DataSlice { 34 | unsafe fn as_bytes(&self) -> &[u8]; 35 | unsafe fn as_mut_bytes(&mut self) -> &mut [u8]; 36 | fn align_for(&self) -> &[d8]; 37 | fn align_for_mut(&mut self) -> &mut [d8]; 38 | } 39 | 40 | impl DataSlice for [d8] { 41 | unsafe fn as_bytes(&self) -> &[u8] { 42 | mem::cast(self) 43 | } 44 | 45 | unsafe fn as_mut_bytes(&mut self) -> &mut [u8] { 46 | mem::cast(self) 47 | } 48 | 49 | fn align_for(&self) -> &[d8] { 50 | unsafe { mem::cast(mem::align_for::(self.as_bytes())) } 51 | } 52 | 53 | fn align_for_mut(&mut self) -> &mut [d8] { 54 | unsafe { mem::cast(mem::align_for_mut::(self.as_mut_bytes())) } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/base/into.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::ops::{Range}; 6 | 7 | #[test] 8 | fn range() { 9 | test!(Into::>>::into(..) == (None..None)); 10 | test!(Into::>>::into(1..) == (Some(1)..None)); 11 | test!(Into::>>::into(..2) == (None..Some(2))); 12 | } 13 | 14 | #[test] 15 | fn ints() { 16 | macro_rules! as_into { 17 | ($from:ty as $to:ty) => { 18 | test!(Into::<$to>::into(1 as $from) == 1); 19 | } 20 | } 21 | as_into!(u8 as u16); 22 | as_into!(u8 as u32); 23 | as_into!(u8 as u64); 24 | as_into!(u8 as usize); 25 | as_into!(u16 as u32); 26 | as_into!(u16 as u64); 27 | as_into!(u16 as usize); 28 | as_into!(u32 as u64); 29 | as_into!(u32 as usize); 30 | as_into!(u8 as i16); 31 | as_into!(u8 as i32); 32 | as_into!(u8 as i64); 33 | as_into!(u8 as isize); 34 | as_into!(u16 as i32); 35 | as_into!(u16 as i64); 36 | as_into!(u16 as isize); 37 | as_into!(u32 as i64); 38 | as_into!(u32 as isize); 39 | as_into!(i8 as i16); 40 | as_into!(i8 as i32); 41 | as_into!(i8 as i64); 42 | as_into!(i8 as isize); 43 | as_into!(i16 as i32); 44 | as_into!(i16 as i64); 45 | as_into!(i16 as isize); 46 | as_into!(i32 as i64); 47 | as_into!(i32 as isize); 48 | } 49 | -------------------------------------------------------------------------------- /src/alloc/libc.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use base::{error}; 7 | use {MemPool, MAX_SIZE}; 8 | use lrs_libc as libc; 9 | 10 | /// The libc allocator 11 | /// 12 | /// = Remarks 13 | /// 14 | /// This allocator ignores the alignment argument and always returns maximally aligned 15 | /// pointers. 16 | #[derive(Copy)] 17 | pub struct Libc; 18 | 19 | impl OutOf for Libc { 20 | fn out_of(_: ()) -> Libc { 21 | Libc 22 | } 23 | } 24 | 25 | impl MemPool for Libc { 26 | unsafe fn alloc(&mut self, size: usize, alignment: usize) -> Result<*mut d8> { 27 | self.realloc(0 as *mut d8, 0, size, alignment) 28 | } 29 | 30 | unsafe fn free(&mut self, ptr: *mut d8, size: usize, alignment: usize) { 31 | self.realloc(ptr, size, 0, alignment); 32 | } 33 | 34 | unsafe fn realloc(&mut self, old_ptr: *mut d8, oldsize: usize, newsize: usize, 35 | alignment: usize) -> Result<*mut d8> { 36 | let _ = oldsize; 37 | let _ = alignment; 38 | if newsize > MAX_SIZE { 39 | Err(error::InvalidArgument) 40 | } else { 41 | let ptr = libc::realloc(old_ptr, newsize); 42 | if ptr.is_null() { 43 | Err(error::NoMemory) 44 | } else { 45 | Ok(ptr) 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/tty/key.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![allow(non_upper_case_globals, non_camel_case_types)] 6 | 7 | use base::prelude::*; 8 | use fmt::{Debug, Write}; 9 | use cty::{self}; 10 | 11 | #[derive(Pod, Eq)] 12 | pub struct TtyKey(pub usize); 13 | 14 | macro_rules! create { 15 | ($($(#[$meta:meta])* key $name:ident = $val:ident;)*) => { 16 | $($(#[$meta])* pub const $name: TtyKey = TtyKey(cty::$val as usize);)* 17 | 18 | impl Debug for TtyKey { 19 | fn fmt(&self, mut w: &mut W) -> Result { 20 | let s = match *self { 21 | $($name => stringify!($name),)* 22 | _ => return write!(w, "Unknown({})", self.0), 23 | }; 24 | w.write_all(s.as_bytes()).ignore_ok() 25 | } 26 | } 27 | } 28 | } 29 | 30 | create! { 31 | key Interrupt = VINTR; 32 | key Quit = VQUIT; 33 | key EraseChar = VERASE; 34 | key EraseLine = VKILL; 35 | key EndOfFile = VEOF; 36 | key Timeout = VTIME; 37 | key MinInput = VMIN; 38 | key StartOutput = VSTART; 39 | key StopOutput = VSTOP; 40 | key Suspend = VSUSP; 41 | key Reprint = VREPRINT; 42 | key EraseWord = VWERASE; 43 | key Escape = VLNEXT; 44 | key EndOfLine = VEOL; 45 | key EndOfLine2 = VEOL2; 46 | } 47 | -------------------------------------------------------------------------------- /src/hashmap/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_hashmap"] 6 | #![crate_type = "lib"] 7 | #![feature(custom_derive)] 8 | #![no_std] 9 | 10 | extern crate lrs_base as base; 11 | extern crate lrs_alloc as alloc; 12 | extern crate lrs_hash as hash; 13 | extern crate lrs_fmt as fmt; 14 | 15 | use base::prelude::*; 16 | use core::ops::{Eq}; 17 | use base::undef::{UndefState}; 18 | use alloc::{Heap}; 19 | use hash::{Hash}; 20 | use hash::xx_hash::{XxHash32}; 21 | use bucket::compact::{CompactBucket}; 22 | use bucket::loose::{LooseBucket}; 23 | use table::{GenericMap}; 24 | 25 | pub use table::{Entry, VacantEntry, OccupiedEntry}; 26 | 27 | mod std { pub use fmt::std::*; } 28 | 29 | mod bucket; 30 | mod table; 31 | 32 | pub type CompactMap 33 | where Allocator: alloc::MemPool, 34 | Hasher: hash::Hasher, 35 | Seed: Into+To, 36 | Key: Eq + Hash + UndefState 37 | = GenericMap, Hasher, Seed, Allocator>; 38 | 39 | pub type HashMap 40 | where Allocator: alloc::MemPool, 41 | Hasher: hash::Hasher, 42 | Seed: Into+To, 43 | Key: Eq + Hash + UndefState 44 | = GenericMap, Hasher, Seed, Allocator>; 45 | -------------------------------------------------------------------------------- /src/lock/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_lock"] 6 | #![crate_type = "lib"] 7 | #![feature(optin_builtin_traits, const_fn, associated_consts)] 8 | #![no_std] 9 | 10 | extern crate lrs_base as base; 11 | extern crate lrs_io as io; 12 | extern crate lrs_fmt as fmt; 13 | extern crate lrs_arch_fns as arch_fns; 14 | extern crate lrs_cell as cell; 15 | extern crate lrs_atomic as atomic; 16 | extern crate lrs_time_base as time_base; 17 | extern crate lrs_cty as cty; 18 | 19 | #[cfg(not(freestanding))]extern crate lrs_syscall as syscall; 20 | 21 | #[cfg(not(freestanding))] pub use raw_condvar::{RawCondvar}; 22 | #[cfg(not(freestanding))] pub use condvar::{Condvar}; 23 | #[cfg(not(freestanding))] pub use lock::{Lock, LockGuard, DUMMY, LockStatus}; 24 | #[cfg(not(freestanding))] pub use mutex::{Mutex, MutexGuard}; 25 | #[cfg(not(freestanding))] pub use once::{Once, OnceStatus}; 26 | pub use stlock::{SingleThreadLock, SingleThreadLockGuard}; 27 | pub use stmutex::{SingleThreadMutex, SingleThreadMutexGuard}; 28 | pub use spinlock::{SpinLock, SpinLockGuard, SpinLockStatus}; 29 | 30 | mod std { pub use fmt::std::*; pub use cty; } 31 | 32 | #[cfg(not(freestanding))] mod raw_condvar; 33 | #[cfg(not(freestanding))] mod condvar; 34 | #[cfg(not(freestanding))] mod lock; 35 | #[cfg(not(freestanding))] mod mutex; 36 | #[cfg(not(freestanding))] mod once; 37 | mod stlock; 38 | mod stmutex; 39 | mod spinlock; 40 | -------------------------------------------------------------------------------- /src/core/bool.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use ops::{ 6 | Eq, FnOnce, BitOr, BitAnd, BitOrAssign, BitAndAssign, BitXor, BitXorAssign, 7 | }; 8 | use option::{Option}; 9 | use option::Option::{Some, None}; 10 | 11 | pub trait BoolExt { 12 | fn map(self, f: F) -> Option where F: FnOnce() -> T; 13 | } 14 | 15 | impl BoolExt for bool { 16 | fn map(self, f: F) -> Option 17 | where F: FnOnce() -> T, 18 | { 19 | if self { 20 | Some(f()) 21 | } else { 22 | None 23 | } 24 | } 25 | } 26 | 27 | impl Eq for bool { 28 | fn eq(&self, other: &bool) -> bool { 29 | *self == *other 30 | } 31 | } 32 | 33 | impl BitOr for bool { 34 | type Output = bool; 35 | fn bitor(self, other: bool) -> bool { self | other } 36 | } 37 | 38 | impl BitOrAssign for bool { 39 | fn bitor_assign(&mut self, other: bool) { *self |= other } 40 | } 41 | 42 | impl BitAnd for bool { 43 | type Output = bool; 44 | fn bitand(self, other: bool) -> bool { self & other } 45 | } 46 | 47 | impl BitAndAssign for bool { 48 | fn bitand_assign(&mut self, other: bool) { *self &= other } 49 | } 50 | 51 | impl BitXor for bool { 52 | type Output = bool; 53 | fn bitxor(self, other: bool) -> bool { self ^ other } 54 | } 55 | 56 | impl BitXorAssign for bool { 57 | fn bitxor_assign(&mut self, other: bool) { *self ^= other } 58 | } 59 | -------------------------------------------------------------------------------- /tests/base/rmo.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #[test] 6 | #[cfg(target_endian = "little")] 7 | fn as_ref() { 8 | test!(AsRef::<[u8]>::as_ref(&1u8) == &[1][..]); 9 | test!(AsRef::<[u8]>::as_ref(&1u16) == &[1, 0][..]); 10 | test!(AsRef::<[u8]>::as_ref(&1u32) == &[1, 0, 0, 0][..]); 11 | test!(AsRef::<[u8]>::as_ref(&1u64) == &[1, 0, 0, 0, 0, 0, 0, 0][..]); 12 | } 13 | 14 | #[test] 15 | #[cfg(target_endian = "big")] 16 | fn as_ref() { 17 | test!(AsRef::<[u8]>::as_ref(&1u8) == &[1][..]); 18 | test!(AsRef::<[u8]>::as_ref(&1u16) == &[0, 1][..]); 19 | test!(AsRef::<[u8]>::as_ref(&1u32) == &[0, 0, 0, 1][..]); 20 | test!(AsRef::<[u8]>::as_ref(&1u64) == &[0, 0, 0, 0, 0, 0, 0, 1][..]); 21 | } 22 | 23 | #[test] 24 | #[cfg(target_endian = "little")] 25 | fn as_mut() { 26 | test!(AsMut::<[u8]>::as_mut(&mut 1u8) == &[1][..]); 27 | test!(AsMut::<[u8]>::as_mut(&mut 1u16) == &[1, 0][..]); 28 | test!(AsMut::<[u8]>::as_mut(&mut 1u32) == &[1, 0, 0, 0][..]); 29 | test!(AsMut::<[u8]>::as_mut(&mut 1u64) == &[1, 0, 0, 0, 0, 0, 0, 0][..]); 30 | } 31 | 32 | #[test] 33 | #[cfg(target_endian = "big")] 34 | fn as_mut() { 35 | test!(AsMut::<[u8]>::as_mut(&mut 1u8) == &[1][..]); 36 | test!(AsMut::<[u8]>::as_mut(&mut 1u16) == &[0, 1][..]); 37 | test!(AsMut::<[u8]>::as_mut(&mut 1u32) == &[0, 0, 0, 1][..]); 38 | test!(AsMut::<[u8]>::as_mut(&mut 1u64) == &[0, 0, 0, 0, 0, 0, 0, 1][..]); 39 | } 40 | -------------------------------------------------------------------------------- /src/process/res_user.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![allow(non_upper_case_globals, non_camel_case_types)] 6 | 7 | use base::prelude::*; 8 | use fmt::{Debug, Write}; 9 | use cty::{ 10 | self, c_int, 11 | }; 12 | 13 | #[derive(Pod, Eq)] 14 | pub struct ResourceUser(pub c_int); 15 | 16 | macro_rules! create { 17 | ($($(#[$meta:meta])* usr $name:ident = $val:ident;)*) => { 18 | $($(#[$meta])* pub const $name: ResourceUser = ResourceUser(cty::$val);)* 19 | 20 | impl Debug for ResourceUser { 21 | fn fmt(&self, mut w: &mut W) -> Result { 22 | let s = match *self { 23 | $($name => stringify!($name),)* 24 | _ => return write!(w, "Invalid({})", self.0), 25 | }; 26 | w.write_all(s.as_bytes()).ignore_ok() 27 | } 28 | } 29 | } 30 | } 31 | 32 | create! { 33 | #[doc = "This process.\n"] 34 | #[doc = "= See also"] 35 | #[doc = "* link:man:getrusage(2) and RUSAGE_SELF therein"] 36 | usr Process = RUSAGE_SELF; 37 | 38 | #[doc = "The children of this process.\n"] 39 | #[doc = "= See also"] 40 | #[doc = "* link:man:getrusage(2) and RUSAGE_CHILDREN therein"] 41 | usr Children = RUSAGE_CHILDREN; 42 | 43 | #[doc = "This thread.\n"] 44 | #[doc = "= See also"] 45 | #[doc = "* link:man:getrusage(2) and RUSAGE_THREAD therein"] 46 | usr Thread = RUSAGE_THREAD; 47 | } 48 | -------------------------------------------------------------------------------- /src/tlalc/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_tlalc"] 6 | #![crate_type = "lib"] 7 | #![feature(link_llvm_intrinsics, thread_local, const_fn)] 8 | #![no_std] 9 | 10 | //! The tlalc allocator. 11 | 12 | extern crate lrs_base as base; 13 | extern crate lrs_cty as cty; 14 | extern crate lrs_syscall as syscall; 15 | extern crate lrs_thread as thread; 16 | extern crate lrs_arch_fns as arch_fns; 17 | 18 | mod std { pub use base::std::*; } 19 | 20 | pub use cache::{Cache}; 21 | 22 | #[macro_use] 23 | mod util; 24 | mod sys; 25 | mod chunk; 26 | mod p; 27 | mod cache; 28 | 29 | const CHUNK_SIZE: usize = 0x200000; 30 | const CHUNK_MASK: usize = CHUNK_SIZE - 1; 31 | const BLOCK_SIZE: usize = 0x1000; 32 | const BLOCK_MASK: usize = BLOCK_SIZE - 1; 33 | const BLOCKS_PER_CHUNK: usize = CHUNK_SIZE / BLOCK_SIZE; // 0x200 == 512 34 | const BLOCK_SHIFT: usize = 12; 35 | const CACHE_SIZE: usize = 4 * BLOCK_SIZE; 36 | const MIN_ALLOC: usize = 0x10; 37 | const MAX_SMALL: usize = 0x100; 38 | const MAX_SMALL_SHIFT: usize = 8; 39 | const LARGE_CLASS_SHIFT: usize = (MAX_SMALL / MIN_ALLOC) - MAX_SMALL_SHIFT - 1; // 7 40 | 41 | pub fn usable_size(size: usize) -> usize { 42 | unsafe { 43 | if likely!(size <= MAX_SMALL) { 44 | align!(size, [%] MIN_ALLOC) 45 | } else if size <= BLOCK_SIZE { 46 | size.next_power_of_two() 47 | } else { 48 | align!(size, [%] BLOCK_SIZE) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/core/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_core"] 6 | #![crate_type = "lib"] 7 | #![feature(no_core, lang_items, intrinsics, asm, plugin, unboxed_closures, 8 | optin_builtin_traits, const_fn, fundamental, associated_type_defaults, 9 | allow_internal_unstable, on_unimplemented)] 10 | #![plugin(lrs_core_plugin)] 11 | #![no_core] 12 | 13 | #[macro_use] 14 | pub mod macros; 15 | 16 | pub mod array; 17 | pub mod bool; 18 | pub mod char; 19 | pub mod cmp; 20 | pub mod intrinsics; 21 | pub mod iter; 22 | pub mod marker; 23 | pub mod tuple; 24 | pub mod mem; 25 | pub mod int; 26 | pub mod ops; 27 | pub mod option; 28 | pub mod panicking; 29 | pub mod ptr; 30 | pub mod repr; 31 | pub mod slice; 32 | pub mod str; 33 | pub mod thread_local; 34 | pub mod non_zero; 35 | pub mod data; 36 | pub mod float; 37 | 38 | mod sort; 39 | 40 | pub mod std { 41 | pub use ::{marker, ops, intrinsics, option, mem}; 42 | } 43 | 44 | mod core { 45 | pub use ::{iter, option, intrinsics}; 46 | } 47 | 48 | pub mod prelude { 49 | pub mod v1 { 50 | pub use marker::{ 51 | Sized, Copy, Pod, Send, Sync, NoSend, NoSync, Interrupt, NoInterrupt, 52 | PhantomData, 53 | }; 54 | pub use option::{Option}; 55 | pub use option::Option::{Some, None}; 56 | pub use ops::{Fn, FnOnce, FnMut, Drop, Deref, DerefMut}; 57 | pub use mem::{drop}; 58 | pub use iter::{Iterator}; 59 | pub use data::{d8, DataSlice}; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/lrs/process.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Process handling. 6 | 7 | pub use lrs_cty::alias::{ProcessId}; 8 | pub use lrs_process::{ 9 | process_id, parent_process_id, exit, set_file_mask, Times, used_time, new_session, 10 | session, set_process_group, process_group, resource_usage, ResourceUsage, 11 | resource_limit, set_resource_limit, 12 | }; 13 | pub use lrs_process::res::{Resource}; 14 | pub use lrs_process::res_user::{ResourceUser}; 15 | pub use lrs_process::exec::{exec}; 16 | pub use lrs_process::wait::{ 17 | ChildStatus, WaitFlags, WAIT_EXITED, WAIT_STOPPED, WAIT_CONTINUED, WAIT_DONT_BLOCK, 18 | WAIT_DONT_REAP, wait_all, wait_id, 19 | }; 20 | pub use lrs_clone::{fork}; 21 | pub use lrs_clone::flags::{CloneFlags}; 22 | 23 | pub mod clone { 24 | pub use lrs_clone::flags::{ 25 | CLONE_VM, CLONE_FS, CLONE_FILES, CLONE_SIGHAND, CLONE_PTRACE, CLONE_VFORK, 26 | CLONE_PARENT, CLONE_THREAD, CLONE_NEWMOUNT, CLONE_SYSVSEM, CLONE_SETTLS, 27 | CLONE_UNTRACED, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWUSER, CLONE_NEWPID, 28 | CLONE_NEWNET, CLONE_IO, 29 | }; 30 | } 31 | 32 | pub mod res_user { 33 | pub use lrs_process::res_user::{ 34 | Process, Children, Thread, 35 | }; 36 | } 37 | 38 | pub mod resource { 39 | pub use lrs_process::res::{ 40 | VirtualMemory, CoreDumpSize, CpuTime, ContiguousCpuTime, DataSegment, FileSize, 41 | LockedMemory, MsgQueue, Niceness, FileDescriptors, Processes, Priority, 42 | PendingSignals, Stack, 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/varargs/aarch64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int}; 6 | use {VarArg}; 7 | use core::{mem, ptr}; 8 | use core::intrinsics::{type_id}; 9 | 10 | #[repr(C)] 11 | pub struct VarArgs { 12 | __stack: *mut u8, 13 | __gr_top: *mut u8, 14 | __vr_top: *mut u8, 15 | __gr_offs: c_int, 16 | __vr_offs: c_int, 17 | } 18 | 19 | impl VarArgs { 20 | pub unsafe fn get(&mut self) -> T { 21 | if fp::() { 22 | let mut offs = self.__vr_offs as isize; 23 | if offs <= -16 { 24 | self.__vr_offs += 16; 25 | if cfg!(target_endian = "big") { 26 | offs += 16 - mem::size_of::() as isize; 27 | } 28 | return ptr::read(self.__vr_top.offset(offs) as *mut T); 29 | } 30 | } else { 31 | let mut offs = self.__gr_offs as isize; 32 | if offs <= -8 { 33 | self.__gr_offs += 8; 34 | if cfg!(target_endian = "big") { 35 | offs += 8 - mem::size_of::() as isize 36 | } 37 | return ptr::read(self.__gr_top.offset(offs) as *mut T); 38 | } 39 | } 40 | 41 | let mut ptr = self.__stack; 42 | self.__stack = ptr.add(8); 43 | if cfg!(target_endian = "big") { 44 | ptr = ptr.add(8 - mem::size_of::()); 45 | } 46 | ptr::read(ptr as *mut T) 47 | } 48 | } 49 | 50 | unsafe fn fp() -> bool { 51 | let id = type_id::(); 52 | id == type_id::() || id == type_id::() 53 | } 54 | -------------------------------------------------------------------------------- /src/lock/once.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use base::prelude::*; 6 | use atomic::{Atomic}; 7 | 8 | const UNINITIALIZED: u8 = 0; 9 | const WORKING: u8 = 1; 10 | const INITIALIZED: u8 = 2; 11 | 12 | /// The status of a once. 13 | pub enum OnceStatus { 14 | Uninitialized, 15 | Working, 16 | Initialized, 17 | } 18 | 19 | #[repr(C)] 20 | pub struct Once { 21 | status: Atomic, 22 | } 23 | 24 | impl<'a> Once { 25 | /// Creates a new, uninitialized, once. 26 | pub const fn new() -> Once { 27 | Once { status: Atomic::new(UNINITIALIZED) } 28 | } 29 | 30 | /// Returns the status of the once. 31 | pub fn status(&self) -> OnceStatus { 32 | match self.status.load_unordered() { 33 | UNINITIALIZED => OnceStatus::Uninitialized, 34 | WORKING => OnceStatus::Working, 35 | _ => OnceStatus::Initialized, 36 | } 37 | } 38 | 39 | pub fn once(&self, f: F) -> Option 40 | where F: FnOnce() -> T, 41 | { 42 | let mut status = self.status.load_acquire(); 43 | if status == INITIALIZED { 44 | return None; 45 | } 46 | if status == UNINITIALIZED { 47 | status = self.status.compare_exchange(UNINITIALIZED, WORKING); 48 | } 49 | if status == UNINITIALIZED { 50 | let res = f(); 51 | self.status.store_release(INITIALIZED); 52 | return Some(res); 53 | } 54 | while status == WORKING { 55 | status = self.status.load_acquire(); 56 | } 57 | None 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/base/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_base"] 6 | #![crate_type = "lib"] 7 | #![feature(custom_derive, default_type_parameter_fallback)] 8 | #![no_std] 9 | 10 | extern crate lrs_wrapping as wrapping; 11 | extern crate lrs_cty_base as cty_base; 12 | 13 | pub mod std { 14 | pub use core::*; 15 | pub use {result, error}; 16 | pub mod share { 17 | pub use core::thread_local::*; 18 | } 19 | pub mod conv { 20 | pub use conv::as_ref::{AsRef, AsMut, TryAsRef, TryAsMut}; 21 | 22 | pub use conv::to::{To, TryTo}; 23 | pub use conv::from::{From, TryFrom}; 24 | 25 | pub use conv::out_of::{OutOf}; 26 | pub use conv::into::{Into}; 27 | 28 | // pub use conv::default::{Default}; 29 | pub use conv::clone::{Clone}; 30 | } 31 | } 32 | 33 | pub mod result; 34 | pub mod error; 35 | pub mod undef; 36 | pub mod conv { 37 | pub mod as_ref; 38 | 39 | pub mod from; 40 | pub mod to; 41 | 42 | pub mod out_of; 43 | pub mod into; 44 | 45 | // pub mod default; 46 | pub mod clone; 47 | } 48 | 49 | pub mod prelude { 50 | pub use core::prelude::v1::*; 51 | pub use core::bool::{BoolExt}; 52 | pub use result::{Result}; 53 | pub use result::Result::{Ok, Err}; 54 | 55 | pub use conv::as_ref::{AsRef, AsMut, TryAsRef, TryAsMut}; 56 | 57 | pub use conv::from::{From, TryFrom}; 58 | pub use conv::to::{To, TryTo}; 59 | 60 | pub use conv::out_of::{OutOf}; 61 | pub use conv::into::{Into}; 62 | 63 | // pub use conv::default::{Default}; 64 | pub use conv::clone::{Clone, TryClone}; 65 | } 66 | -------------------------------------------------------------------------------- /src/varargs/lib.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![crate_name = "lrs_varargs"] 6 | #![crate_type = "lib"] 7 | #![no_std] 8 | 9 | extern crate lrs_cty as cty; 10 | 11 | #[cfg(target_arch = "x86_64")] #[path = "x86_64.rs"] mod arch; 12 | #[cfg(target_arch = "x86")] #[path = "x86.rs"] mod arch; 13 | #[cfg(target_arch = "arm")] #[path = "arm.rs"] mod arch; 14 | #[cfg(target_arch = "aarch64")] #[path = "aarch64.rs"] mod arch; 15 | 16 | /// A list of variable arguments. 17 | /// 18 | /// = Remarks 19 | /// 20 | /// This type is compatible with the `va_list` C type in arguments. 21 | #[repr(C)] 22 | pub struct VarArgs { 23 | inner: arch::VarArgs, 24 | } 25 | 26 | impl VarArgs { 27 | /// Retrieves an object from the list of variable arguments. 28 | pub unsafe fn get(&mut self) -> T { 29 | self.inner.get() 30 | } 31 | } 32 | 33 | /// Objects that can be retrieved from a VarArgs object. 34 | /// 35 | /// = Remarks 36 | /// 37 | /// This trait must not be implemented by user code. 38 | pub unsafe trait VarArg: Sized { } 39 | 40 | unsafe impl VarArg for u8 { } 41 | unsafe impl VarArg for u16 { } 42 | unsafe impl VarArg for u32 { } 43 | unsafe impl VarArg for u64 { } 44 | unsafe impl VarArg for usize { } 45 | unsafe impl VarArg for i8 { } 46 | unsafe impl VarArg for i16 { } 47 | unsafe impl VarArg for i32 { } 48 | unsafe impl VarArg for i64 { } 49 | unsafe impl VarArg for isize { } 50 | unsafe impl VarArg for f32 { } 51 | unsafe impl VarArg for f64 { } 52 | unsafe impl VarArg for *const T { } 53 | unsafe impl VarArg for *mut T { } 54 | -------------------------------------------------------------------------------- /tests/fmt/num.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::alloc::{OncePool}; 6 | 7 | macro_rules! tt { 8 | ($fmt:expr, $name:ident, $val:expr, $res:expr) => { 9 | #[test] fn $name() { 10 | let mut buf = [0; 30]; 11 | let mut buf = Vec::with_pool(OncePool::new(buf.as_mut())); 12 | write!(&mut buf, $fmt, $val); 13 | test!(&*buf == $res); 14 | } 15 | } 16 | } 17 | 18 | tt!("{:?}", debug_i8, -127i8, "-127"); 19 | tt!("{:?}", display_i8, -127i8, "-127"); 20 | 21 | tt!("{:?}", debug_i16, -127i16, "-127"); 22 | tt!("{:?}", display_i16, -127i16, "-127"); 23 | 24 | tt!("{:?}", debug_i32, -127i32, "-127"); 25 | tt!("{:?}", display_i32, -127i32, "-127"); 26 | 27 | tt!("{:?}", debug_i64, i64::min() + 1, "-9223372036854775807"); 28 | tt!("{:?}", display_i64, i64::min() + 1, "-9223372036854775807"); 29 | 30 | tt!("{:?}", debug_u8, 127u8, "127"); 31 | tt!("{:?}", display_u8, 127u8, "127"); 32 | 33 | tt!("{:?}", debug_u16, 127u16, "127"); 34 | tt!("{:?}", display_u16, 127u16, "127"); 35 | 36 | tt!("{:?}", debug_u32, 127u32, "127"); 37 | tt!("{:?}", display_u32, 127u32, "127"); 38 | 39 | tt!("{:?}", debug_u64, u64::max(), "18446744073709551615"); 40 | tt!("{:?}", display_u64, u64::max(), "18446744073709551615"); 41 | 42 | tt!("{:x}", lowerhex_u8, 127u8, "7f"); 43 | tt!("{:X}", upperhex_u8, 127u8, "7F"); 44 | 45 | tt!("{:x}", lowerhex_i16, 127u16, "7f"); 46 | tt!("{:X}", upperhex_i16, 127u16, "7F"); 47 | 48 | tt!("{:x}", lowerhex_i32, 127u32, "7f"); 49 | tt!("{:X}", upperhex_i32, 127u32, "7F"); 50 | 51 | tt!("{:x}", lowerhex_i64, u64::max(), "ffffffffffffffff"); 52 | tt!("{:X}", upperhex_i64, u64::max(), "FFFFFFFFFFFFFFFF"); 53 | -------------------------------------------------------------------------------- /src/tree/path.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use {Node}; 6 | use core::{intrinsics}; 7 | 8 | // The longest path in a LLRB tree is bounded by 2*ln(n). Since n cannot be larger 9 | // than the number addresses, we get the bound below. 10 | #[cfg(target_pointer_width = "32")] pub const LONGEST_PATH: usize = 64; 11 | #[cfg(target_pointer_width = "64")] pub const LONGEST_PATH: usize = 128; 12 | 13 | pub struct Path<'a, U: Copy> { 14 | buf: [(&'a Node, U); LONGEST_PATH], 15 | pos: usize, 16 | } 17 | 18 | impl<'a, U: Copy> Path<'a, U> { 19 | /// Creates a new path. 20 | /// 21 | /// = Remarks 22 | /// 23 | /// The `reset` method must be called before the path is used or the behavior is 24 | /// undefnied. 25 | pub unsafe fn new() -> Path<'a, U> { 26 | intrinsics::uninit() 27 | } 28 | 29 | /// Resets the length of the path to `0`. 30 | pub fn reset(&mut self) { 31 | self.pos = 0; 32 | } 33 | 34 | /// Adds a node to the path. 35 | /// 36 | /// = Remarks 37 | /// 38 | /// This is unsafe because it doesn't check for overflow. The logest allowed path 39 | /// length is `LONGEST_PATH`. 40 | pub unsafe fn push(&mut self, node: &'a Node, ord: U) { 41 | *self.buf.as_mut_ptr().add(self.pos) = (node, ord); 42 | self.pos += 1; 43 | } 44 | 45 | /// Removes an element from the path. 46 | pub fn pop(&mut self) -> Option<(&'a Node, U)> { 47 | unsafe { 48 | if self.pos > 0 { 49 | self.pos -= 1; 50 | Some(*self.buf.as_ptr().add(self.pos)) 51 | } else { 52 | None 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/cty_base/arm.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod errno { 6 | pub use ::gen::{ 7 | EPERM, ENOENT, ESRCH, EINTR, EIO, ENXIO, E2BIG, ENOEXEC, EBADF, ECHILD, EAGAIN, 8 | ENOMEM, EACCES, EFAULT, ENOTBLK, EBUSY, EEXIST, EXDEV, ENODEV, ENOTDIR, EISDIR, 9 | EINVAL, ENFILE, EMFILE, ENOTTY, ETXTBSY, EFBIG, ENOSPC, ESPIPE, EROFS, EMLINK, 10 | EPIPE, EDOM, ERANGE, EDEADLK, ENAMETOOLONG, ENOLCK, ENOSYS, ENOTEMPTY, ELOOP, 11 | EWOULDBLOCK, ENOMSG, EIDRM, ECHRNG, EL2NSYNC, EL3HLT, EL3RST, ELNRNG, EUNATCH, 12 | ENOCSI, EL2HLT, EBADE, EBADR, EXFULL, ENOANO, EBADRQC, EBADSLT, EDEADLOCK, EBFONT, 13 | ENOSTR, ENODATA, ETIME, ENOSR, ENONET, ENOPKG, EREMOTE, ENOLINK, EADV, ESRMNT, 14 | ECOMM, EPROTO, EMULTIHOP, EDOTDOT, EBADMSG, EOVERFLOW, ENOTUNIQ, EBADFD, EREMCHG, 15 | ELIBACC, ELIBBAD, ELIBSCN, ELIBMAX, ELIBEXEC, EILSEQ, ERESTART, ESTRPIPE, EUSERS, 16 | ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT, 17 | ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, EAFNOSUPPORT, EADDRINUSE, 18 | EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, ENETRESET, ECONNABORTED, ECONNRESET, 19 | ENOBUFS, EISCONN, ENOTCONN, ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, 20 | EHOSTDOWN, EHOSTUNREACH, EALREADY, EINPROGRESS, ESTALE, EUCLEAN, ENOTNAM, ENAVAIL, 21 | EISNAM, EREMOTEIO, EDQUOT, ENOMEDIUM, EMEDIUMTYPE, ECANCELED, ENOKEY, EKEYEXPIRED, 22 | EKEYREVOKED, EKEYREJECTED, EOWNERDEAD, ENOTRECOVERABLE, ERFKILL, EHWPOISON, 23 | }; 24 | } 25 | 26 | pub mod types { 27 | // These will not be reused by cty and have to be kept in sync manually. 28 | pub type c_int = i32; 29 | pub type c_char = u8; 30 | } 31 | -------------------------------------------------------------------------------- /src/cty_base/x86.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod errno { 6 | pub use ::gen::{ 7 | EPERM, ENOENT, ESRCH, EINTR, EIO, ENXIO, E2BIG, ENOEXEC, EBADF, ECHILD, EAGAIN, 8 | ENOMEM, EACCES, EFAULT, ENOTBLK, EBUSY, EEXIST, EXDEV, ENODEV, ENOTDIR, EISDIR, 9 | EINVAL, ENFILE, EMFILE, ENOTTY, ETXTBSY, EFBIG, ENOSPC, ESPIPE, EROFS, EMLINK, 10 | EPIPE, EDOM, ERANGE, EDEADLK, ENAMETOOLONG, ENOLCK, ENOSYS, ENOTEMPTY, ELOOP, 11 | EWOULDBLOCK, ENOMSG, EIDRM, ECHRNG, EL2NSYNC, EL3HLT, EL3RST, ELNRNG, EUNATCH, 12 | ENOCSI, EL2HLT, EBADE, EBADR, EXFULL, ENOANO, EBADRQC, EBADSLT, EDEADLOCK, EBFONT, 13 | ENOSTR, ENODATA, ETIME, ENOSR, ENONET, ENOPKG, EREMOTE, ENOLINK, EADV, ESRMNT, 14 | ECOMM, EPROTO, EMULTIHOP, EDOTDOT, EBADMSG, EOVERFLOW, ENOTUNIQ, EBADFD, EREMCHG, 15 | ELIBACC, ELIBBAD, ELIBSCN, ELIBMAX, ELIBEXEC, EILSEQ, ERESTART, ESTRPIPE, EUSERS, 16 | ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT, 17 | ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, EAFNOSUPPORT, EADDRINUSE, 18 | EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, ENETRESET, ECONNABORTED, ECONNRESET, 19 | ENOBUFS, EISCONN, ENOTCONN, ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, 20 | EHOSTDOWN, EHOSTUNREACH, EALREADY, EINPROGRESS, ESTALE, EUCLEAN, ENOTNAM, ENAVAIL, 21 | EISNAM, EREMOTEIO, EDQUOT, ENOMEDIUM, EMEDIUMTYPE, ECANCELED, ENOKEY, EKEYEXPIRED, 22 | EKEYREVOKED, EKEYREJECTED, EOWNERDEAD, ENOTRECOVERABLE, ERFKILL, EHWPOISON, 23 | }; 24 | } 25 | 26 | pub mod types { 27 | // These will not be reused by cty and have to be kept in sync manually. 28 | pub type c_int = i32; 29 | pub type c_char = i8; 30 | } 31 | -------------------------------------------------------------------------------- /src/cty_base/aarch64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod errno { 6 | pub use ::gen::{ 7 | EPERM, ENOENT, ESRCH, EINTR, EIO, ENXIO, E2BIG, ENOEXEC, EBADF, ECHILD, EAGAIN, 8 | ENOMEM, EACCES, EFAULT, ENOTBLK, EBUSY, EEXIST, EXDEV, ENODEV, ENOTDIR, EISDIR, 9 | EINVAL, ENFILE, EMFILE, ENOTTY, ETXTBSY, EFBIG, ENOSPC, ESPIPE, EROFS, EMLINK, 10 | EPIPE, EDOM, ERANGE, EDEADLK, ENAMETOOLONG, ENOLCK, ENOSYS, ENOTEMPTY, ELOOP, 11 | EWOULDBLOCK, ENOMSG, EIDRM, ECHRNG, EL2NSYNC, EL3HLT, EL3RST, ELNRNG, EUNATCH, 12 | ENOCSI, EL2HLT, EBADE, EBADR, EXFULL, ENOANO, EBADRQC, EBADSLT, EDEADLOCK, EBFONT, 13 | ENOSTR, ENODATA, ETIME, ENOSR, ENONET, ENOPKG, EREMOTE, ENOLINK, EADV, ESRMNT, 14 | ECOMM, EPROTO, EMULTIHOP, EDOTDOT, EBADMSG, EOVERFLOW, ENOTUNIQ, EBADFD, EREMCHG, 15 | ELIBACC, ELIBBAD, ELIBSCN, ELIBMAX, ELIBEXEC, EILSEQ, ERESTART, ESTRPIPE, EUSERS, 16 | ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT, 17 | ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, EAFNOSUPPORT, EADDRINUSE, 18 | EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, ENETRESET, ECONNABORTED, ECONNRESET, 19 | ENOBUFS, EISCONN, ENOTCONN, ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, 20 | EHOSTDOWN, EHOSTUNREACH, EALREADY, EINPROGRESS, ESTALE, EUCLEAN, ENOTNAM, ENAVAIL, 21 | EISNAM, EREMOTEIO, EDQUOT, ENOMEDIUM, EMEDIUMTYPE, ECANCELED, ENOKEY, EKEYEXPIRED, 22 | EKEYREVOKED, EKEYREJECTED, EOWNERDEAD, ENOTRECOVERABLE, ERFKILL, EHWPOISON, 23 | }; 24 | } 25 | 26 | pub mod types { 27 | // These will not be reused by cty and have to be kept in sync manually. 28 | pub type c_int = i32; 29 | pub type c_char = u8; 30 | } 31 | -------------------------------------------------------------------------------- /src/cty_base/x86_64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub mod errno { 6 | pub use ::gen::{ 7 | EPERM, ENOENT, ESRCH, EINTR, EIO, ENXIO, E2BIG, ENOEXEC, EBADF, ECHILD, EAGAIN, 8 | ENOMEM, EACCES, EFAULT, ENOTBLK, EBUSY, EEXIST, EXDEV, ENODEV, ENOTDIR, EISDIR, 9 | EINVAL, ENFILE, EMFILE, ENOTTY, ETXTBSY, EFBIG, ENOSPC, ESPIPE, EROFS, EMLINK, 10 | EPIPE, EDOM, ERANGE, EDEADLK, ENAMETOOLONG, ENOLCK, ENOSYS, ENOTEMPTY, ELOOP, 11 | EWOULDBLOCK, ENOMSG, EIDRM, ECHRNG, EL2NSYNC, EL3HLT, EL3RST, ELNRNG, EUNATCH, 12 | ENOCSI, EL2HLT, EBADE, EBADR, EXFULL, ENOANO, EBADRQC, EBADSLT, EDEADLOCK, EBFONT, 13 | ENOSTR, ENODATA, ETIME, ENOSR, ENONET, ENOPKG, EREMOTE, ENOLINK, EADV, ESRMNT, 14 | ECOMM, EPROTO, EMULTIHOP, EDOTDOT, EBADMSG, EOVERFLOW, ENOTUNIQ, EBADFD, EREMCHG, 15 | ELIBACC, ELIBBAD, ELIBSCN, ELIBMAX, ELIBEXEC, EILSEQ, ERESTART, ESTRPIPE, EUSERS, 16 | ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT, 17 | ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, EAFNOSUPPORT, EADDRINUSE, 18 | EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, ENETRESET, ECONNABORTED, ECONNRESET, 19 | ENOBUFS, EISCONN, ENOTCONN, ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, 20 | EHOSTDOWN, EHOSTUNREACH, EALREADY, EINPROGRESS, ESTALE, EUCLEAN, ENOTNAM, ENAVAIL, 21 | EISNAM, EREMOTEIO, EDQUOT, ENOMEDIUM, EMEDIUMTYPE, ECANCELED, ENOKEY, EKEYEXPIRED, 22 | EKEYREVOKED, EKEYREJECTED, EOWNERDEAD, ENOTRECOVERABLE, ERFKILL, EHWPOISON, 23 | }; 24 | } 25 | 26 | pub mod types { 27 | // These will not be reused by cty and have to be kept in sync manually. 28 | pub type c_int = i32; 29 | pub type c_char = i8; 30 | } 31 | -------------------------------------------------------------------------------- /src/lrs/tty.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | pub use lrs_tty::{Tty, is_a_tty, hang_up}; 6 | pub use lrs_tty::attr::{TtyAttr, TtyInFlags, TtyOutFlags, TtyCtrlFlags, TtyLocFlags}; 7 | pub use lrs_tty::disc::{LineDiscipline}; 8 | pub use lrs_tty::key::{TtyKey}; 9 | 10 | pub mod flags { 11 | pub use lrs_tty::attr::{ 12 | TTYIN_NONE, TTYIN_IGNORE_BREAK, TTYIN_BREAK_TO_INT, TTYIN_IGNORE_ERRORS, 13 | TTYIN_MARK_ERRORS, TTYIN_CHECK_INPUT, TTYIN_TO_LOWER, TTYIN_TO_ASCII, 14 | TTYIN_NL_TO_CR, TTYIN_IGNORE_CR, TTYIN_CR_TO_NL, TTYIN_OUTPUT_FLOW_CTRL, 15 | TTYIN_INPUT_FLOW_CTRL, TTYIN_ANY_RESTART, TTYIN_UTF8, TTYOUT_NONE, TTYOUT_PROCESS, 16 | TTYOUT_TO_UPPER, TTYOUT_NL_TO_CRNL, TTYOUT_CR_TO_NL, TTYOUT_NO_COL0_CR, 17 | TTYOUT_NO_CR, TTYCTRL_NONE, TTYCTRL_CSTOPB, TTYCTRL_CREAD, TTYCTRL_PARENB, 18 | TTYCTRL_PARODD, TTYCTRL_HUPCL, TTYCTRL_CLOCAL, TTYCTRL_CMSPAR, TTYCTRL_CRTSCTS, 19 | TTYLOC_NONE, TTYLOC_SIGNALS, TTYLOC_CANONICAL, TTYLOC_ECHO, TTYLOC_ERASE, 20 | TTYLOC_KILL, TTYLOC_ECHO_NL, TTYLOC_ECHO_ESCAPED, TTYLOC_ECHOPRT, TTYLOC_ECHOKE, 21 | TTYLOC_NOFLSH, TTYLOC_TOSTOP, TTYLOC_IEXTEN, 22 | }; 23 | } 24 | 25 | pub mod line_disc { 26 | pub use lrs_tty::disc::{ 27 | Tty, Slip, Mouse, Ppp, Strip, Ax25, X25, SixPack, Masc, R3964, ProfibusFdl, Irda, 28 | Smsblock, Hdlc, SyncPpp, Hci, GigasetM101, Slcan, Pps, V253, Caif, Gsm0710, TiWl, 29 | TraceSink, TraceRouter, 30 | }; 31 | } 32 | 33 | pub mod key { 34 | pub use lrs_tty::key::{ 35 | Interrupt, Quit, EraseChar, EraseLine, EndOfFile, Timeout, MinInput, StartOutput, 36 | StopOutput, Suspend, Reprint, EraseWord, Escape, EndOfLine, EndOfLine2, 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /src/rt/aux.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_int, ElfPhdr, AUX_CNT, AT_PHDR, AT_EXECFD, AT_PHNUM, AT_PAGESZ, PAGE_SIZE}; 6 | use core::{slice}; 7 | 8 | static mut AUXV: [usize; AUX_CNT] = [0; AUX_CNT]; 9 | 10 | /// Initializes the AUXV. 11 | /// 12 | /// [argument, auxv] 13 | /// A pointer to the environment variable passed by the OS. 14 | pub fn init(mut auxv: *const usize) { 15 | unsafe { 16 | while *auxv != 0 { 17 | auxv = auxv.add(1); 18 | } 19 | auxv = auxv.add(1); 20 | 21 | while *auxv != 0 { 22 | if *auxv < AUX_CNT { 23 | AUXV[*auxv] = *auxv.add(1); 24 | } 25 | auxv = auxv.add(2); 26 | } 27 | } 28 | } 29 | 30 | /// The program to be interpreted. 31 | /// 32 | /// [return_value] 33 | /// Returns a file descriptor to the object file to be interpreted. 34 | /// 35 | /// = Remarks 36 | /// 37 | /// Only set if this program is an interpreter. Even then, `AT_PHDR` might be set instead. 38 | pub fn program_fd() -> Option { 39 | match unsafe { AUXV[AT_EXECFD] } { 40 | 0 => None, 41 | n => Some(n as c_int), 42 | } 43 | } 44 | 45 | /// The program header table. 46 | /// 47 | /// [return_value] 48 | /// Said table. 49 | pub fn program_header_table() -> Option<&'static [ElfPhdr]> { 50 | match unsafe { AUXV[AT_PHDR] } { 51 | 0 => None, 52 | n => Some(unsafe { slice::from_ptr(n as *const _, AUXV[AT_PHNUM]) }), 53 | } 54 | } 55 | 56 | /// The page size of the process. 57 | /// 58 | /// [return_value] 59 | /// Said size. 60 | pub fn page_size() -> usize { 61 | match unsafe { AUXV[AT_PAGESZ] } { 62 | 0 => PAGE_SIZE, 63 | n => n, 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/getopt/mod.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use std::getopt::{Getopt}; 6 | use std::iter::{IteratorExt}; 7 | use std::string::{CStr}; 8 | 9 | macro_rules! cs { 10 | ($t:expr) => { 11 | concat!($t, "\0").try_as_ref().unwrap():&CStr 12 | } 13 | } 14 | 15 | macro_rules! cmp { 16 | ($e:expr, $left:expr) => { 17 | match $e { 18 | Some((l, None)) if l == $left => { }, 19 | _ => abort!(), 20 | } 21 | }; 22 | ($e:expr, $left:expr, $right:expr) => { 23 | match $e { 24 | Some((l, r)) if l == $left && r.unwrap() == $right => { }, 25 | _ => abort!(), 26 | } 27 | } 28 | } 29 | 30 | #[test] 31 | fn test() { 32 | let opts = [ 33 | (Some('a'), Some("aa"), false), 34 | (Some('b'), Some("bb"), true), 35 | ]; 36 | let args = [ 37 | cs!("-a"), cs!("a"), 38 | cs!("-aa"), 39 | cs!("--aa"), cs!("a"), 40 | cs!("--aa=a"), 41 | cs!("-b"), 42 | cs!("-bb"), 43 | cs!("--bb"), 44 | cs!("--bb=b"), 45 | cs!("-cde"), 46 | cs!("--test"), 47 | cs!("--"), 48 | cs!("test"), 49 | ]; 50 | let mut g = Getopt::new(args.iter().map(|a| *a), &opts); 51 | 52 | cmp!(g.next(), "a", "a"); 53 | cmp!(g.next(), "a", "a"); 54 | cmp!(g.next(), "aa", "a"); 55 | cmp!(g.next(), "aa", "a"); 56 | cmp!(g.next(), "b"); 57 | cmp!(g.next(), "b", "b"); 58 | cmp!(g.next(), "bb"); 59 | cmp!(g.next(), "bb", "b"); 60 | cmp!(g.next(), "c"); 61 | cmp!(g.next(), "d"); 62 | cmp!(g.next(), "e"); 63 | cmp!(g.next(), "test"); 64 | 65 | assert!(g.next() == None); 66 | assert!(g.used() == args.len() - 1); 67 | } 68 | -------------------------------------------------------------------------------- /src/str_two/cmp.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::ops::{Eq, Deref}; 6 | use str_one::{ByteStr, CStr, NoNullStr}; 7 | use string::{String}; 8 | use c_string::{CString}; 9 | use alloc::{MemPool}; 10 | 11 | macro_rules! owned { 12 | ($one:ident, $two:ident) => { 13 | impl Eq<$two

> for $one

14 | where H1: MemPool, 15 | H2: MemPool, 16 | { 17 | fn eq(&self, other: &$two

) -> bool { 18 | self.deref() == other.deref() 19 | } 20 | } 21 | } 22 | } 23 | 24 | owned!(CString, CString); 25 | owned!(CString, String); 26 | owned!(String, CString); 27 | owned!(String, String); 28 | 29 | macro_rules! borrowed_no_str { 30 | ($one:ident, $two:ty) => { 31 | impl Eq<$two> for $one 32 | where H: MemPool, 33 | { 34 | fn eq(&self, other: &$two) -> bool { 35 | let deref: &[u8] = self.deref().deref(); 36 | deref == other 37 | } 38 | } 39 | } 40 | } 41 | 42 | borrowed_no_str!(CString, ByteStr); 43 | borrowed_no_str!(CString, NoNullStr); 44 | borrowed_no_str!(CString, CStr); 45 | borrowed_no_str!(CString, str); 46 | borrowed_no_str!(CString, [u8]); 47 | 48 | macro_rules! borrowed_str { 49 | ($one:ident, $two:ty) => { 50 | impl Eq<$two> for $one 51 | where H: MemPool, 52 | { 53 | fn eq(&self, other: &$two) -> bool { 54 | self.as_bytes() == other 55 | } 56 | } 57 | } 58 | } 59 | 60 | borrowed_str!(String, ByteStr); 61 | borrowed_str!(String, NoNullStr); 62 | borrowed_str!(String, CStr); 63 | borrowed_str!(String, str); 64 | borrowed_str!(String, [u8]); 65 | -------------------------------------------------------------------------------- /src/varargs/x86_64.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use cty::{c_uint}; 6 | use {VarArg}; 7 | use core::ptr::{self, NoAliasMutObjPtr}; 8 | use core::intrinsics::{type_id}; 9 | 10 | #[repr(C)] 11 | pub struct VarArgs { 12 | int: *mut VarInt, 13 | } 14 | 15 | #[repr(C)] 16 | struct VarInt { 17 | gp_offset: c_uint, 18 | fp_offset: c_uint, 19 | overflow_arg_area: *mut u8, 20 | reg_save_area: *mut u8, 21 | } 22 | 23 | impl VarArgs { 24 | pub unsafe fn get(&mut self) -> T { 25 | let mut var = NoAliasMutObjPtr::new(self.int); 26 | 27 | if fp::() { 28 | // ABI says here 304 instead of 176 which is 48 + 16 * 16 instead of 29 | // 48 + 8 * 16. That is, ABI says that up to 16 floating point registers are 30 | // used as arguments. However, GCC says that only 8 fp registers are used and 31 | // this agrees with what the ABI says about argument passing elsewhere. 32 | if var.fp_offset <= 176 - 16 { 33 | let val = ptr::read(var.reg_save_area.add(var.fp_offset as usize) as *mut T); 34 | var.fp_offset += 16; 35 | return val; 36 | } 37 | } else { 38 | if var.gp_offset <= 48 - 8 { 39 | let val = ptr::read(var.reg_save_area.add(var.gp_offset as usize) as *mut T); 40 | var.gp_offset += 8; 41 | return val; 42 | } 43 | } 44 | 45 | let val = ptr::read(var.overflow_arg_area as *mut T); 46 | var.overflow_arg_area = var.overflow_arg_area.add(8); 47 | val 48 | } 49 | } 50 | 51 | unsafe fn fp() -> bool { 52 | let id = type_id::(); 53 | id == type_id::() || id == type_id::() 54 | } 55 | -------------------------------------------------------------------------------- /Documentation/adoc/undefined_operations.adoc: -------------------------------------------------------------------------------- 1 | = Undefined Operations in lrs 2 | 3 | This document contains an incomplete list of operations that are undefined in 4 | lrs programs. 5 | 6 | If an lrs program contains an undefined operation, the behavior of the abstract 7 | machine executing said program is undefined. Note that, as long as you're not 8 | using the `unsafe` keyword, you're not at fault if your program contains an 9 | undefined operation. 10 | 11 | :llvm_par: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules 12 | :llvm_noalias: http://llvm.org/docs/LangRef.html#noalias 13 | 14 | Data races:: 15 | + 16 | [quote, The C++11 Standard] 17 | The execution of a program contains a *data race* if it contains two conflicting 18 | actions in different threads, at least one of which is not atomic, and neither 19 | happens before the other. 20 | Memory access that violates LLVM's pointer aliasing rules:: These 21 | {llvm_par}[rules] forbid, in particular, null pointer access. 22 | Creating invalid (mutable) references:: This includes: 23 | + 24 | -- 25 | * References that violate LLVM's {llvm_noalias}[noalias] model. 26 | * References with addresses smaller than 4096. 27 | * References that don't point to objects of the specified type. 28 | -- 29 | Storing invalid values in objects of primitive type:: This includes: 30 | + 31 | -- 32 | * Values other than `true` and `false` in `bool`. 33 | * Enumerations with undefined discriminant values. 34 | * Values outside the valid unicode range in `char`. 35 | * Non-UTF-8 sequences in `str`. 36 | -- 37 | Not running the destructors of objects at the end of their lifetime:: Unless 38 | said objects implement the `Leak` trait. 39 | 40 | Note that, while the rustc manual describes access of uninitialized memory as 41 | an undefined operation, this is not the case in general. However, when used as 42 | input to safe functions, the values read from uninitialized memory can cause 43 | those functions to perform undefined operations. 44 | -------------------------------------------------------------------------------- /src/str_one/c_str/index.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::{mem}; 6 | use core::ops::{Index, IndexMut, RangeFrom, RangeTo, Range, RangeFull}; 7 | use {CStr, NoNullStr}; 8 | 9 | impl Index for CStr { 10 | type Output = u8; 11 | fn index(&self, idx: usize) -> &u8 { 12 | &self.0[idx] 13 | } 14 | } 15 | 16 | impl Index for CStr { 17 | type Output = CStr; 18 | fn index(&self, _: RangeFull) -> &CStr { 19 | self 20 | } 21 | } 22 | 23 | impl IndexMut for CStr { 24 | fn index_mut(&mut self, _: RangeFull) -> &mut CStr { 25 | self 26 | } 27 | } 28 | 29 | impl Index> for CStr { 30 | type Output = CStr; 31 | fn index(&self, idx: RangeFrom) -> &CStr { 32 | unsafe { mem::cast(&self.0[idx]) } 33 | } 34 | } 35 | 36 | impl IndexMut> for CStr { 37 | fn index_mut(&mut self, idx: RangeFrom) -> &mut CStr { 38 | unsafe { mem::cast(&mut self.0[idx]) } 39 | } 40 | } 41 | 42 | impl Index> for CStr { 43 | type Output = NoNullStr; 44 | fn index(&self, idx: RangeTo) -> &NoNullStr { 45 | unsafe { mem::cast(&self.0[idx]) } 46 | } 47 | } 48 | 49 | impl IndexMut> for CStr { 50 | fn index_mut(&mut self, idx: RangeTo) -> &mut NoNullStr { 51 | unsafe { mem::cast(&mut self.0[idx]) } 52 | } 53 | } 54 | 55 | impl Index> for CStr { 56 | type Output = NoNullStr; 57 | fn index(&self, idx: Range) -> &NoNullStr { 58 | unsafe { mem::cast(&self.0[idx]) } 59 | } 60 | } 61 | 62 | impl IndexMut> for CStr { 63 | fn index_mut(&mut self, idx: Range) -> &mut NoNullStr { 64 | unsafe { mem::cast(&mut self.0[idx]) } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/tty/disc.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | #![allow(non_upper_case_globals, non_camel_case_types)] 6 | 7 | use base::prelude::*; 8 | use fmt::{Debug, Write}; 9 | use cty::{ 10 | self, c_int, 11 | }; 12 | 13 | #[derive(Pod, Eq)] 14 | pub struct LineDiscipline(pub c_int); 15 | 16 | macro_rules! create { 17 | ($($(#[$meta:meta])* disc $name:ident = $val:ident;)*) => { 18 | $($(#[$meta])* pub const $name: LineDiscipline = LineDiscipline(cty::$val);)* 19 | 20 | impl Debug for LineDiscipline { 21 | fn fmt(&self, mut w: &mut W) -> Result { 22 | let s = match *self { 23 | $($name => stringify!($name),)* 24 | _ => return write!(w, "Unknown({})", self.0), 25 | }; 26 | w.write_all(s.as_bytes()).ignore_ok() 27 | } 28 | } 29 | } 30 | } 31 | 32 | create! { 33 | disc Tty = N_TTY; 34 | disc Slip = N_SLIP; 35 | disc Mouse = N_MOUSE; 36 | disc Ppp = N_PPP; 37 | disc Strip = N_STRIP; 38 | disc Ax25 = N_AX25; 39 | disc X25 = N_X25; 40 | disc SixPack = N_6PACK; 41 | disc Masc = N_MASC; 42 | disc R3964 = N_R3964; 43 | disc ProfibusFdl = N_PROFIBUS_FDL; 44 | disc Irda = N_IRDA; 45 | disc Smsblock = N_SMSBLOCK; 46 | disc Hdlc = N_HDLC; 47 | disc SyncPpp = N_SYNC_PPP; 48 | disc Hci = N_HCI; 49 | disc GigasetM101 = N_GIGASET_M101; 50 | disc Slcan = N_SLCAN; 51 | disc Pps = N_PPS; 52 | disc V253 = N_V253; 53 | disc Caif = N_CAIF; 54 | disc Gsm0710 = N_GSM0710; 55 | disc TiWl = N_TI_WL; 56 | disc TraceSink = N_TRACESINK; 57 | disc TraceRouter = N_TRACEROUTER; 58 | } 59 | -------------------------------------------------------------------------------- /src/lrs/atomic.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | //! Atomic integers 6 | //! 7 | //! = Remarks 8 | //! 9 | //! This module contains integer wrappers with atomic operations. All types support the 10 | //! same operations: 11 | //! 12 | //! |=== 13 | //! | `new` | Creates a new object with the specified value. 14 | //! 15 | //! | `wrap` | Wraps the integer as an atomic integer. The integer must be aligned and \ 16 | //! must not be accessed non-atomically concurrently or the behavior is \ 17 | //! undefined. 18 | //! 19 | //! | `unwrap` | Returns a mutable pointer to the integer. 20 | //! 21 | //! | `load` | Loads the value. 22 | //! 23 | //! | `store` | Stores a new value. 24 | //! 25 | //! | `exchange` | Stores a new value and returns the old one. 26 | //! 27 | //! | `compare_exchange` | Compares the current value to a given one and if they match \ 28 | //! replaces the value by by a new one. Returns the old value. 29 | //! 30 | //! | `add` | Adds a value to the current value and returns the old value. 31 | //! 32 | //! | `sub`, `and`, `or`, `nand`, `xor` | Like `add`. 33 | //! 34 | //! | `min` | Stores the minimum of the current value and a new value. Returns the old \ 35 | //! value. 36 | //! 37 | //! | `max` | Like `min`. 38 | //! 39 | //! |=== 40 | //! 41 | //! The default ordering is sequentially consistent. The other available orderings are 42 | //! 43 | //! * `unordered`: No ordering guarantees but races with this mode are not undefined \ 44 | //! behavior. 45 | //! * `monotonic`: Relaxed in C++11. 46 | //! * `release`, `acquire`, `acquire_release`: As in C++11. 47 | //! 48 | //! See the C++11 standard for a concise description of these orderings. 49 | 50 | pub use lrs_atomic::{ 51 | fence_release, fence_acquire, fence_acquire_release, fence, Atomic, 52 | }; 53 | -------------------------------------------------------------------------------- /src/str_one/no_null_str/index.rs: -------------------------------------------------------------------------------- 1 | // This Source Code Form is subject to the terms of the Mozilla Public 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this 3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | 5 | use core::{mem}; 6 | use core::ops::{Index, IndexMut, Range, RangeFrom, RangeTo, RangeFull}; 7 | use {NoNullStr}; 8 | 9 | impl Index for NoNullStr { 10 | type Output = u8; 11 | fn index(&self, idx: usize) -> &u8 { 12 | &self.0[idx] 13 | } 14 | } 15 | 16 | impl Index for NoNullStr { 17 | type Output = NoNullStr; 18 | fn index(&self, _: RangeFull) -> &NoNullStr { self } 19 | } 20 | 21 | impl IndexMut for NoNullStr { 22 | fn index_mut(&mut self, _: RangeFull) -> &mut NoNullStr { self } 23 | } 24 | 25 | impl Index> for NoNullStr { 26 | type Output = NoNullStr; 27 | fn index(&self, idx: RangeTo) -> &NoNullStr { 28 | unsafe { mem::cast(&self.0[idx]) } 29 | } 30 | } 31 | 32 | impl IndexMut> for NoNullStr { 33 | fn index_mut(&mut self, idx: RangeTo) -> &mut NoNullStr { 34 | unsafe { mem::cast(&mut self.0[idx]) } 35 | } 36 | } 37 | 38 | impl Index> for NoNullStr { 39 | type Output = NoNullStr; 40 | fn index(&self, idx: RangeFrom) -> &NoNullStr { 41 | unsafe { mem::cast(&self.0[idx]) } 42 | } 43 | } 44 | 45 | impl IndexMut> for NoNullStr { 46 | fn index_mut(&mut self, idx: RangeFrom) -> &mut NoNullStr { 47 | unsafe { mem::cast(&mut self.0[idx]) } 48 | } 49 | } 50 | 51 | impl Index> for NoNullStr { 52 | type Output = NoNullStr; 53 | fn index(&self, idx: Range) -> &NoNullStr { 54 | unsafe { mem::cast(&self.0[idx]) } 55 | } 56 | } 57 | 58 | impl IndexMut> for NoNullStr { 59 | fn index_mut(&mut self, idx: Range) -> &mut NoNullStr { 60 | unsafe { mem::cast(&mut self.0[idx]) } 61 | } 62 | } 63 | --------------------------------------------------------------------------------