From 21aa67b74866fb4fc15d79b1ab1484308dbe4496 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 2 Aug 2020 16:08:56 +0800 Subject: [PATCH] workspace: remove workspace The kernel and userspace both need to use `xous`, but have different requirements. If we use a workspace, then all instances of `xous-rs` must have the same feature set. This breaks them apart so the kernel can have one set of features and programs can have another set. As part of this change, tests are now integrated into the kernel, and a new `create_process_as_thread()` and `wait_process_as_thread()` function pair have been added. Signed-off-by: Sean Cross --- Cargo.lock | 783 --------------------------------- Cargo.toml | 17 - examples/log/Cargo.toml | 2 + kernel/Cargo.toml | 2 +- kernel/src/arch/hosted.rs | 6 +- kernel/src/main.rs | 2 +- kernel/src/test.rs | 60 +-- xous-rs/src/arch/hosted.rs | 308 +++++++------ xous-rs/src/arch/mod.rs | 4 +- xous-rs/src/arch/native.rs | 156 +++++++ xous-rs/src/arch/native/mod.rs | 30 -- xous-rs/src/definitions.rs | 6 +- xous-rs/src/lib.rs | 3 + xous-rs/src/syscall.rs | 87 ++-- 14 files changed, 393 insertions(+), 1073 deletions(-) delete mode 100644 Cargo.lock delete mode 100644 Cargo.toml create mode 100644 xous-rs/src/arch/native.rs delete mode 100644 xous-rs/src/arch/native/mod.rs diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 65f4f488d..000000000 --- a/Cargo.lock +++ /dev/null @@ -1,783 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "addr2line" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543" -dependencies = [ - "gimli", -] - -[[package]] -name = "aho-corasick" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" -dependencies = [ - "memchr", -] - -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "backtrace" -version = "0.3.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "object", - "rustc-demangle", -] - -[[package]] -name = "bare-metal" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a" -dependencies = [ - "rustc_version", -] - -[[package]] -name = "bit_field" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "block-buffer" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array", -] - -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", -] - -[[package]] -name = "bstr" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502ae1441a0a5adb8fbd38a5955a6416b9493e92b465de5e4a9bde6a539c2c48" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - -[[package]] -name = "build_const" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" - -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - -[[package]] -name = "byteorder" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - -[[package]] -name = "c2-chacha" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" -dependencies = [ - "ppv-lite86", -] - -[[package]] -name = "cc" -version = "1.0.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "clap" -version = "2.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", -] - -[[package]] -name = "crc" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" -dependencies = [ - "build_const", -] - -[[package]] -name = "csv" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" -dependencies = [ - "bstr", - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - -[[package]] -name = "debug-here" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7791f83f55f330aa6406d71cc29d6d785ea1e2cf326001d7b2b45a5065efb1" -dependencies = [ - "lazy_static", - "which", - "winapi", -] - -[[package]] -name = "digest" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -dependencies = [ - "generic-array", -] - -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log 0.4.8", - "regex", - "termcolor", -] - -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", -] - -[[package]] -name = "generic-array" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" -dependencies = [ - "typenum", -] - -[[package]] -name = "getrandom" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" - -[[package]] -name = "hermit-abi" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" -dependencies = [ - "libc", -] - -[[package]] -name = "hex" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" - -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - -[[package]] -name = "itoa" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" - -[[package]] -name = "keccak" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" - -[[package]] -name = "kernel" -version = "0.1.0" -dependencies = [ - "bitflags", - "debug-here", - "hex", - "lazy_static", - "rand", - "riscv", - "sha3", - "stats_alloc", - "xous", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" - -[[package]] -name = "loader" -version = "0.1.0" -dependencies = [ - "lazy_static", - "rand", -] - -[[package]] -name = "log" -version = "0.1.0" -dependencies = [ - "pancurses", - "xous", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" - -[[package]] -name = "ncurses" -version = "5.99.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - -[[package]] -name = "num-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "num-traits" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -dependencies = [ - "autocfg", -] - -[[package]] -name = "object" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" - -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - -[[package]] -name = "pancurses" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3058bc37c433096b2ac7afef1c5cdfae49ede0a4ffec3dfc1df1df0959d0ff0" -dependencies = [ - "libc", - "log 0.4.8", - "ncurses", - "pdcurses-sys", - "winreg", -] - -[[package]] -name = "pdcurses-sys" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084dd22796ff60f1225d4eb6329f33afaf4c85419d51d440ab6b8c6f4529166b" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "pkg-config" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" - -[[package]] -name = "ppv-lite86" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" - -[[package]] -name = "proc-macro2" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - -[[package]] -name = "quote" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" -dependencies = [ - "c2-chacha", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - -[[package]] -name = "regex" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", - "thread_local", -] - -[[package]] -name = "regex-automata" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] - -[[package]] -name = "regex-syntax" -version = "0.6.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1" - -[[package]] -name = "riscv" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a12a859c86dbbcad4eb18daa0465932d907687abfa909c9cc0ca32dc237c8c3" -dependencies = [ - "bare-metal", - "bit_field", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "ryu" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - -[[package]] -name = "serde" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" - -[[package]] -name = "sha3" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" -dependencies = [ - "block-buffer", - "byte-tools", - "digest", - "keccak", - "opaque-debug", -] - -[[package]] -name = "shell" -version = "0.1.0" -dependencies = [ - "bitflags", - "xous", -] - -[[package]] -name = "stats_alloc" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a260c96bf26273969f360c2fc2e2c7732acc2ce49d939c7243c7230c2ad179d0" - -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "syn" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "termcolor" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "tests" -version = "0.1.1" -dependencies = [ - "bitflags", - "hex", - "lazy_static", - "rand", - "sha3", - "xous", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tools" -version = "0.1.0" -dependencies = [ - "bitflags", - "clap", - "crc", - "csv", - "env_logger", - "log 0.4.8", - "xmas-elf", -] - -[[package]] -name = "typenum" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" - -[[package]] -name = "unicode-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "vec_map" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" - -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "which" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" -dependencies = [ - "failure", - "libc", -] - -[[package]] -name = "winapi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "winreg" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a" -dependencies = [ - "winapi", -] - -[[package]] -name = "xmas-elf" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74de9a366f6ab8c405fa6b371d9ac24943921fa14b3d64afcb202065c405f11" -dependencies = [ - "zero", -] - -[[package]] -name = "xous" -version = "0.1.0" -dependencies = [ - "bitflags", - "hex", - "lazy_static", - "num-derive", - "num-traits", -] - -[[package]] -name = "zero" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1bc8a6b2005884962297587045002d8cfb8dcec9db332f4ca216ddc5de82c5" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index f66280c15..000000000 --- a/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[workspace] -members = [ - "kernel", - "tests", - "loader", - "tools", - "xous-rs", - "examples/shell", - "examples/log", -] -#default-members = ["xous-rs", "examples/shell", "examples/log"] - -[profile.release] -codegen-units = 1 # 1 better optimizations -debug = true # symbols are nice and they don't increase the size on Flash -lto = true -#opt-level=0 diff --git a/examples/log/Cargo.toml b/examples/log/Cargo.toml index d96b4207f..553e997ce 100644 --- a/examples/log/Cargo.toml +++ b/examples/log/Cargo.toml @@ -7,5 +7,7 @@ description = "Log output program" [dependencies] xous = { path = "../../xous-rs" } + +[target.'cfg(any(windows, unix))'.dependencies] #bracket-terminal = "0.8.1" pancurses = "*" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index f1d3d63fa..235934a6e 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -7,7 +7,7 @@ description = "Core kernel for Xous, including task switching and memory managem [dependencies] bitflags = "1.2.1" -xous = { path = "../xous-rs", features = ["forget-memory-messages"] } +xous = { path = "../xous-rs", features = ["forget-memory-messages", "processes-as-threads"] } debug-here = "0.2.2" stats_alloc = { version = "0.1.8", optional = true } sha3 = { default-features = false, version = "0.8.2" } diff --git a/kernel/src/arch/hosted.rs b/kernel/src/arch/hosted.rs index 892922647..9c7ab60e9 100644 --- a/kernel/src/arch/hosted.rs +++ b/kernel/src/arch/hosted.rs @@ -57,7 +57,7 @@ pub fn set_send_addr(send_addr: Sender) { }); } -#[cfg(not(feature = "testing"))] +#[cfg(not(test))] fn generate_pid_key() -> [u8; 16] { use rand::{thread_rng, Rng}; let mut process_key = [0u8; 16]; @@ -401,7 +401,7 @@ pub fn idle() -> bool { }) .unwrap_or_else(|_| NETWORK_LISTEN_ADDRESS.with(|nla| *nla.borrow())); - #[cfg(not(feature = "testing"))] + #[cfg(not(test))] let address_receiver = { let (sender, receiver) = channel(); set_send_addr(sender); @@ -416,7 +416,7 @@ pub fn idle() -> bool { .expect("couldn't spawn listen thread") }); - #[cfg(not(feature = "testing"))] + #[cfg(not(test))] { let address = address_receiver.recv().unwrap(); xous::arch::set_xous_address(address); diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 048af7cd8..f65647cb6 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -158,7 +158,7 @@ pub extern "C" fn kmain() { /// The main entrypoint when run in hosted mode. When running in embedded mode, /// this function does not exist. -#[cfg(all(not(baremetal),not(feature = "testing")))] +#[cfg(all(not(baremetal)))] fn main() { kmain(); } diff --git a/kernel/src/test.rs b/kernel/src/test.rs index a7105cf99..108714d5c 100644 --- a/kernel/src/test.rs +++ b/kernel/src/test.rs @@ -78,8 +78,8 @@ fn start_kernel(server_spec: &str) -> JoinHandle<()> { fn shutdown_kernel() { // Any process ought to be able to shut down the system currently. - xous::wait_process( - xous::create_process(xous::ProcessArgs::new("shutdown", || { + xous::wait_process_as_thread( + xous::create_process_as_thread(xous::ProcessArgsAsThread::new("shutdown", || { rsyscall(SysCall::Shutdown).expect("unable to shutdown server"); })) .expect("couldn't shut down the kernel"), @@ -126,7 +126,7 @@ fn send_scalar_message() { // and receive the message. Note that we need to communicate to the // "Client" what our server ID is. Normally this would be done via // an external nameserver. - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_scalar_message server", move || { let sid = @@ -148,7 +148,7 @@ fn send_scalar_message() { .expect("couldn't spawn server process"); // Spawn the client "process" and wait for the server address. - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_scalar_message client", move || { let sid = server_addr_recv.recv().unwrap(); @@ -169,8 +169,8 @@ fn send_scalar_message() { .expect("couldn't spawn client process"); // Wait for both processes to finish - crate::wait_process(xous_server).expect("couldn't join server process"); - crate::wait_process(xous_client).expect("couldn't join client process"); + crate::wait_process_as_thread(xous_server).expect("couldn't join server process"); + crate::wait_process_as_thread(xous_client).expect("couldn't join client process"); shutdown_kernel(); main_thread.join().expect("couldn't join kernel process"); @@ -185,7 +185,7 @@ fn send_move_message() { let (server_addr_send, server_addr_recv) = channel(); - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_move_message server", move || { // println!("SERVER: Creating server..."); @@ -212,7 +212,7 @@ fn send_move_message() { )) .expect("couldn't start server"); - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_move_message client", move || { // println!("CLIENT: Waiting for server address..."); @@ -228,8 +228,8 @@ fn send_move_message() { .expect("couldn't start client"); // Wait for both processes to finish - crate::wait_process(xous_server).expect("couldn't join server process"); - crate::wait_process(xous_client).expect("couldn't join client process"); + crate::wait_process_as_thread(xous_server).expect("couldn't join server process"); + crate::wait_process_as_thread(xous_client).expect("couldn't join client process"); // Any process ought to be able to shut down the system currently. shutdown_kernel(); @@ -244,7 +244,7 @@ fn send_borrow_message() { let test_str = "Hello, world!"; let test_bytes = test_str.as_bytes(); - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_borrow_message server", move || { // println!("SERVER: Creating server..."); @@ -272,7 +272,7 @@ fn send_borrow_message() { )) .expect("couldn't start server"); - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_borrow_message client", move || { // Get the server address (out of band) so we know what to connect to @@ -299,8 +299,8 @@ fn send_borrow_message() { .expect("couldn't start client"); // Wait for both processes to finish - crate::wait_process(xous_server).expect("couldn't join server process"); - crate::wait_process(xous_client).expect("couldn't join client process"); + crate::wait_process_as_thread(xous_server).expect("couldn't join server process"); + crate::wait_process_as_thread(xous_client).expect("couldn't join client process"); // Any process ought to be able to shut down the system currently. shutdown_kernel(); @@ -315,7 +315,7 @@ fn send_mutableborrow_message() { let test_str = "Hello, world!"; let test_bytes = test_str.as_bytes(); - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_mutableborrow_message server", move || { let sid = @@ -340,7 +340,7 @@ fn send_mutableborrow_message() { )) .expect("couldn't start server"); - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_mutableborrow_message client", move || { // Get the server address (out of band) so we know what to connect to @@ -368,8 +368,8 @@ fn send_mutableborrow_message() { .expect("couldn't start client"); // Wait for both processes to finish - crate::wait_process(xous_server).expect("couldn't join server process"); - crate::wait_process(xous_client).expect("couldn't join client process"); + crate::wait_process_as_thread(xous_server).expect("couldn't join server process"); + crate::wait_process_as_thread(xous_client).expect("couldn't join client process"); // Any process ought to be able to shut down the system currently. shutdown_kernel(); @@ -386,7 +386,7 @@ fn send_mutableborrow_message_repeat() { let loops = 50; - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_mutableborrow_message_repeat server", move || { let sid = @@ -413,7 +413,7 @@ fn send_mutableborrow_message_repeat() { )) .expect("couldn't start server"); - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "send_mutableborrow_message_repeat client", move || { // Get the server address (out of band) so we know what to connect to @@ -443,8 +443,8 @@ fn send_mutableborrow_message_repeat() { .expect("couldn't start client"); // Wait for both processes to finish - crate::wait_process(xous_server).expect("couldn't join server process"); - crate::wait_process(xous_client).expect("couldn't join client process"); + crate::wait_process_as_thread(xous_server).expect("couldn't join server process"); + crate::wait_process_as_thread(xous_client).expect("couldn't join client process"); // Any process ought to be able to shut down the system currently. shutdown_kernel(); @@ -486,7 +486,7 @@ fn server_client_same_process() { // Start the kernel in its own thread let main_thread = start_kernel(SERVER_SPEC); - let internal_server = xous::create_process(xous::arch::ProcessArgs::new( + let internal_server = xous::create_process_as_thread(xous::arch::ProcessArgsAsThread::new( "server_client_same_process process", || { let server = xous::create_server(b"s_c_same_process").expect("couldn't create server"); @@ -509,7 +509,7 @@ fn server_client_same_process() { )) .expect("couldn't start server"); - xous::wait_process(internal_server).expect("couldn't join internal_server process"); + xous::wait_process_as_thread(internal_server).expect("couldn't join internal_server process"); // Any process ought to be able to shut down the system currently. rsyscall(SysCall::Shutdown).expect("unable to shutdown server"); @@ -524,7 +524,7 @@ fn multiple_contexts() { // Start the kernel in its own thread let main_thread = start_kernel(SERVER_SPEC); - let internal_server = xous::create_process(xous::ProcessArgs::new( + let internal_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "multiple_contexts process", move || { let server = xous::create_server(b"multiple_context").expect("couldn't create server"); @@ -559,7 +559,7 @@ fn multiple_contexts() { )) .expect("couldn't create internal server"); - xous::wait_process(internal_server).expect("couldn't join internal_server process"); + xous::wait_process_as_thread(internal_server).expect("couldn't join internal_server process"); // Any process ought to be able to shut down the system currently. shutdown_kernel(); @@ -585,7 +585,7 @@ fn process_restart_server() { fn create_destroy_server(test_bytes: &'static [u8]) { let (server_addr_send, server_addr_recv) = channel(); - let xous_server = xous::create_process(xous::ProcessArgs::new( + let xous_server = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "process_restart_server server", move || { let sid = @@ -617,7 +617,7 @@ fn process_restart_server() { .expect("couldn't spawn server process"); // Wait for the server to start up - let xous_client = xous::create_process(xous::ProcessArgs::new( + let xous_client = xous::create_process_as_thread(xous::ProcessArgsAsThread::new( "process_restart_server client", move || { let sid = server_addr_recv.recv().unwrap(); @@ -629,8 +629,8 @@ fn process_restart_server() { )) .expect("couldn't start client process"); - xous::wait_process(xous_server).expect("couldn't join server process"); - xous::wait_process(xous_client).expect("couldn't join client process"); + xous::wait_process_as_thread(xous_server).expect("couldn't join server process"); + xous::wait_process_as_thread(xous_client).expect("couldn't join client process"); } // create_destroy_server(test_bytes); diff --git a/xous-rs/src/arch/hosted.rs b/xous-rs/src/arch/hosted.rs index 112fd0a77..36155a84c 100644 --- a/xous-rs/src/arch/hosted.rs +++ b/xous-rs/src/arch/hosted.rs @@ -26,180 +26,174 @@ pub struct ProcessInit { } #[cfg(feature = "processes-as-threads")] -mod process { - pub use super::*; - pub struct ProcessArgs { - main: F, - name: String, - } +pub struct ProcessArgsAsThread { + main: F, + name: String, +} - impl ProcessArgs - where - F: FnOnce(), - { - pub fn new(name: &str, main: F) -> ProcessArgs { - ProcessArgs { - main, - name: name.to_owned(), - } +#[cfg(feature = "processes-as-threads")] +impl ProcessArgsAsThread +where + F: FnOnce(), +{ + pub fn new(name: &str, main: F) -> ProcessArgsAsThread { + ProcessArgsAsThread { + main, + name: name.to_owned(), } } - pub struct ProcessHandle(std::thread::JoinHandle<()>); +} +#[cfg(feature = "processes-as-threads")] +pub struct ProcessHandleAsThread(std::thread::JoinHandle<()>); - /// If no connection exists, create a new connection to the server. This means - /// our parent PID will be PID1. Otherwise, reuse the same connection. - pub fn create_process_pre( - _args: &ProcessArgs, - ) -> core::result::Result - where - F: FnOnce(), - { - ensure_connection()?; +/// If no connection exists, create a new connection to the server. This means +/// our parent PID will be PID1. Otherwise, reuse the same connection. +#[cfg(feature = "processes-as-threads")] +pub fn create_process_pre_as_thread( + _args: &ProcessArgsAsThread, +) -> core::result::Result +where + F: FnOnce(), +{ + ensure_connection()?; - // Ensure there is a connection, because after this function returns - // we'll make a syscall with CreateProcess(). This should only need - // to happen for PID1. - Ok(ProcessInit { - key: PROCESS_KEY - .with(|pk| *pk.borrow()) - .unwrap_or_else(default_process_key), - }) - } + // Ensure there is a connection, because after this function returns + // we'll make a syscall with CreateProcess(). This should only need + // to happen for PID1. + Ok(ProcessInit { + key: PROCESS_KEY + .with(|pk| *pk.borrow()) + .unwrap_or_else(default_process_key), + }) +} - pub fn create_process_post( - args: ProcessArgs, - init: ProcessInit, - pid: PID, - ) -> core::result::Result - where - F: FnOnce() + Send + 'static, - { - let server_address = xous_address(); +#[cfg(feature = "processes-as-threads")] +pub fn create_process_post_as_thread( + args: ProcessArgsAsThread, + init: ProcessInit, + pid: PID, +) -> core::result::Result +where + F: FnOnce() + Send + 'static, +{ + let server_address = xous_address(); - let f = args.main; - let thread_main = std::thread::Builder::new() - .name(args.name) - .spawn(move || { - set_xous_address(server_address); - THREAD_ID.with(|tid| *tid.borrow_mut() = 1); - PROCESS_ID.with(|p| *p.borrow_mut() = pid); - XOUS_SERVER_CONNECTION.with(|xsc| { - let mut xsc = xsc.borrow_mut(); - match xous_connect_impl(server_address, &init.key) { - Ok(a) => { - *xsc = Some(a); - Ok(()) - } - Err(_) => Err(crate::Error::InternalError), + let f = args.main; + let thread_main = std::thread::Builder::new() + .name(args.name) + .spawn(move || { + set_xous_address(server_address); + THREAD_ID.with(|tid| *tid.borrow_mut() = 1); + PROCESS_ID.with(|p| *p.borrow_mut() = pid); + XOUS_SERVER_CONNECTION.with(|xsc| { + let mut xsc = xsc.borrow_mut(); + match xous_connect_impl(server_address, &init.key) { + Ok(a) => { + *xsc = Some(a); + Ok(()) } - })?; + Err(_) => Err(crate::Error::InternalError), + } + })?; - crate::create_thread(f) - }) - .map_err(|_| crate::Error::InternalError)? - .join() - .unwrap() - .unwrap(); - - Ok(ProcessHandle(thread_main.0)) - } - - pub fn wait_process(joiner: ProcessHandle) -> crate::SysCallResult { - joiner.0.join().map(|_| Result::Ok).map_err(|_x| { - // panic!("wait error: {:?}", x); - crate::Error::InternalError + crate::create_thread(f) }) - } + .map_err(|_| crate::Error::InternalError)? + .join() + .unwrap() + .unwrap(); + + Ok(ProcessHandleAsThread(thread_main.0)) } -#[cfg(not(feature = "processes-as-threads"))] -mod process { - pub use super::*; - pub struct ProcessArgs { - command: String, - name: String, - } +#[cfg(feature = "processes-as-threads")] +pub fn wait_process_as_thread(joiner: ProcessHandleAsThread) -> crate::SysCallResult { + joiner.0.join().map(|_| Result::Ok).map_err(|_x| { + // panic!("wait error: {:?}", x); + crate::Error::InternalError + }) +} - impl ProcessArgs { - pub fn new(name: &str, command: String) -> ProcessArgs { - ProcessArgs { - command, - name: name.to_owned(), - } +pub struct ProcessArgs { + command: String, + name: String, +} + +impl ProcessArgs { + pub fn new(name: &str, command: String) -> ProcessArgs { + ProcessArgs { + command, + name: name.to_owned(), } } - - #[derive(Debug)] - pub struct ProcessHandle(std::process::Child); - - /// If no connection exists, create a new connection to the server. This means - /// our parent PID will be PID1. Otherwise, reuse the same connection. - pub fn create_process_pre( - _args: &ProcessArgs, - ) -> core::result::Result { - ensure_connection()?; - - // Ensure there is a connection, because after this function returns - // we'll make a syscall with CreateProcess(). This should only need - // to happen for PID1. - Ok(ProcessInit { - key: PROCESS_KEY - .with(|pk| *pk.borrow()) - .unwrap_or_else(default_process_key), - }) - } - - pub fn create_process_post( - args: ProcessArgs, - init: ProcessInit, - pid: PID, - ) -> core::result::Result { - use std::process::Command; - let server_env = format!("{}", xous_address()); - let pid_env = format!("{}", pid); - let process_name_env = args.name.to_string(); - let process_key_env = hex::encode(&init.key.0); - let (shell, args) = if cfg!(windows) { - ("cmd", ["/C", &args.command]) - } else if cfg!(unix) { - ("sh", ["-c", &args.command]) - } else { - panic!("unrecognized platform -- don't know how to shell out"); - }; - - println!("Launching process..."); - let result = Command::new(shell) - .args(&args) - .env("XOUS_SERVER", server_env) - .env("XOUS_PID", pid_env) - .env("XOUS_PROCESS_NAME", process_name_env) - .env("XOUS_PROCESS_KEY", process_key_env) - .spawn() - .map(ProcessHandle) - .map_err(|e| { - eprintln!("couldn't start command: {}", e); - crate::Error::InternalError - }); - // println!("Process result: {:?}", result); - result - } - - pub fn wait_process(mut joiner: ProcessHandle) -> crate::SysCallResult { - joiner - .0 - .wait() - .or(Err(crate::Error::InternalError)) - .and_then(|e| { - if e.success() { - Ok(crate::Result::Ok) - } else { - Err(crate::Error::UnknownError) - } - }) - } } -pub use process::*; +#[derive(Debug)] +pub struct ProcessHandle(std::process::Child); + +/// If no connection exists, create a new connection to the server. This means +/// our parent PID will be PID1. Otherwise, reuse the same connection. +pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result { + ensure_connection()?; + + // Ensure there is a connection, because after this function returns + // we'll make a syscall with CreateProcess(). This should only need + // to happen for PID1. + Ok(ProcessInit { + key: PROCESS_KEY + .with(|pk| *pk.borrow()) + .unwrap_or_else(default_process_key), + }) +} + +pub fn create_process_post( + args: ProcessArgs, + init: ProcessInit, + pid: PID, +) -> core::result::Result { + use std::process::Command; + let server_env = format!("{}", xous_address()); + let pid_env = format!("{}", pid); + let process_name_env = args.name.to_string(); + let process_key_env = hex::encode(&init.key.0); + let (shell, args) = if cfg!(windows) { + ("cmd", ["/C", &args.command]) + } else if cfg!(unix) { + ("sh", ["-c", &args.command]) + } else { + panic!("unrecognized platform -- don't know how to shell out"); + }; + + println!("Launching process..."); + let result = Command::new(shell) + .args(&args) + .env("XOUS_SERVER", server_env) + .env("XOUS_PID", pid_env) + .env("XOUS_PROCESS_NAME", process_name_env) + .env("XOUS_PROCESS_KEY", process_key_env) + .spawn() + .map(ProcessHandle) + .map_err(|e| { + eprintln!("couldn't start command: {}", e); + crate::Error::InternalError + }); + // println!("Process result: {:?}", result); + result +} + +pub fn wait_process(mut joiner: ProcessHandle) -> crate::SysCallResult { + joiner + .0 + .wait() + .or(Err(crate::Error::InternalError)) + .and_then(|e| { + if e.success() { + Ok(crate::Result::Ok) + } else { + Err(crate::Error::UnknownError) + } + }) +} pub struct WaitHandle(std::thread::JoinHandle); diff --git a/xous-rs/src/arch/mod.rs b/xous-rs/src/arch/mod.rs index 2b03fa250..d4d658e1d 100644 --- a/xous-rs/src/arch/mod.rs +++ b/xous-rs/src/arch/mod.rs @@ -1,6 +1,6 @@ -#[cfg(not(any(windows,unix)))] +#[cfg(baremetal)] pub mod native; -#[cfg(not(any(windows,unix)))] +#[cfg(baremetal)] pub use native::*; #[cfg(any(windows,unix))] diff --git a/xous-rs/src/arch/native.rs b/xous-rs/src/arch/native.rs new file mode 100644 index 000000000..08480fe97 --- /dev/null +++ b/xous-rs/src/arch/native.rs @@ -0,0 +1,156 @@ +use crate::{Error, MemoryAddress, PID, TID}; +use core::convert::TryInto; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct ProcessArgs { + name: [u8; 16], +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct ThreadInit { + call: fn(data: *const usize) -> usize, + stack: MemoryAddress, + arg: Option, + name: [u8; 16], +} + +#[derive(Copy, Clone, Debug, PartialEq)] +pub struct ProcessKey([u8; 16]); +impl ProcessKey { + pub fn new(key: [u8; 16]) -> ProcessKey { + ProcessKey(key) + } +} + +#[derive(Copy, Clone, Debug, PartialEq)] +pub struct ProcessInit { + pub key: ProcessKey, +} + +pub struct WaitHandle(core::marker::PhantomData); +pub struct ProcessHandle(()); + +pub fn thread_to_args(call: usize, init: ThreadInit) -> [usize; 8] { + [ + call as usize, + init.call as usize, + init.stack.get(), + init.arg.map(|x| x.get()).unwrap_or_default(), + 0, + 0, + 0, + 0, + ] +} + +/// This code is executed inside the kernel. It takes the list of args +/// that were passed via registers and converts them into a `ThreadInit` +/// struct with enough information to start the new thread. +pub fn args_to_thread( + a1: usize, + a2: usize, + a3: usize, + a4: usize, + a5: usize, + a6: usize, + a7: usize, +) -> core::result::Result { + todo!() + // let call = unsafe { core::mem::transmute:: usize; + // let stack = MemoryAddress::new(a2).ok_or(Error::InvalidSyscall)?; + // let arg = MemoryAddress::new(a2); + // Ok(ThreadInit { + // call, + // stack, + // arg, + // name: [8u8; 16], + // }) +} + +pub fn create_thread_pre(_f: &F) -> core::result::Result +where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, +{ + todo!() + // Ok(ThreadInit {}) +} + +pub fn create_thread_post( + _f: F, + _thread_id: TID, +) -> core::result::Result, crate::Error> +where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, +{ + todo!() + // let server_address = xous_address(); + // let server_connection = + // XOUS_SERVER_CONNECTION.with(|xsc| xsc.borrow().as_ref().unwrap().clone()); + // let process_id = PROCESS_ID.with(|pid| *pid.borrow()); + // Ok(std::thread::Builder::new() + // .spawn(move || { + // set_xous_address(server_address); + // THREAD_ID.with(|tid| *tid.borrow_mut() = thread_id); + // PROCESS_ID.with(|pid| *pid.borrow_mut() = process_id); + // XOUS_SERVER_CONNECTION.with(|xsc| *xsc.borrow_mut() = Some(server_connection)); + // f() + // }) + // .map(WaitHandle) + // .map_err(|_| crate::Error::InternalError)?) +} + +pub fn wait_thread(_joiner: WaitHandle) -> crate::SysCallResult { + todo!() + // joiner + // .0 + // .join() + // .map(|_| Result::Ok) + // .map_err(|_| crate::Error::InternalError) +} + +pub fn process_to_args(call: usize, init: &ProcessInit) -> [usize; 8] { + [ + call, + u32::from_le_bytes(init.key.0[0..4].try_into().unwrap()) as _, + u32::from_le_bytes(init.key.0[4..8].try_into().unwrap()) as _, + u32::from_le_bytes(init.key.0[8..12].try_into().unwrap()) as _, + u32::from_le_bytes(init.key.0[12..16].try_into().unwrap()) as _, + 0, + 0, + 0, + ] +} + +pub fn args_to_process( + a1: usize, + a2: usize, + a3: usize, + a4: usize, + _a5: usize, + _a6: usize, + _a7: usize, +) -> core::result::Result { + todo!() +} + +/// If no connection exists, create a new connection to the server. This means +/// our parent PID will be PID1. Otherwise, reuse the same connection. +pub fn create_process_pre(_args: &ProcessArgs) -> core::result::Result { + todo!() +} + +pub fn create_process_post( + _args: ProcessArgs, + _init: ProcessInit, + _pid: PID, +) -> core::result::Result { + todo!() +} + +pub fn wait_process(_joiner: ProcessHandle) -> crate::SysCallResult { + todo!() +} diff --git a/xous-rs/src/arch/native/mod.rs b/xous-rs/src/arch/native/mod.rs deleted file mode 100644 index 91aa13101..000000000 --- a/xous-rs/src/arch/native/mod.rs +++ /dev/null @@ -1,30 +0,0 @@ -// pub mod syscall; -// pub use syscall::*; -pub fn context_to_args(call: usize, _init: ContextInit) -> [usize; 8] { - [ - SysCallNumber::CreateThread as usize, - a1.get(), - a2.get(), - a3.map(|x| x.get()).unwrap_or_default(), - 0, - 0, - 0, - 0, - ] -} - -pub fn args_to_context( - a1: usize, - a2: usize, - a3: usize, - a4: usize, - a5: usize, - a6: usize, - a7: usize, -) -> core::result::Result { - Ok(( - MemoryAddress::new(a1).ok_or(Error::InvalidSyscall)?, - MemoryAddress::new(a2).ok_or(Error::InvalidSyscall)?, - MemoryAddress::new(a3), - )) -} diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index 403144db8..19da795e5 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -43,7 +43,7 @@ impl SID { } } -impl std::str::FromStr for SID { +impl core::str::FromStr for SID { type Err = (); fn from_str(s: &str) -> core::result::Result { @@ -322,8 +322,8 @@ impl MessageEnvelope { impl Drop for MessageEnvelope { fn drop(&mut self) { match &self.message { - Message::ImmutableBorrow(x) | Message::MutableBorrow(x) => { - crate::syscall::return_memory(self.sender, x.buf.addr.get(), x.buf.size.get()) + Message::Borrow(x) | Message::MutableBorrow(x) => { + crate::syscall::return_memory(self.sender, x.buf) .expect("couldn't return memory") } Message::Move(msg) => crate::syscall::unmap_memory(msg.buf.addr, msg.buf.size) diff --git a/xous-rs/src/lib.rs b/xous-rs/src/lib.rs index 59a90b0bc..4d2c8c105 100644 --- a/xous-rs/src/lib.rs +++ b/xous-rs/src/lib.rs @@ -17,6 +17,9 @@ pub use definitions::*; pub use messages::*; pub use syscall::*; +#[cfg(feature = "processes-as-threads")] +pub use arch::ProcessArgsAsThread; + /// Convert a four-letter string into a 32-bit int. #[macro_export] macro_rules! make_name { diff --git a/xous-rs/src/syscall.rs b/xous-rs/src/syscall.rs index 17b9e4853..ef05ad058 100644 --- a/xous-rs/src/syscall.rs +++ b/xous-rs/src/syscall.rs @@ -6,6 +6,9 @@ use crate::{ use num_derive::FromPrimitive; use num_traits::FromPrimitive; +#[cfg(feature = "processes-as-threads")] +use crate::ProcessArgsAsThread; + #[derive(Debug, PartialEq)] pub enum SysCall { /// Allocates pages of memory, equal to a total of `size` bytes. A physical @@ -577,7 +580,9 @@ impl SysCall { Some(SysCallNumber::CreateServer) => { SysCall::CreateServer(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _)) } - Some(SysCallNumber::Connect) => SysCall::Connect(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _)), + Some(SysCallNumber::Connect) => { + SysCall::Connect(SID::from_u32(a1 as _, a2 as _, a3 as _, a4 as _)) + } Some(SysCallNumber::SendMessage) => match a2 { 1 => SysCall::SendMessage( a1, @@ -776,7 +781,6 @@ pub fn receive_message(server: SID) -> core::result::Result(joiner: crate::arch::WaitHandle) -> SysCallResult { /// Create a new process by running it in its own thread #[cfg(feature = "processes-as-threads")] -mod process { - use super::*; - pub fn create_process( - args: ProcessArgs, - ) -> core::result::Result - where - F: FnOnce() + Send + 'static, - { - let process_init = crate::arch::create_process_pre(&args)?; - rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| { - if let Result::ProcessID(pid) = result { - crate::arch::create_process_post(args, process_init, pid) - } else { - Err(Error::InternalError) - } - }) - } - - /// Wait for a thread to finish - pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult { - crate::arch::wait_process(joiner) - } +pub fn create_process_as_thread( + args: ProcessArgsAsThread, +) -> core::result::Result +where + F: FnOnce() + Send + 'static, +{ + let process_init = crate::arch::create_process_pre_as_thread(&args)?; + rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| { + if let Result::ProcessID(pid) = result { + crate::arch::create_process_post_as_thread(args, process_init, pid) + } else { + Err(Error::InternalError) + } + }) } -#[cfg(not(feature = "processes-as-threads"))] -mod process { - use super::*; - pub fn create_process( - args: ProcessArgs, - ) -> core::result::Result - { - let process_init = crate::arch::create_process_pre(&args)?; - rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| { - if let Result::ProcessID(pid) = result { - crate::arch::create_process_post(args, process_init, pid) - } else { - Err(Error::InternalError) - } - }) - } - - /// Wait for a thread to finish - pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult { - crate::arch::wait_process(joiner) - } +/// Wait for a thread to finish +#[cfg(feature = "processes-as-threads")] +pub fn wait_process_as_thread(joiner: crate::arch::ProcessHandleAsThread) -> SysCallResult { + crate::arch::wait_process_as_thread(joiner) } -pub use process::*; +pub fn create_process( + args: ProcessArgs, +) -> core::result::Result { + let process_init = crate::arch::create_process_pre(&args)?; + rsyscall(SysCall::CreateProcess(process_init)).and_then(|result| { + if let Result::ProcessID(pid) = result { + crate::arch::create_process_post(args, process_init, pid) + } else { + Err(Error::InternalError) + } + }) +} + +/// Wait for a thread to finish +pub fn wait_process(joiner: crate::arch::ProcessHandle) -> SysCallResult { + crate::arch::wait_process(joiner) +} pub fn rsyscall(call: SysCall) -> SysCallResult { let mut ret = Result::Ok;