diff --git a/.gitattributes b/.gitattributes index 8675e119a..56078daf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,8 @@ -src/kxos-user/hello_world/hello_world filter=lfs diff=lfs merge=lfs -text -src/kxos-user/fork/fork filter=lfs diff=lfs merge=lfs -text -src/kxos-user/hello_c/hello filter=lfs diff=lfs merge=lfs -text -src/kxos-user/execve/execve filter=lfs diff=lfs merge=lfs -text -src/kxos-user/execve/hello filter=lfs diff=lfs merge=lfs -text -src/kxos-user/fork_c/fork filter=lfs diff=lfs merge=lfs -text -src/kxos-user/signal_c/signal_test filter=lfs diff=lfs merge=lfs -text -src/kxos-user/busybox/busybox filter=lfs diff=lfs merge=lfs -text \ No newline at end of file +src/apps/hello_world/hello_world filter=lfs diff=lfs merge=lfs -text +src/apps/fork/fork filter=lfs diff=lfs merge=lfs -text +src/appshello_c/hello filter=lfs diff=lfs merge=lfs -text +src/apps/execve/execve filter=lfs diff=lfs merge=lfs -text +src/apps/execve/hello filter=lfs diff=lfs merge=lfs -text +src/apps/fork_c/fork filter=lfs diff=lfs merge=lfs -text +src/apps/signal_c/signal_test filter=lfs diff=lfs merge=lfs -text +src/apps/busybox/busybox filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/README.md b/README.md index 97254ccd0..dbd77bcf9 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ -# KxOS +# Jinux -KxOS is a modern and secure OS kernel written in Rust, especially suitable for Trusted Execution Environments (TEEs) +Jinux is a modern and secure OS kernel written in Rust, especially suitable for Trusted Execution Environments (TEEs) ## Design Goals -**1. Security by design.** Security is our top priority in the design of KxOS. As such, we adopt the widely acknowledged security best practice of [least privilege principle](https://en.wikipedia.org/wiki/Principle_of_least_privilege) and enforce it in a fashion that leverages the full strengths of Rust. To do so, we partition KxOS into two halves: a _privileged_ OS core and _unprivileged_ OS components. As a result, we can write the OS components almost entirely in _safe_ Rust, while taking extra cautions with the _unsafe_ Rust code in the OS core. Furthermore, we propose the idea of _everything-is-a-capability_, which elevates the status of [capabilities](https://en.wikipedia.org/wiki/Capability-based_security) to the level of a ubiquitous security primitive used throughout the OS. We make novel use of Rust's advanced features (e.g., [type-level programming](https://willcrichton.net/notes/type-level-programming/)) to make capabilities more accessible and efficient. The net result is improved security and uncompromised performance. +**1. Security by design.** Security is our top priority in the design of Jinux. As such, we adopt the widely acknowledged security best practice of [least privilege principle](https://en.wikipedia.org/wiki/Principle_of_least_privilege) and enforce it in a fashion that leverages the full strengths of Rust. To do so, we partition Jinux into two halves: a _privileged_ OS core and _unprivileged_ OS components. As a result, we can write the OS components almost entirely in _safe_ Rust, while taking extra cautions with the _unsafe_ Rust code in the OS core. Furthermore, we propose the idea of _everything-is-a-capability_, which elevates the status of [capabilities](https://en.wikipedia.org/wiki/Capability-based_security) to the level of a ubiquitous security primitive used throughout the OS. We make novel use of Rust's advanced features (e.g., [type-level programming](https://willcrichton.net/notes/type-level-programming/)) to make capabilities more accessible and efficient. The net result is improved security and uncompromised performance. -**2. Trustworthy OS-level virtualization.** OS-level virtualization mechanisms (like Linux's cgroups and namespaces) enable containers, a more lightweight and arguably more popular alternative to virtual machines (VMs). But there is one problem with containers: they are not as secure as VMs (see [StackExchange](https://security.stackexchange.com/questions/169642/what-makes-docker-more-secure-than-vms-or-bare-metal), [LWN](https://lwn.net/Articles/796700/), and [AWS](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/security-tasks-containers.html)). There is a real risk that malicious containers may exploit privilege escalation bugs in the OS kernel to attack the host. [A study](https://dl.acm.org/doi/10.1145/3274694.3274720) found that 11 out of 88 kernel exploits are effective in breaking the container sandbox. The seemingly inherent insecurity of OS kernels leads to a new breed of container implementations (e.g., [Kata](https://katacontainers.io/) and [gVisor](https://gvisor.dev/)) that are based on VMs, instead of kernels, for isolation and sandboxing. We argue that this unfortunate retreat from OS-level virtualization to VM-based one is unwarranted---if the OS kernels are secure enough. And this is exactly what we plan to achieve with KxOS. We aim to provide a trustworthy OS-level virtualization mechanism on KxOS. +**2. Trustworthy OS-level virtualization.** OS-level virtualization mechanisms (like Linux's cgroups and namespaces) enable containers, a more lightweight and arguably more popular alternative to virtual machines (VMs). But there is one problem with containers: they are not as secure as VMs (see [StackExchange](https://security.stackexchange.com/questions/169642/what-makes-docker-more-secure-than-vms-or-bare-metal), [LWN](https://lwn.net/Articles/796700/), and [AWS](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/security-tasks-containers.html)). There is a real risk that malicious containers may exploit privilege escalation bugs in the OS kernel to attack the host. [A study](https://dl.acm.org/doi/10.1145/3274694.3274720) found that 11 out of 88 kernel exploits are effective in breaking the container sandbox. The seemingly inherent insecurity of OS kernels leads to a new breed of container implementations (e.g., [Kata](https://katacontainers.io/) and [gVisor](https://gvisor.dev/)) that are based on VMs, instead of kernels, for isolation and sandboxing. We argue that this unfortunate retreat from OS-level virtualization to VM-based one is unwarranted---if the OS kernels are secure enough. And this is exactly what we plan to achieve with Jinux. We aim to provide a trustworthy OS-level virtualization mechanism on Jinux. -**3. High-velocity development.** Traditional OS kernels like Linux are hard to develop, test, and debug. Kernel development involves countless rounds of programming, failing, and rebooting on bare-metal or virtual machines. This way of life is unproductive and painful. Such a pain point is also recognized and partially addressed by [research work](https://www.usenix.org/conference/fast21/presentation/miller), but we think we can do more. In this spirit, we design the OS core to provide high-level APIs that are largely independent of the underlying hardware and implement it with two targets: one target is as part of a regular OS in kernel space and the other is as a library OS in user space. This way, all the OS components of KxOS, which are stacked above the OS core, can be developed, tested, and debugged in user space, which is more friendly to developers than kernel space. +**3. High-velocity development.** Traditional OS kernels like Linux are hard to develop, test, and debug. Kernel development involves countless rounds of programming, failing, and rebooting on bare-metal or virtual machines. This way of life is unproductive and painful. Such a pain point is also recognized and partially addressed by [research work](https://www.usenix.org/conference/fast21/presentation/miller), but we think we can do more. In this spirit, we design the OS core to provide high-level APIs that are largely independent of the underlying hardware and implement it with two targets: one target is as part of a regular OS in kernel space and the other is as a library OS in user space. This way, all the OS components of Jinux, which are stacked above the OS core, can be developed, tested, and debugged in user space, which is more friendly to developers than kernel space. -**4. High-fidelity Linux ABI.** An OS without usable applications is useless. So we believe it is important for KxOS to fit in an established and thriving ecosystem of software, such as the one around Linux. This is why we conclude that KxOS should aim at implementing high-fidelity Linux ABI, including the system calls, the proc file system, etc. +**4. High-fidelity Linux ABI.** An OS without usable applications is useless. So we believe it is important for Jinux to fit in an established and thriving ecosystem of software, such as the one around Linux. This is why we conclude that Jinux should aim at implementing high-fidelity Linux ABI, including the system calls, the proc file system, etc. ## Architecture -Here is an overview of the architecture of KxOS. +Here is an overview of the architecture of Jinux. ![architecture overview](docs/figures/arch_overview.png) ## Roadmap -While there is nothing revolutionary in KxOS, it does explore some new design points in constructing secure Rust OSes. To minimize the risks of the project, we plan to move towards Minimal Viable Product (MVP) in iterations. +While there is nothing revolutionary in Jinux, it does explore some new design points in constructing secure Rust OSes. To minimize the risks of the project, we plan to move towards Minimal Viable Product (MVP) in iterations. - [ ] Iteration 1: Build a minimal OS core runnable in both VMs and user space. - [ ] Iteration 2: Build a minimal set of OS components to run simple programs diff --git a/docs/README.md b/docs/README.md index b4c9b3445..501530b42 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# KxOS Documentation +# Jinux Documentation The documentation is rendered as a book with [mdBook](https://rust-lang.github.io/mdBook/), which can be installed with `cargo`. diff --git a/docs/book.toml b/docs/book.toml index 7a7ed5602..99f587534 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -3,7 +3,7 @@ authors = ["Tate, Hongliang Tian"] language = "en" multilingual = false src = "src" -title = "KxOS: A Secure, Fast, and Modern OS in Rust" +title = "Jinux: A Secure, Fast, and Modern OS in Rust" [rust] edition = "2021" diff --git a/docs/src/README.md b/docs/src/README.md index eadc2837f..5f3ab2fa9 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -14,7 +14,7 @@ # Introduction -This document describes KxOS, a secure, fast, and modern OS written in Rust. +This document describes Jinux, a secure, fast, and modern OS written in Rust. As the project is a work in progress, this document is by no means complete. Despite the incompleteness, this evolving document serves several important purposes: @@ -50,7 +50,7 @@ OSes, e.g., [Kerla](https://github.com/nuta/kerla), and [zCore](https://github.com/rcore-os/zCore). Despite their varying degrees of success, none of them are general-purpose, industrial-strength OSes that are or will ever be competitive with Linux. Eventually, a winner will emerge out of this -market of Rust OSes, and KxOS is our bet for this competition. +market of Rust OSes, and Jinux is our bet for this competition. Second, Rust OSes are a perfect fit for [Trusted Execution Environments (TEEs)](https://en.wikipedia.org/wiki/Trusted_execution_environment). @@ -79,24 +79,24 @@ relational databases: [Oracle and IBM are losing ground as Chinese vendors catch up with their US counterparts](https://www.theregister.com/2022/07/06/international_database_vendors_are_losing/). Can such success stories be repeated in the field of OSes? I think so. There are some China's home-grown OSes like [openKylin](https://www.openkylin.top/index.php?lang=en), but all of them are based on Linux and lack a self-developed -OS _kernel_. The long-term goal of KxOS is to fill this key missing core of the home-grown OSes. +OS _kernel_. The long-term goal of Jinux is to fill this key missing core of the home-grown OSes. ## Architecture Overview -Here is an overview of the architecture of KxOS. +Here is an overview of the architecture of Jinux. ![architecture overview](images/arch_overview.png) ## Features -**1. Security by design.** Security is our top priority in the design of KxOS. As such, we adopt the widely acknowledged security best practice of [least privilege principle](https://en.wikipedia.org/wiki/Principle_of_least_privilege) and enforce it in a fashion that leverages the full strengths of Rust. To do so, we partition KxOS into two halves: a _privileged_ OS core and _unprivileged_ OS components. All OS components are written entirely in _safe_ Rust and only the privileged OS core +**1. Security by design.** Security is our top priority in the design of Jinux. As such, we adopt the widely acknowledged security best practice of [least privilege principle](https://en.wikipedia.org/wiki/Principle_of_least_privilege) and enforce it in a fashion that leverages the full strengths of Rust. To do so, we partition Jinux into two halves: a _privileged_ OS core and _unprivileged_ OS components. All OS components are written entirely in _safe_ Rust and only the privileged OS core is allowed to have _unsafe_ Rust code. Furthermore, we propose the idea of _everything-is-a-capability_, which elevates the status of [capabilities](https://en.wikipedia.org/wiki/Capability-based_security) to the level of a ubiquitous security primitive used throughout the OS. We make novel use of Rust's advanced features (e.g., [type-level programming](https://willcrichton.net/notes/type-level-programming/)) to make capabilities more accessible and efficient. The net result is improved security and uncompromised performance. -**2. Trustworthy OS-level virtualization.** OS-level virtualization mechanisms (like Linux's cgroups and namespaces) enable containers, a more lightweight and arguably more popular alternative to virtual machines (VMs). But there is one problem with containers: they are not as secure as VMs (see [StackExchange](https://security.stackexchange.com/questions/169642/what-makes-docker-more-secure-than-vms-or-bare-metal), [LWN](https://lwn.net/Articles/796700/), and [AWS](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/security-tasks-containers.html)). There is a real risk that malicious containers may exploit privilege escalation bugs in the OS kernel to attack the host. [A study](https://dl.acm.org/doi/10.1145/3274694.3274720) found that 11 out of 88 kernel exploits are effective in breaking the container sandbox. The seemingly inherent insecurity of OS kernels leads to a new breed of container implementations (e.g., [Kata](https://katacontainers.io/) and [gVisor](https://gvisor.dev/)) that are based on VMs, instead of kernels, for isolation and sandboxing. We argue that this unfortunate retreat from OS-level virtualization to VM-based one is unwarranted---if the OS kernels are secure enough. And this is exactly what we plan to achieve with KxOS. We aim to provide a trustworthy OS-level virtualization mechanism on KxOS. +**2. Trustworthy OS-level virtualization.** OS-level virtualization mechanisms (like Linux's cgroups and namespaces) enable containers, a more lightweight and arguably more popular alternative to virtual machines (VMs). But there is one problem with containers: they are not as secure as VMs (see [StackExchange](https://security.stackexchange.com/questions/169642/what-makes-docker-more-secure-than-vms-or-bare-metal), [LWN](https://lwn.net/Articles/796700/), and [AWS](https://docs.aws.amazon.com/AmazonECS/latest/bestpracticesguide/security-tasks-containers.html)). There is a real risk that malicious containers may exploit privilege escalation bugs in the OS kernel to attack the host. [A study](https://dl.acm.org/doi/10.1145/3274694.3274720) found that 11 out of 88 kernel exploits are effective in breaking the container sandbox. The seemingly inherent insecurity of OS kernels leads to a new breed of container implementations (e.g., [Kata](https://katacontainers.io/) and [gVisor](https://gvisor.dev/)) that are based on VMs, instead of kernels, for isolation and sandboxing. We argue that this unfortunate retreat from OS-level virtualization to VM-based one is unwarranted---if the OS kernels are secure enough. And this is exactly what we plan to achieve with Jinux. We aim to provide a trustworthy OS-level virtualization mechanism on Jinux. -**3. Fast user-mode development.** Traditional OS kernels like Linux are hard to develop, test, and debug. Kernel development involves countless rounds of programming, failing, and rebooting on bare-metal or virtual machines. This way of life is unproductive and painful. Such a pain point is also recognized and partially addressed by [research work](https://www.usenix.org/conference/fast21/presentation/miller), but we think we can do more. In this spirit, we design the OS core to provide high-level APIs that are largely independent of the underlying hardware and implement it with two targets: one target is as part of a regular OS in kernel space and the other is as a library OS in user space. This way, all the OS components of KxOS, which are stacked above the OS core, can be developed, tested, and debugged in user space, which is more friendly to developers than kernel space. +**3. Fast user-mode development.** Traditional OS kernels like Linux are hard to develop, test, and debug. Kernel development involves countless rounds of programming, failing, and rebooting on bare-metal or virtual machines. This way of life is unproductive and painful. Such a pain point is also recognized and partially addressed by [research work](https://www.usenix.org/conference/fast21/presentation/miller), but we think we can do more. In this spirit, we design the OS core to provide high-level APIs that are largely independent of the underlying hardware and implement it with two targets: one target is as part of a regular OS in kernel space and the other is as a library OS in user space. This way, all the OS components of Jinux, which are stacked above the OS core, can be developed, tested, and debugged in user space, which is more friendly to developers than kernel space. -**4. High-fidelity Linux ABI.** An OS without usable applications is useless. So we believe it is important for KxOS to fit in an established and thriving ecosystem of software, such as the one around Linux. This is why we conclude that KxOS should aim at implementing high-fidelity Linux ABI, including the system calls, the proc file system, etc. +**4. High-fidelity Linux ABI.** An OS without usable applications is useless. So we believe it is important for Jinux to fit in an established and thriving ecosystem of software, such as the one around Linux. This is why we conclude that Jinux should aim at implementing high-fidelity Linux ABI, including the system calls, the proc file system, etc. **5. TEEs as top-tier targets.** (Todo) diff --git a/docs/src/capabilities/README.md b/docs/src/capabilities/README.md index 682db3906..e5fd82c6a 100644 --- a/docs/src/capabilities/README.md +++ b/docs/src/capabilities/README.md @@ -20,12 +20,12 @@ capabilities in a limited fashion, mostly as a means to limit the access from external users (e.g., via syscall), rather than a mechanism to enforce advanced security policies internally (e.g., module-level isolation). -So we ask this question: is it possible to use capabilities as a _ubitiquous_ security primitive throughout KxOS to enhance the security and robustness of the +So we ask this question: is it possible to use capabilities as a _ubitiquous_ security primitive throughout Jinux to enhance the security and robustness of the OS? Specifically, we propose a new principle called "_everything is a capability_". Here, "everything" refers to any type of OS resource, internal or external alike. In traditional OSes, treating everything as a capability is unrewarding because (1) capabilities themselves are unreliable due to memory safety problems -, and (2) capabilities are no free lunch as they incur memory and CPU overheads. But these arguments may no longer stand in a well-designed Rust OS like KxOS. +, and (2) capabilities are no free lunch as they incur memory and CPU overheads. But these arguments may no longer stand in a well-designed Rust OS like Jinux. Because the odds of memory safety bugs are minimized and advanced Rust features like type-level programming allow us to implement capabilities as a zero-cost abstraction. diff --git a/docs/src/capabilities/zero_cost_capabilities.md b/docs/src/capabilities/zero_cost_capabilities.md index 9167adf4b..b07173c8c 100644 --- a/docs/src/capabilities/zero_cost_capabilities.md +++ b/docs/src/capabilities/zero_cost_capabilities.md @@ -1,6 +1,6 @@ # Zero-Cost Capabilities -To strengthen the security of KxOS, we aim to implement all kinds of OS resources +To strengthen the security of Jinux, we aim to implement all kinds of OS resources as capabilities. As the capabilities are going to be used throughout the OS, it is highly desirable to minimize their costs. For this purpose, we want to implement capabilities as a _zero-cost abstraction_. @@ -351,7 +351,7 @@ mod test { ### Implement access rights with typeflags -The `kxos-rights/lib.rs` file implements access rights. +The `Jinux-rights/lib.rs` file implements access rights. ```rust //! Access rights. @@ -376,7 +376,7 @@ typeflags! { } ``` -The `kxos-rights-proc/lib.rs` file implements the `require` procedural macro. +The `Jinux-rights-proc/lib.rs` file implements the `require` procedural macro. See the channel capability example later for how `require` is used. ```rust diff --git a/docs/src/privilege_separation/README.md b/docs/src/privilege_separation/README.md index 09f5b02cd..fd341d04d 100644 --- a/docs/src/privilege_separation/README.md +++ b/docs/src/privilege_separation/README.md @@ -1,15 +1,15 @@ # Privilege Separation -One fundamental design goal of KxOS is to support _privilege separation_, i.e., the separation between the privileged OS core and the unprivileged OS components. The privileged portion is allowed to use `unsafe` keyword to carry out dangerous tasks like accessing CPU registers, manipulating stack frames, and doing MMIO or PIO. In contrast, the unprivileged portion, which forms the majority of the OS, must be free from `unsafe` code. With privilege separation, the memory safety of KxOS can be boiled down to the correctness of the privileged OS core, regardless of the correctness of the unprivileged OS components, thus reducing the size of TCB significantly. +One fundamental design goal of Jinux is to support _privilege separation_, i.e., the separation between the privileged OS core and the unprivileged OS components. The privileged portion is allowed to use `unsafe` keyword to carry out dangerous tasks like accessing CPU registers, manipulating stack frames, and doing MMIO or PIO. In contrast, the unprivileged portion, which forms the majority of the OS, must be free from `unsafe` code. With privilege separation, the memory safety of Jinux can be boiled down to the correctness of the privileged OS core, regardless of the correctness of the unprivileged OS components, thus reducing the size of TCB significantly. To put privilege separation into perspective, let's compare the architectures -of the monolithic kernels, microkernels, and KxOS. +of the monolithic kernels, microkernels, and Jinux. ![Arch comparison](../images/arch_comparison.png) The diagram above highlights the characteristics of different OS architectures in terms of communication overheads and the TCB for memory safety. -Thanks to privilege separation, KxOS promises the benefit of being _as safe as a microkernel and as fast as a monolithic kernel_. +Thanks to privilege separation, Jinux promises the benefit of being _as safe as a microkernel and as fast as a monolithic kernel_. Privilege separation is an interesting research problem, prompting us to answer a series of technical questions. diff --git a/docs/src/privilege_separation/pci_virtio_drivers.md b/docs/src/privilege_separation/pci_virtio_drivers.md index aca7b7e49..b85e42092 100644 --- a/docs/src/privilege_separation/pci_virtio_drivers.md +++ b/docs/src/privilege_separation/pci_virtio_drivers.md @@ -22,7 +22,7 @@ Here are some of the elements in PCI-based Virtio devices that may involve `unsa ### Privileged part ```rust -// file: kxos-core-libs/pci-io-port/lib.rs +// file: jinux-core-libs/pci-io-port/lib.rs use x86::IoPort; /// The I/O port to write an address in the PCI @@ -49,7 +49,7 @@ pub const PCI_DATA_PORT: IoPort = { ### Unprivileged part ```rust -// file: kxos-comps/pci/lib.rs +// file: jinux-comps/pci/lib.rs use pci_io_port::{PCI_ADDR_PORT, PCI_DATA_PORT}; /// The PCI configuration space, which enables the discovery, @@ -128,7 +128,7 @@ pub struct PciCapabilities { Most code of Virtio drivers can be unprivileged thanks to the abstractions of `VmPager` and `VmCell` provided by the OS core. ```rust -// file: kxos-comp-libs/virtio/transport.rs +// file: jinux-comp-libs/virtio/transport.rs /// The transport layer for configuring a Virtio device. pub struct VirtioTransport { diff --git a/docs/src/privilege_separation/syscall_workflow.md b/docs/src/privilege_separation/syscall_workflow.md index e52d5a257..3873c8161 100644 --- a/docs/src/privilege_separation/syscall_workflow.md +++ b/docs/src/privilege_separation/syscall_workflow.md @@ -138,7 +138,7 @@ impl UserPtr { } ``` -The examples reveal two important considerations in designing KxOS: +The examples reveal two important considerations in designing Jinux: 1. Exposing _truly_ safe APIs. The privileged OS core must expose _truly safe_ APIs: however buggy or silly the unprivileged OS components may be written, they must _not_ cause undefined behaviors. 2. Handling _arbitrary_ pointers safely. The safe API of the OS core must provide a safe way to deal with arbitrary pointers. @@ -146,15 +146,15 @@ With the two points in mind, let's get back to our main goal of privilege separa ## Code organization with privilege separation -Our first step is to separate privileged and unprivileged code in the codebase of KxOS. For our purpose of demonstrating a syscall handling framework, a minimal codebase may look like the following. +Our first step is to separate privileged and unprivileged code in the codebase of Jinux. For our purpose of demonstrating a syscall handling framework, a minimal codebase may look like the following. ```text . -├── kxos +├── jinux │   ├── src │ │   └── main.rs │   └── Cargo.toml -├── kxos-core +├── jinux-core │   ├── src │ │   ├── lib.rs │ │   ├── syscall_handler.rs @@ -162,7 +162,7 @@ Our first step is to separate privileged and unprivileged code in the codebase o │ │ ├── vmo.rs │ │ └── vmar.rs │   └── Cargo.toml -├── kxos-core-libs +├── jinux-core-libs │ ├── linux-abi-types │ │   ├── src │ │   │ └── lib.rs @@ -171,34 +171,34 @@ Our first step is to separate privileged and unprivileged code in the codebase o │ ├── src │   │ └── lib.rs │  └── Cargo.toml -├── kxos-comps +├── jinux-comps │   └── linux-syscall │ ├── src │   │ └── lib.rs │   └── Cargo.toml -└── kxos-comp-libs +└── jinux-comp-libs    └── linux-abi ├── src   │ └── lib.rs    └── Cargo.toml ``` -The ultimate build target of the codebase is the `kxos` crate, which is an OS kernel that consists of a privileged OS core (crate `kxos-core`) and multiple OS components (the crates under `kxos-comps/`). +The ultimate build target of the codebase is the `jinux` crate, which is an OS kernel that consists of a privileged OS core (crate `jinux-core`) and multiple OS components (the crates under `jinux-comps/`). -For the sake of privilege separation, only crate `kxos` and `kxos-core` along with the crates under `kxos-core-libs` are allowed to use the `unsafe` keyword. To the contrary, the crates under `kxos-comps/` along with their dependent crates under `kxos-comp-libs/` are not allowed to use `unsafe` directly; they may only borrow the superpower of `unsafe` by using the safe API exposed by `kxos-core` or the crates under `kxos-core-libs`. To summarize, the memory safety of the OS only relies on a small and well-defined TCB that constitutes the `kxos` and `kxos-core` crate plus the crates under `kxos-core-libs/`. +For the sake of privilege separation, only crate `jinux` and `jinux-core` along with the crates under `jinux-core-libs` are allowed to use the `unsafe` keyword. To the contrary, the crates under `jinux-comps/` along with their dependent crates under `jinux-comp-libs/` are not allowed to use `unsafe` directly; they may only borrow the superpower of `unsafe` by using the safe API exposed by `jinux-core` or the crates under `jinux-core-libs`. To summarize, the memory safety of the OS only relies on a small and well-defined TCB that constitutes the `jinux` and `jinux-core` crate plus the crates under `jinux-core-libs/`. -Under this setting, all implementation of system calls goes to the `linux-syscall` crate. We are about to show that the _safe_ API provided by `kxos-core` is powerful enough to enable the _safe_ implementation of `linux-syscall`. +Under this setting, all implementation of system calls goes to the `linux-syscall` crate. We are about to show that the _safe_ API provided by `jinux-core` is powerful enough to enable the _safe_ implementation of `linux-syscall`. -## Crate `kxos-core` +## Crate `jinux-core` -For our purposes here, the two most relevant APIs provided by `kxos-core` is the abstraction for syscall handlers and virtual memory (VM). +For our purposes here, the two most relevant APIs provided by `jinux-core` is the abstraction for syscall handlers and virtual memory (VM). ### Syscall handlers The `SyscallHandler` abstraction enables the OS core to hide the low-level, architectural-dependent aspects of syscall handling workflow (e.g., user-kernel switching and CPU register manipulation) and allow the unprivileged OS components to implement system calls. ```rust -// file: kxos-core/src/syscall_handler.rs +// file: jinux-core/src/syscall_handler.rs pub trait SyscallHandler { fn handle_syscall(&self, ctx: &mut SyscallContext); @@ -243,8 +243,8 @@ an important concept that we will elaborate on later. Basically, they are capabi Here we demonstrate how to leverage the APIs of `ksos-core` to implement system calls with safe Rust code in crate `linux-syscall`. ```rust -// file: kxos-comps/linux-syscall/src/lib.rs -use kxos_core::{SyscallContext, SyscallHandler, Vmar}; +// file: jinux-comps/linux-syscall/src/lib.rs +use jinux_core::{SyscallContext, SyscallHandler, Vmar}; use linux_abi::{SyscallNum::*, UserPtr, RawFd, RawTimeVal, RawTimeZone}; pub struct SampleHandler; @@ -315,7 +315,7 @@ impl SampleHandler { This crate defines a marker trait `Pod`, which represents plain-old data. ```rust -/// file: kxos-core-libs/pod/src/lib.rs +/// file: jinux-core-libs/pod/src/lib.rs /// A marker trait for plain old data (POD). /// @@ -388,7 +388,7 @@ unsafe impl [T; N] for Pod {} ## Crate `linux-abi-type` ```rust -// file: kxos-core-libs/linux-abi-types +// file: jinux-core-libs/linux-abi-types use pod::Pod; pub type RawFd = i32; @@ -404,7 +404,7 @@ unsafe impl Pod for RawTimeVal {} ## Crate `linux-abi` ```rust -// file: kxos-comp-libs/linux-abi +// file: jinux-comp-libs/linux-abi pub use linux_abi_types::*; pub enum SyscallNum { diff --git a/src/.cargo/config.toml b/src/.cargo/config.toml index 2684f7bb5..d692eefbf 100644 --- a/src/.cargo/config.toml +++ b/src/.cargo/config.toml @@ -1,6 +1,6 @@ [target.'cfg(target_os = "none")'] -runner = "cargo run --package kxos-boot --" +runner = "cargo run --package jinux-boot --" [alias] kcheck = "check --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" diff --git a/src/Cargo.lock b/src/Cargo.lock index 7f4fb839f..3329c62a9 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -34,9 +34,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bootloader" -version = "0.10.12" +version = "0.10.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d9b14b92a825ecc3b24e4c163a578af473fbba5f190bfaf48092b29b604504" +checksum = "24e13520aa8580a2850fc9f5390dc6753f1062fb66f90e5a61bd5c72b55df731" [[package]] name = "bootloader-locator" @@ -78,22 +78,16 @@ dependencies = [ ] [[package]] -name = "json" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" - -[[package]] -name = "kxos" +name = "jinux" version = "0.1.0" dependencies = [ "bootloader", - "kxos-frame", - "kxos-std", + "jinux-frame", + "jinux-std", ] [[package]] -name = "kxos-boot" +name = "jinux-boot" version = "0.1.0" dependencies = [ "anyhow", @@ -103,7 +97,7 @@ dependencies = [ ] [[package]] -name = "kxos-frame" +name = "jinux-frame" version = "0.1.0" dependencies = [ "bitflags", @@ -112,6 +106,8 @@ dependencies = [ "font8x8", "lazy_static", "linked_list_allocator", + "pod", + "pod-derive", "spin 0.9.4", "uart_16550", "volatile", @@ -119,28 +115,20 @@ dependencies = [ ] [[package]] -name = "kxos-frame-pod-derive" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "kxos-pci" +name = "jinux-pci" version = "0.1.0" dependencies = [ "bitflags", - "kxos-frame", - "kxos-frame-pod-derive", - "kxos-util", + "jinux-frame", + "jinux-util", "lazy_static", + "pod", + "pod-derive", "spin 0.9.4", ] [[package]] -name = "kxos-rights-proc" +name = "jinux-rights-proc" version = "0.1.0" dependencies = [ "proc-macro2", @@ -149,57 +137,53 @@ dependencies = [ ] [[package]] -name = "kxos-std" +name = "jinux-std" version = "0.1.0" dependencies = [ "bitflags", - "kxos-frame", - "kxos-frame-pod-derive", - "kxos-pci", - "kxos-rights-proc", - "kxos-typeflags", - "kxos-typeflags-util", - "kxos-virtio", + "jinux-frame", + "jinux-pci", + "jinux-rights-proc", + "jinux-virtio", "lazy_static", + "pod", + "pod-derive", "ringbuffer", "spin 0.9.4", + "typeflags", + "typeflags-util", "vte", "xmas-elf", ] [[package]] -name = "kxos-typeflags" +name = "jinux-util" version = "0.1.0" dependencies = [ - "itertools", - "proc-macro2", - "quote", - "syn", + "jinux-frame", + "pod", + "pod-derive", ] [[package]] -name = "kxos-typeflags-util" -version = "0.1.0" - -[[package]] -name = "kxos-util" -version = "0.1.0" -dependencies = [ - "kxos-frame", -] - -[[package]] -name = "kxos-virtio" +name = "jinux-virtio" version = "0.1.0" dependencies = [ "bitflags", - "kxos-frame", - "kxos-frame-pod-derive", - "kxos-pci", - "kxos-util", + "jinux-frame", + "jinux-pci", + "jinux-util", + "pod", + "pod-derive", "spin 0.9.4", ] +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "lazy_static" version = "1.4.0" @@ -211,9 +195,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.132" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "linked_list_allocator" @@ -235,19 +219,32 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", ] +[[package]] +name = "pod" +version = "0.1.0" + +[[package]] +name = "pod-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -321,9 +318,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.99" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -332,24 +329,38 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "typeflags" +version = "0.1.0" +dependencies = [ + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typeflags-util" +version = "0.1.0" + [[package]] name = "uart_16550" version = "0.2.18" @@ -363,9 +374,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "utf8parse" diff --git a/src/Cargo.toml b/src/Cargo.toml index 1c252408d..7b1a1b491 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -1,26 +1,27 @@ [package] -name = "kxos" +name = "jinux" version = "0.1.0" edition = "2021" [dependencies] bootloader = {version="0.10.12"} -kxos-frame = {path = "kxos-frame"} -kxos-std = {path = "kxos-std"} +jinux-frame = {path = "framework/jinux-frame"} +jinux-std = {path = "services/libs/jinux-std"} [workspace] members = [ - "kxos-frame", - "kxos-std", - "kxos-boot", - "kxos-pci", - "kxos-virtio", - "kxos-util", - "kxos-frame-pod-derive", - "kxos-typeflags", - "kxos-typeflags-util", - "kxos-rights-proc", + "jinux-boot", + "framework/jinux-frame", + "framework/pod", + "framework/pod-derive", + "services/comps/jinux-pci", + "services/comps/jinux-virtio", + "services/libs/jinux-std", + "services/libs/jinux-rights-proc", + "services/libs/typeflags", + "services/libs/typeflags-util", + "services/libs/jinux-util", ] [package.metadata.bootloader] diff --git a/src/README.md b/src/README.md index 56438e95f..50f789b6a 100644 --- a/src/README.md +++ b/src/README.md @@ -1,27 +1,27 @@ -# KxOS Source Code +# Jinux Source Code ## Code organization The codebase is organized as a number of Rust crates. -* The `kxos` crate assembles all other crates into a runnable OS kernel image. +* The `jinux` crate assembles all other crates into a runnable OS kernel image. This is the only binary crate; all other crates are libraries. -* The `kxos-frame` crate constitutes the main part of the KxOS framework, +* The `jinux-frame` crate constitutes the main part of the jinux framework, providing a minimal set of _safe_ abstractions that encapsulates _unsafe_ Rust code to deal with hardware resources like CPU, memory, and interrupts. -* The `kxos-frame-*` crates complement `kxos-frame` by providing more _safe_ -types, APIs, or abstractions that are useful to specific aspects of the KxOS. -* The `kxos-std` crate is KxOS's equivalent of Rust's std crate, although +* The `jinux-frame-*` crates complement `jinux-frame` by providing more _safe_ +types, APIs, or abstractions that are useful to specific aspects of the Jinux. +* The `jinux-std` crate is Jinux's equivalent of Rust's std crate, although their APIs are quite different. This crate offers an extensive set of high-level safe APIs that are widely used throughout the OS code above the framework (i.e., the crates described below). -* The rest of `kxos-*` crates implement most of the functionalities of KxOS, e.g., +* The rest of `jinux-*` crates implement most of the functionalities of Jinux, e.g., Linux syscall dispatching, process management, file systems, network stacks, and device drivers. ## Privilege separation -KxOS is a _framekernel_, separating the entire OS into two halves: +Jinux is a _framekernel_, separating the entire OS into two halves: the _privileged_ half (so-called "frame") and the _unprivileged_ half. Only the privileged half is allowed to include any _unsafe_ Rust code. And it is the privileged half's responsibility to encapsulate the _unsafe_ Rust @@ -30,5 +30,5 @@ with safe Rust in the unprivileged half. This philosophy of privilege separationn is also reflected in the code organization. -* The privileged half consists of `kxos`, `kxos-frame`, and `kxos-frame-*` crates. -* The unprivileged half consists of `kxos-std` and the rest `kxos-*` crates. +* The privileged half consists of `jinux`, `jinux-frame`, and `jinux-frame-*` crates. +* The unprivileged half consists of `jinux-std` and the rest `jinux-*` crates. diff --git a/src/kxos-user/busybox/README.md b/src/apps/busybox/README.md similarity index 100% rename from src/kxos-user/busybox/README.md rename to src/apps/busybox/README.md diff --git a/src/kxos-user/busybox/busybox b/src/apps/busybox/busybox similarity index 100% rename from src/kxos-user/busybox/busybox rename to src/apps/busybox/busybox diff --git a/src/kxos-user/execve/Makefile b/src/apps/execve/Makefile similarity index 100% rename from src/kxos-user/execve/Makefile rename to src/apps/execve/Makefile diff --git a/src/kxos-user/execve/execve b/src/apps/execve/execve similarity index 100% rename from src/kxos-user/execve/execve rename to src/apps/execve/execve diff --git a/src/kxos-user/execve/execve.c b/src/apps/execve/execve.c similarity index 100% rename from src/kxos-user/execve/execve.c rename to src/apps/execve/execve.c diff --git a/src/kxos-user/execve/hello b/src/apps/execve/hello similarity index 100% rename from src/kxos-user/execve/hello rename to src/apps/execve/hello diff --git a/src/kxos-user/execve/hello.c b/src/apps/execve/hello.c similarity index 100% rename from src/kxos-user/execve/hello.c rename to src/apps/execve/hello.c diff --git a/src/kxos-user/fork/Makefile b/src/apps/fork/Makefile similarity index 100% rename from src/kxos-user/fork/Makefile rename to src/apps/fork/Makefile diff --git a/src/kxos-user/fork/fork b/src/apps/fork/fork similarity index 100% rename from src/kxos-user/fork/fork rename to src/apps/fork/fork diff --git a/src/kxos-user/fork/fork.s b/src/apps/fork/fork.s similarity index 100% rename from src/kxos-user/fork/fork.s rename to src/apps/fork/fork.s diff --git a/src/kxos-user/fork_c/Makefile b/src/apps/fork_c/Makefile similarity index 100% rename from src/kxos-user/fork_c/Makefile rename to src/apps/fork_c/Makefile diff --git a/src/kxos-user/fork_c/fork b/src/apps/fork_c/fork similarity index 100% rename from src/kxos-user/fork_c/fork rename to src/apps/fork_c/fork diff --git a/src/kxos-user/fork_c/fork.c b/src/apps/fork_c/fork.c similarity index 100% rename from src/kxos-user/fork_c/fork.c rename to src/apps/fork_c/fork.c diff --git a/src/kxos-user/hello_c/Makefile b/src/apps/hello_c/Makefile similarity index 100% rename from src/kxos-user/hello_c/Makefile rename to src/apps/hello_c/Makefile diff --git a/src/apps/hello_c/hello b/src/apps/hello_c/hello new file mode 100755 index 000000000..aff26147f Binary files /dev/null and b/src/apps/hello_c/hello differ diff --git a/src/kxos-user/hello_c/hello.c b/src/apps/hello_c/hello.c similarity index 100% rename from src/kxos-user/hello_c/hello.c rename to src/apps/hello_c/hello.c diff --git a/src/kxos-user/hello_world/Makefile b/src/apps/hello_world/Makefile similarity index 100% rename from src/kxos-user/hello_world/Makefile rename to src/apps/hello_world/Makefile diff --git a/src/kxos-user/hello_world/hello_world b/src/apps/hello_world/hello_world similarity index 100% rename from src/kxos-user/hello_world/hello_world rename to src/apps/hello_world/hello_world diff --git a/src/kxos-user/hello_world/hello_world.s b/src/apps/hello_world/hello_world.s similarity index 100% rename from src/kxos-user/hello_world/hello_world.s rename to src/apps/hello_world/hello_world.s diff --git a/src/kxos-user/signal_c/Makefile b/src/apps/signal_c/Makefile similarity index 100% rename from src/kxos-user/signal_c/Makefile rename to src/apps/signal_c/Makefile diff --git a/src/kxos-user/signal_c/signal_test b/src/apps/signal_c/signal_test similarity index 100% rename from src/kxos-user/signal_c/signal_test rename to src/apps/signal_c/signal_test diff --git a/src/kxos-user/signal_c/signal_test.c b/src/apps/signal_c/signal_test.c similarity index 99% rename from src/kxos-user/signal_c/signal_test.c rename to src/apps/signal_c/signal_test.c index 0d2e5bf5b..158d94639 100644 --- a/src/kxos-user/signal_c/signal_test.c +++ b/src/apps/signal_c/signal_test.c @@ -185,7 +185,7 @@ int test_handle_sigfpe() { c = div_maybe_zero(a, b); fxsave(y); - // kxos does not save and restore fpregs now, so we emit this check. + // jinux does not save and restore fpregs now, so we emit this check. // if (memcmp(x, y, 512) != 0) { // THROW_ERROR("floating point registers are modified"); // } diff --git a/src/kxos-frame/Cargo.toml b/src/framework/jinux-frame/Cargo.toml similarity index 87% rename from src/kxos-frame/Cargo.toml rename to src/framework/jinux-frame/Cargo.toml index 03699f134..fed9a9326 100644 --- a/src/kxos-frame/Cargo.toml +++ b/src/framework/jinux-frame/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-frame" +name = "jinux-frame" version = "0.1.0" edition = "2021" @@ -15,6 +15,8 @@ linked_list_allocator = "0.9.0" bootloader = {version="0.10.12"} font8x8 = { version = "0.2.5", default-features = false, features = ["unicode"]} uart_16550 = "0.2.0" +pod = {path = "../pod"} +pod-derive = {path = "../pod-derive"} [dependencies.lazy_static] version = "1.0" diff --git a/src/kxos-frame/src/cell.rs b/src/framework/jinux-frame/src/cell.rs similarity index 100% rename from src/kxos-frame/src/cell.rs rename to src/framework/jinux-frame/src/cell.rs diff --git a/src/kxos-frame/src/config.rs b/src/framework/jinux-frame/src/config.rs similarity index 100% rename from src/kxos-frame/src/config.rs rename to src/framework/jinux-frame/src/config.rs diff --git a/src/kxos-frame/src/cpu.rs b/src/framework/jinux-frame/src/cpu.rs similarity index 99% rename from src/kxos-frame/src/cpu.rs rename to src/framework/jinux-frame/src/cpu.rs index d780774ae..14dd4000d 100644 --- a/src/kxos-frame/src/cpu.rs +++ b/src/framework/jinux-frame/src/cpu.rs @@ -6,7 +6,7 @@ use core::mem::MaybeUninit; use crate::debug; use crate::trap::{CalleeRegs, CallerRegs, SyscallFrame, TrapFrame}; -use crate::vm::Pod; +use pod::Pod; /// Defines a CPU-local variable. #[macro_export] diff --git a/src/kxos-frame/src/device/framebuffer.rs b/src/framework/jinux-frame/src/device/framebuffer.rs similarity index 100% rename from src/kxos-frame/src/device/framebuffer.rs rename to src/framework/jinux-frame/src/device/framebuffer.rs diff --git a/src/kxos-frame/src/device/io_port.rs b/src/framework/jinux-frame/src/device/io_port.rs similarity index 100% rename from src/kxos-frame/src/device/io_port.rs rename to src/framework/jinux-frame/src/device/io_port.rs diff --git a/src/kxos-frame/src/device/mod.rs b/src/framework/jinux-frame/src/device/mod.rs similarity index 100% rename from src/kxos-frame/src/device/mod.rs rename to src/framework/jinux-frame/src/device/mod.rs diff --git a/src/kxos-frame/src/device/pci.rs b/src/framework/jinux-frame/src/device/pci.rs similarity index 100% rename from src/kxos-frame/src/device/pci.rs rename to src/framework/jinux-frame/src/device/pci.rs diff --git a/src/kxos-frame/src/device/pic.rs b/src/framework/jinux-frame/src/device/pic.rs similarity index 100% rename from src/kxos-frame/src/device/pic.rs rename to src/framework/jinux-frame/src/device/pic.rs diff --git a/src/kxos-frame/src/device/serial.rs b/src/framework/jinux-frame/src/device/serial.rs similarity index 100% rename from src/kxos-frame/src/device/serial.rs rename to src/framework/jinux-frame/src/device/serial.rs diff --git a/src/kxos-frame/src/error.rs b/src/framework/jinux-frame/src/error.rs similarity index 100% rename from src/kxos-frame/src/error.rs rename to src/framework/jinux-frame/src/error.rs diff --git a/src/kxos-frame/src/lib.rs b/src/framework/jinux-frame/src/lib.rs similarity index 98% rename from src/kxos-frame/src/lib.rs rename to src/framework/jinux-frame/src/lib.rs index dd09c5df2..630a6e4b5 100644 --- a/src/kxos-frame/src/lib.rs +++ b/src/framework/jinux-frame/src/lib.rs @@ -1,4 +1,4 @@ -//! The framework part of KxOS. +//! The framework part of Jinux. #![no_std] #![allow(dead_code)] #![allow(unused_variables)] @@ -45,7 +45,6 @@ pub use mm::address::{align_down, align_up, is_aligned, virt_to_phys}; pub use trap::{allocate_irq, IrqAllocateHandle, TrapFrame}; use trap::{IrqCallbackHandle, IrqLine}; pub use util::AlignExt; -pub use vm::Pod; use x86_64_util::enable_common_cpu_features; static mut IRQ_CALLBACK_LIST: Vec = Vec::new(); diff --git a/src/kxos-frame/src/linker.ld b/src/framework/jinux-frame/src/linker.ld similarity index 100% rename from src/kxos-frame/src/linker.ld rename to src/framework/jinux-frame/src/linker.ld diff --git a/src/kxos-frame/src/log.rs b/src/framework/jinux-frame/src/log.rs similarity index 100% rename from src/kxos-frame/src/log.rs rename to src/framework/jinux-frame/src/log.rs diff --git a/src/kxos-frame/src/mm/address.rs b/src/framework/jinux-frame/src/mm/address.rs similarity index 100% rename from src/kxos-frame/src/mm/address.rs rename to src/framework/jinux-frame/src/mm/address.rs diff --git a/src/kxos-frame/src/mm/frame_allocator.rs b/src/framework/jinux-frame/src/mm/frame_allocator.rs similarity index 100% rename from src/kxos-frame/src/mm/frame_allocator.rs rename to src/framework/jinux-frame/src/mm/frame_allocator.rs diff --git a/src/kxos-frame/src/mm/heap_allocator.rs b/src/framework/jinux-frame/src/mm/heap_allocator.rs similarity index 100% rename from src/kxos-frame/src/mm/heap_allocator.rs rename to src/framework/jinux-frame/src/mm/heap_allocator.rs diff --git a/src/kxos-frame/src/mm/memory_set.rs b/src/framework/jinux-frame/src/mm/memory_set.rs similarity index 100% rename from src/kxos-frame/src/mm/memory_set.rs rename to src/framework/jinux-frame/src/mm/memory_set.rs diff --git a/src/kxos-frame/src/mm/mod.rs b/src/framework/jinux-frame/src/mm/mod.rs similarity index 100% rename from src/kxos-frame/src/mm/mod.rs rename to src/framework/jinux-frame/src/mm/mod.rs diff --git a/src/kxos-frame/src/mm/page_table.rs b/src/framework/jinux-frame/src/mm/page_table.rs similarity index 100% rename from src/kxos-frame/src/mm/page_table.rs rename to src/framework/jinux-frame/src/mm/page_table.rs diff --git a/src/kxos-frame/src/prelude.rs b/src/framework/jinux-frame/src/prelude.rs similarity index 100% rename from src/kxos-frame/src/prelude.rs rename to src/framework/jinux-frame/src/prelude.rs diff --git a/src/kxos-frame/src/sync/atomic_bits.rs b/src/framework/jinux-frame/src/sync/atomic_bits.rs similarity index 100% rename from src/kxos-frame/src/sync/atomic_bits.rs rename to src/framework/jinux-frame/src/sync/atomic_bits.rs diff --git a/src/kxos-frame/src/sync/mod.rs b/src/framework/jinux-frame/src/sync/mod.rs similarity index 100% rename from src/kxos-frame/src/sync/mod.rs rename to src/framework/jinux-frame/src/sync/mod.rs diff --git a/src/kxos-frame/src/sync/rcu/mod.rs b/src/framework/jinux-frame/src/sync/rcu/mod.rs similarity index 100% rename from src/kxos-frame/src/sync/rcu/mod.rs rename to src/framework/jinux-frame/src/sync/rcu/mod.rs diff --git a/src/kxos-frame/src/sync/rcu/monitor.rs b/src/framework/jinux-frame/src/sync/rcu/monitor.rs similarity index 100% rename from src/kxos-frame/src/sync/rcu/monitor.rs rename to src/framework/jinux-frame/src/sync/rcu/monitor.rs diff --git a/src/kxos-frame/src/sync/rcu/owner_ptr.rs b/src/framework/jinux-frame/src/sync/rcu/owner_ptr.rs similarity index 100% rename from src/kxos-frame/src/sync/rcu/owner_ptr.rs rename to src/framework/jinux-frame/src/sync/rcu/owner_ptr.rs diff --git a/src/kxos-frame/src/sync/spin.rs b/src/framework/jinux-frame/src/sync/spin.rs similarity index 100% rename from src/kxos-frame/src/sync/spin.rs rename to src/framework/jinux-frame/src/sync/spin.rs diff --git a/src/kxos-frame/src/sync/up.rs b/src/framework/jinux-frame/src/sync/up.rs similarity index 100% rename from src/kxos-frame/src/sync/up.rs rename to src/framework/jinux-frame/src/sync/up.rs diff --git a/src/kxos-frame/src/sync/wait.rs b/src/framework/jinux-frame/src/sync/wait.rs similarity index 100% rename from src/kxos-frame/src/sync/wait.rs rename to src/framework/jinux-frame/src/sync/wait.rs diff --git a/src/kxos-frame/src/task/mod.rs b/src/framework/jinux-frame/src/task/mod.rs similarity index 100% rename from src/kxos-frame/src/task/mod.rs rename to src/framework/jinux-frame/src/task/mod.rs diff --git a/src/kxos-frame/src/task/processor.rs b/src/framework/jinux-frame/src/task/processor.rs similarity index 100% rename from src/kxos-frame/src/task/processor.rs rename to src/framework/jinux-frame/src/task/processor.rs diff --git a/src/kxos-frame/src/task/scheduler.rs b/src/framework/jinux-frame/src/task/scheduler.rs similarity index 100% rename from src/kxos-frame/src/task/scheduler.rs rename to src/framework/jinux-frame/src/task/scheduler.rs diff --git a/src/kxos-frame/src/task/switch.S b/src/framework/jinux-frame/src/task/switch.S similarity index 100% rename from src/kxos-frame/src/task/switch.S rename to src/framework/jinux-frame/src/task/switch.S diff --git a/src/kxos-frame/src/task/task.rs b/src/framework/jinux-frame/src/task/task.rs similarity index 100% rename from src/kxos-frame/src/task/task.rs rename to src/framework/jinux-frame/src/task/task.rs diff --git a/src/kxos-frame/src/timer.rs b/src/framework/jinux-frame/src/timer.rs similarity index 100% rename from src/kxos-frame/src/timer.rs rename to src/framework/jinux-frame/src/timer.rs diff --git a/src/kxos-frame/src/trap/handler.rs b/src/framework/jinux-frame/src/trap/handler.rs similarity index 97% rename from src/kxos-frame/src/trap/handler.rs rename to src/framework/jinux-frame/src/trap/handler.rs index 95c67ca14..b7ba5308b 100644 --- a/src/kxos-frame/src/trap/handler.rs +++ b/src/framework/jinux-frame/src/trap/handler.rs @@ -26,7 +26,7 @@ pub(crate) extern "C" fn trap_handler(f: &mut TrapFrame) { current.inner_exclusive_access().is_from_trap = true; *current.trap_frame() = *SWITCH_TO_USER_SPACE_TASK.trap_frame(); if is_cpu_fault(current.trap_frame()) { - // if is cpu fault, we will pass control to trap handler in kxos std + // if is cpu fault, we will pass control to trap handler in jinux std unsafe { context_switch( get_idle_task_cx_ptr() as *mut TaskContext, @@ -68,7 +68,7 @@ fn is_from_kernel(cs: u64) -> bool { /// Aborts: Some severe unrecoverable error. /// This function will determine a trap is a CPU faults. -/// We will pass control to kxos-std if the trap is **faults**. +/// We will pass control to jinux-std if the trap is **faults**. pub fn is_cpu_fault(trap_frame: &TrapFrame) -> bool { match trap_frame.id { DIVIDE_BY_ZERO diff --git a/src/kxos-frame/src/trap/irq.rs b/src/framework/jinux-frame/src/trap/irq.rs similarity index 99% rename from src/kxos-frame/src/trap/irq.rs rename to src/framework/jinux-frame/src/trap/irq.rs index 9c9ca3710..7482ea70c 100644 --- a/src/kxos-frame/src/trap/irq.rs +++ b/src/framework/jinux-frame/src/trap/irq.rs @@ -28,7 +28,7 @@ pub(crate) fn allocate_target_irq(target_irq: u8) -> Result { } } -/// The handle to a allocate irq number between [32,256), used in std and other parts in kxos +/// The handle to a allocate irq number between [32,256), used in std and other parts in jinux /// /// When the handle is dropped, all the callback in this will be unregistered automatically. #[derive(Debug)] diff --git a/src/kxos-frame/src/trap/mod.rs b/src/framework/jinux-frame/src/trap/mod.rs similarity index 100% rename from src/kxos-frame/src/trap/mod.rs rename to src/framework/jinux-frame/src/trap/mod.rs diff --git a/src/kxos-frame/src/trap/trap.S b/src/framework/jinux-frame/src/trap/trap.S similarity index 100% rename from src/kxos-frame/src/trap/trap.S rename to src/framework/jinux-frame/src/trap/trap.S diff --git a/src/kxos-frame/src/trap/vector.S b/src/framework/jinux-frame/src/trap/vector.S similarity index 100% rename from src/kxos-frame/src/trap/vector.S rename to src/framework/jinux-frame/src/trap/vector.S diff --git a/src/kxos-frame/src/user.rs b/src/framework/jinux-frame/src/user.rs similarity index 99% rename from src/kxos-frame/src/user.rs rename to src/framework/jinux-frame/src/user.rs index 5725a9123..899e72d1d 100644 --- a/src/kxos-frame/src/user.rs +++ b/src/framework/jinux-frame/src/user.rs @@ -69,7 +69,7 @@ impl UserSpace { /// Here is a sample code on how to use `UserMode`. /// /// ```no_run -/// use kxos_frame::task::Task; +/// use jinux_frame::task::Task; /// /// let current = Task::current(); /// let user_space = current.user_space() diff --git a/src/kxos-frame/src/util/align_ext.rs b/src/framework/jinux-frame/src/util/align_ext.rs similarity index 100% rename from src/kxos-frame/src/util/align_ext.rs rename to src/framework/jinux-frame/src/util/align_ext.rs diff --git a/src/kxos-frame/src/util/mod.rs b/src/framework/jinux-frame/src/util/mod.rs similarity index 100% rename from src/kxos-frame/src/util/mod.rs rename to src/framework/jinux-frame/src/util/mod.rs diff --git a/src/kxos-frame/src/util/recycle_allocator.rs b/src/framework/jinux-frame/src/util/recycle_allocator.rs similarity index 100% rename from src/kxos-frame/src/util/recycle_allocator.rs rename to src/framework/jinux-frame/src/util/recycle_allocator.rs diff --git a/src/kxos-frame/src/util/type_map.rs b/src/framework/jinux-frame/src/util/type_map.rs similarity index 100% rename from src/kxos-frame/src/util/type_map.rs rename to src/framework/jinux-frame/src/util/type_map.rs diff --git a/src/kxos-frame/src/vm/frame.rs b/src/framework/jinux-frame/src/vm/frame.rs similarity index 99% rename from src/kxos-frame/src/vm/frame.rs rename to src/framework/jinux-frame/src/vm/frame.rs index 8a34b6f23..05684ae37 100644 --- a/src/kxos-frame/src/vm/frame.rs +++ b/src/framework/jinux-frame/src/vm/frame.rs @@ -1,6 +1,7 @@ use core::iter::Iterator; -use crate::{config::PAGE_SIZE, mm::address::PhysAddr, prelude::*, Error, Pod}; +use crate::{config::PAGE_SIZE, mm::address::PhysAddr, prelude::*, Error}; +use pod::Pod; use super::VmIo; diff --git a/src/kxos-frame/src/vm/io.rs b/src/framework/jinux-frame/src/vm/io.rs similarity index 99% rename from src/kxos-frame/src/vm/io.rs rename to src/framework/jinux-frame/src/vm/io.rs index c447d3a7c..870d16de2 100644 --- a/src/kxos-frame/src/vm/io.rs +++ b/src/framework/jinux-frame/src/vm/io.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::vm::Pod; +use pod::Pod; /// A trait that enables reading/writing data from/to a VM object, /// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`. diff --git a/src/kxos-frame/src/vm/mod.rs b/src/framework/jinux-frame/src/vm/mod.rs similarity index 90% rename from src/kxos-frame/src/vm/mod.rs rename to src/framework/jinux-frame/src/vm/mod.rs index 34c00fad8..88c91845f 100644 --- a/src/kxos-frame/src/vm/mod.rs +++ b/src/framework/jinux-frame/src/vm/mod.rs @@ -8,10 +8,9 @@ pub type Paddr = usize; mod frame; mod io; -mod pod; +mod offset; mod space; pub use self::frame::{VmAllocOptions, VmFrame, VmFrameVec, VmFrameVecIter}; pub use self::io::VmIo; -pub use self::pod::Pod; pub use self::space::{VmMapOptions, VmPerm, VmSpace}; diff --git a/src/framework/jinux-frame/src/vm/offset.rs b/src/framework/jinux-frame/src/vm/offset.rs new file mode 100644 index 000000000..634716037 --- /dev/null +++ b/src/framework/jinux-frame/src/vm/offset.rs @@ -0,0 +1,35 @@ +/// Get the offset of a field within a type as a pointer. +/// +/// ```rust +/// #[repr(C)] +/// pub struct Foo { +/// first: u8, +/// second: u32, +/// } +/// +/// assert!(offset_of(Foo, first) == (0 as *const u8)); +/// assert!(offset_of(Foo, second) == (4 as *const u32)); +/// ``` +#[macro_export] +macro_rules! offset_of { + ($container:ty, $($field:tt)+) => ({ + // SAFETY. It is ok to have this uninitialized value because + // 1) Its memory won't be acccessed; + // 2) It will be forgoten rather than being dropped; + // 3) Before it gets forgten, the code won't return prematurely or panic. + let tmp: $container = unsafe { core::mem::MaybeUninit::uninit().assume_init() }; + + let container_addr = &tmp as *const _; + let field_addr = &tmp.$($field)* as *const _; + + ::core::mem::forget(tmp); + + let field_offset = (field_addr as usize - container_addr as usize) as *const _; + + // Let Rust compiler infer our intended pointer type of field_offset + // by comparing it with another pointer. + let _: bool = field_offset == field_addr; + + field_offset + }); +} diff --git a/src/kxos-frame/src/vm/space.rs b/src/framework/jinux-frame/src/vm/space.rs similarity index 100% rename from src/kxos-frame/src/vm/space.rs rename to src/framework/jinux-frame/src/vm/space.rs diff --git a/src/kxos-frame/src/x86_64_util.rs b/src/framework/jinux-frame/src/x86_64_util.rs similarity index 100% rename from src/kxos-frame/src/x86_64_util.rs rename to src/framework/jinux-frame/src/x86_64_util.rs diff --git a/src/kxos-frame-pod-derive/Cargo.toml b/src/framework/pod-derive/Cargo.toml similarity index 89% rename from src/kxos-frame-pod-derive/Cargo.toml rename to src/framework/pod-derive/Cargo.toml index f1ed8313a..6325f297a 100644 --- a/src/kxos-frame-pod-derive/Cargo.toml +++ b/src/framework/pod-derive/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-frame-pod-derive" +name = "pod-derive" version = "0.1.0" edition = "2021" diff --git a/src/kxos-frame-pod-derive/src/lib.rs b/src/framework/pod-derive/src/lib.rs similarity index 88% rename from src/kxos-frame-pod-derive/src/lib.rs rename to src/framework/pod-derive/src/lib.rs index 69d231cd6..095d38232 100644 --- a/src/kxos-frame-pod-derive/src/lib.rs +++ b/src/framework/pod-derive/src/lib.rs @@ -1,5 +1,5 @@ -//! This crate is used to provide a procedural macro to derive Pod trait defined in kxos_frame. -//! When use this crate, kxos-frame should also be added as a dependency. +//! This crate is used to provide a procedural macro to derive Pod trait defined in framework/pod. +//! When use this crate, framework/pod should also be added as a dependency. //! This macro should only be used outside //! When derive Pod trait, we will do a check whether the derive is safe since Pod trait is an unsafe trait. //! For struct, we will check that the struct has valid repr (e.g,. repr(C), repr(u8)), and each field is Pod type. @@ -53,7 +53,7 @@ fn impl_pod_for_struct( .map(|field| { let field_ty = field.ty; quote! { - #field_ty: ::kxos_frame::Pod + #field_ty: ::pod::Pod } }) .collect::>(); @@ -62,12 +62,12 @@ fn impl_pod_for_struct( if where_clause.is_none() { quote! { #[automatically_derived] - unsafe impl #impl_generics ::kxos_frame::Pod #type_generics for #ident where #(#pod_where_predicates),* {} + unsafe impl #impl_generics ::pod::Pod #type_generics for #ident where #(#pod_where_predicates),* {} } } else { quote! { #[automatically_derived] - unsafe impl #impl_generics ::kxos_frame::Pod #type_generics for #ident #where_clause, #(#pod_where_predicates),* {} + unsafe impl #impl_generics ::pod::Pod #type_generics for #ident #where_clause, #(#pod_where_predicates),* {} } } } @@ -88,7 +88,7 @@ fn impl_pod_for_enum_or_union( let (impl_generics, type_generics, where_clause) = generics.split_for_impl(); quote! { #[automatically_derived] - unsafe impl #impl_generics ::kxos_frame::Pod #type_generics for #ident #where_clause {} + unsafe impl #impl_generics ::pod::Pod #type_generics for #ident #where_clause {} } } diff --git a/src/kxos-typeflags-util/Cargo.toml b/src/framework/pod/Cargo.toml similarity index 84% rename from src/kxos-typeflags-util/Cargo.toml rename to src/framework/pod/Cargo.toml index f47df8145..be11d00df 100644 --- a/src/kxos-typeflags-util/Cargo.toml +++ b/src/framework/pod/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-typeflags-util" +name = "pod" version = "0.1.0" edition = "2021" diff --git a/src/kxos-frame/src/vm/pod.rs b/src/framework/pod/src/lib.rs similarity index 64% rename from src/kxos-frame/src/vm/pod.rs rename to src/framework/pod/src/lib.rs index 479dbce11..6c03a19c5 100644 --- a/src/kxos-frame/src/vm/pod.rs +++ b/src/framework/pod/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use core::{fmt::Debug, mem::MaybeUninit}; /// A marker trait for plain old data (POD). @@ -57,43 +59,7 @@ macro_rules! impl_pod_for { $(unsafe impl Pod for $pod_ty {})* }; } - +// impl Pod for primitive types impl_pod_for!(u8, u16, u32, u64, i8, i16, i32, i64, isize, usize); - +// impl Pod for array unsafe impl Pod for [T; N] {} - -/// Get the offset of a field within a type as a pointer. -/// -/// ```rust -/// #[repr(C)] -/// pub struct Foo { -/// first: u8, -/// second: u32, -/// } -/// -/// assert!(offset_of(Foo, first) == (0 as *const u8)); -/// assert!(offset_of(Foo, second) == (4 as *const u32)); -/// ``` -#[macro_export] -macro_rules! offset_of { - ($container:ty, $($field:tt)+) => ({ - // SAFETY. It is ok to have this uninitialized value because - // 1) Its memory won't be acccessed; - // 2) It will be forgoten rather than being dropped; - // 3) Before it gets forgten, the code won't return prematurely or panic. - let tmp: $container = unsafe { core::mem::MaybeUninit::uninit().assume_init() }; - - let container_addr = &tmp as *const _; - let field_addr = &tmp.$($field)* as *const _; - - ::core::mem::forget(tmp); - - let field_offset = (field_addr as usize - container_addr as usize) as *const _; - - // Let Rust compiler infer our intended pointer type of field_offset - // by comparing it with another pointer. - let _: bool = field_offset == field_addr; - - field_offset - }); -} diff --git a/src/kxos-boot/Cargo.toml b/src/jinux-boot/Cargo.toml similarity index 94% rename from src/kxos-boot/Cargo.toml rename to src/jinux-boot/Cargo.toml index c41e2dbbf..333eb44f8 100644 --- a/src/kxos-boot/Cargo.toml +++ b/src/jinux-boot/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-boot" +name = "jinux-boot" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/kxos-boot/src/main.rs b/src/jinux-boot/src/main.rs similarity index 100% rename from src/kxos-boot/src/main.rs rename to src/jinux-boot/src/main.rs diff --git a/src/kxos-std/src/user_apps.rs b/src/kxos-std/src/user_apps.rs deleted file mode 100644 index 2180310c4..000000000 --- a/src/kxos-std/src/user_apps.rs +++ /dev/null @@ -1,122 +0,0 @@ -use crate::prelude::*; - -pub struct UserApp { - pub app_name: CString, - pub app_content: &'static [u8], - pub argv: Vec, - pub envp: Vec, -} - -impl UserApp { - pub fn new(app_name: &str, app_content: &'static [u8]) -> Self { - let app_name = CString::new(app_name).unwrap(); - UserApp { - app_name, - app_content, - argv: Vec::new(), - envp: Vec::new(), - } - } - - pub fn set_argv(&mut self, argv: Vec) { - self.argv = argv; - } - - pub fn set_envp(&mut self, envp: Vec) { - self.envp = envp; - } -} - -pub fn get_all_apps() -> Vec { - let mut res = Vec::with_capacity(16); - - // Most simple hello world, written in assembly - let asm_hello_world = UserApp::new("hello_world", read_hello_world_content()); - res.push(asm_hello_world); - - // Hello world, written in C language. - // Since glibc requires the app name starts with "/", and we don't have filesystem now. - // So we manually add a leading "/" for app written in C language. - let hello_c = UserApp::new("/hello_c", read_hello_c_content()); - res.push(hello_c); - - // Fork process, written in assembly - let asm_fork = UserApp::new("fork", read_fork_content()); - res.push(asm_fork); - - // Execve, written in C language. - let execve_c = UserApp::new("/execve", read_execve_content()); - res.push(execve_c); - - // Fork new process, written in C language. (Fork in glibc uses syscall clone actually) - let fork_c = UserApp::new("/fork", read_fork_c_content()); - res.push(fork_c); - - // signal test - let signal_test = UserApp::new("/signal_test", read_signal_test_content()); - res.push(signal_test); - - // busybox - let mut busybox = UserApp::new("/busybox", read_busybox_content()); - // -l option means the busybox is running as logging shell - let argv = ["/busybox", "sh", "-l"]; - // let envp = ["SHELL=/bin/bash", "COLORTERM=truecolor", "TERM_PROGRAM_VERSION=1.73.0", "LC_ADDRESS=zh_CN.UTF-8", "LC_NAME=zh_CN.UTF-8", "LC_MONETARY=zh_CN.UTF-8", "PWD=/", "LOGNAME=root", "XDG_SESSION_TYPE=tty", "VSCODE_GIT_ASKPASS_NODE=/home/jiangjf/.vscode-server/bin/8fa188b2b301d36553cbc9ce1b0a146ccb93351f/node", "MOTD_SHOWN=pam", "HOME=/home/jiangjf", "LC_PAPER=zh_CN.UTF-8", "LANG=en_US.UTF-8", "LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35", "GIT_ASKPASS=/home/jiangjf/.vscode-server/bin/8fa188b2b301d36553cbc9ce1b0a146ccb93351f/extensions/git/dist/askpass.sh", "SSH_CONNECTION=30.177.3.156 54687 30.77.178.76 22", "VSCODE_GIT_ASKPASS_EXTRA_ARGS=", "LESSCLOSE=/usr/bin/lesspipe %s %s", "XDG_SESSION_CLASS=user", "TERM=xterm-256color", "LC_IDENTIFICATION=zh_CN.UTF-8", "LESSOPEN=| /usr/bin/lesspipe %s", "USER=jiangjf", "VSCODE_GIT_IPC_HANDLE=/run/user/1015/vscode-git-623b69fb06.sock", "SHLVL=2", "LC_TELEPHONE=zh_CN.UTF-8", "LC_MEASUREMENT=zh_CN.UTF-8", "XDG_SESSION_ID=8884", "XDG_RUNTIME_DIR=/run/user/1015", "SSH_CLIENT=30.177.3.156 54687 22", "LC_TIME=zh_CN.UTF-8", "VSCODE_GIT_ASKPASS_MAIN=/home/jiangjf/.vscode-server/bin/8fa188b2b301d36553cbc9ce1b0a146ccb93351f/extensions/git/dist/askpass-main.js", "XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop", "BROWSER=/home/jiangjf/.vscode-server/bin/8fa188b2b301d36553cbc9ce1b0a146ccb93351f/bin/helpers/browser.sh", "PATH=/home/jiangjf/.vscode-server/bin/8fa188b2b301d36553cbc9ce1b0a146ccb93351f/bin/remote-cli:/home/jiangjf/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin", "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1015/bus", "LC_NUMERIC=zh_CN.UTF-8", "TERM_PROGRAM=vscode", "VSCODE_IPC_HOOK_CLI=/run/user/1015/vscode-ipc-ed06ed64-441d-4b59-a8fe-90ce2cf29a8a.sock", "OLDPWD=/"]; - let envp = [ - "SHELL=/bin/sh", - "PWD=/", - "LOGNAME=root", - "HOME=/", - "USER=root", - "PATH=", - "OLDPWD=/", - ]; - - let argv = to_vec_cstring(&argv).unwrap(); - let envp = to_vec_cstring(&envp).unwrap(); - busybox.set_argv(argv); - busybox.set_envp(envp); - res.push(busybox); - - res -} - -fn read_hello_world_content() -> &'static [u8] { - include_bytes!("../../kxos-user/hello_world/hello_world") -} - -fn read_hello_c_content() -> &'static [u8] { - include_bytes!("../../kxos-user/hello_c/hello") -} - -fn read_fork_content() -> &'static [u8] { - include_bytes!("../../kxos-user/fork/fork") -} - -fn read_execve_content() -> &'static [u8] { - include_bytes!("../../kxos-user/execve/execve") -} - -pub fn read_execve_hello_content() -> &'static [u8] { - include_bytes!("../../kxos-user/execve/hello") -} - -fn read_fork_c_content() -> &'static [u8] { - include_bytes!("../../kxos-user/fork_c/fork") -} - -fn read_signal_test_content() -> &'static [u8] { - include_bytes!("../../kxos-user/signal_c/signal_test") -} - -fn read_busybox_content() -> &'static [u8] { - include_bytes!("../../kxos-user/busybox/busybox") -} - -fn to_vec_cstring(raw_strs: &[&str]) -> Result> { - let mut res = Vec::new(); - for raw_str in raw_strs { - let cstring = CString::new(*raw_str)?; - res.push(cstring); - } - Ok(res) -} diff --git a/src/kxos-user/hello_c/hello b/src/kxos-user/hello_c/hello deleted file mode 100755 index 4db2c3de7..000000000 --- a/src/kxos-user/hello_c/hello +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:dda5a7d6081cc2252056375d0550731ef2fd24789aa5f17da189a36bf78c588d -size 871896 diff --git a/src/kxos-virtio/Cargo.toml b/src/kxos-virtio/Cargo.toml deleted file mode 100644 index e248d9693..000000000 --- a/src/kxos-virtio/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "kxos-virtio" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -bitflags = "1.3" -spin = "0.9.4" -kxos-frame = {path = "../kxos-frame"} -kxos-pci = {path="../kxos-pci"} -kxos-util = {path="../kxos-util"} -kxos-frame-pod-derive = {path = "../kxos-frame-pod-derive"} - - -[features] - diff --git a/src/kxos-pci/Cargo.toml b/src/services/comps/jinux-pci/Cargo.toml similarity index 56% rename from src/kxos-pci/Cargo.toml rename to src/services/comps/jinux-pci/Cargo.toml index e936683aa..dff4cd5fe 100644 --- a/src/kxos-pci/Cargo.toml +++ b/src/services/comps/jinux-pci/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-pci" +name = "jinux-pci" version = "0.1.0" edition = "2021" @@ -8,9 +8,10 @@ edition = "2021" [dependencies] bitflags = "1.3" spin = "0.9.4" -kxos-frame = {path = "../kxos-frame"} -kxos-util = {path="../kxos-util"} -kxos-frame-pod-derive = {path = "../kxos-frame-pod-derive"} +jinux-frame = {path = "../../../framework/jinux-frame"} +jinux-util = {path="../../libs/jinux-util"} +pod = {path = "../../../framework/pod"} +pod-derive = {path = "../../../framework/pod-derive"} [dependencies.lazy_static] version = "1.0" diff --git a/src/kxos-pci/src/capability/exp.rs b/src/services/comps/jinux-pci/src/capability/exp.rs similarity index 100% rename from src/kxos-pci/src/capability/exp.rs rename to src/services/comps/jinux-pci/src/capability/exp.rs diff --git a/src/kxos-pci/src/capability/mod.rs b/src/services/comps/jinux-pci/src/capability/mod.rs similarity index 100% rename from src/kxos-pci/src/capability/mod.rs rename to src/services/comps/jinux-pci/src/capability/mod.rs diff --git a/src/kxos-pci/src/capability/msi.rs b/src/services/comps/jinux-pci/src/capability/msi.rs similarity index 100% rename from src/kxos-pci/src/capability/msi.rs rename to src/services/comps/jinux-pci/src/capability/msi.rs diff --git a/src/kxos-pci/src/capability/msix.rs b/src/services/comps/jinux-pci/src/capability/msix.rs similarity index 100% rename from src/kxos-pci/src/capability/msix.rs rename to src/services/comps/jinux-pci/src/capability/msix.rs diff --git a/src/kxos-pci/src/capability/pm.rs b/src/services/comps/jinux-pci/src/capability/pm.rs similarity index 100% rename from src/kxos-pci/src/capability/pm.rs rename to src/services/comps/jinux-pci/src/capability/pm.rs diff --git a/src/kxos-pci/src/capability/sata.rs b/src/services/comps/jinux-pci/src/capability/sata.rs similarity index 100% rename from src/kxos-pci/src/capability/sata.rs rename to src/services/comps/jinux-pci/src/capability/sata.rs diff --git a/src/kxos-pci/src/capability/vendor/mod.rs b/src/services/comps/jinux-pci/src/capability/vendor/mod.rs similarity index 100% rename from src/kxos-pci/src/capability/vendor/mod.rs rename to src/services/comps/jinux-pci/src/capability/vendor/mod.rs diff --git a/src/kxos-pci/src/capability/vendor/virtio.rs b/src/services/comps/jinux-pci/src/capability/vendor/virtio.rs similarity index 100% rename from src/kxos-pci/src/capability/vendor/virtio.rs rename to src/services/comps/jinux-pci/src/capability/vendor/virtio.rs diff --git a/src/kxos-pci/src/lib.rs b/src/services/comps/jinux-pci/src/lib.rs similarity index 94% rename from src/kxos-pci/src/lib.rs rename to src/services/comps/jinux-pci/src/lib.rs index f83952167..856a7be7a 100644 --- a/src/kxos-pci/src/lib.rs +++ b/src/services/comps/jinux-pci/src/lib.rs @@ -1,4 +1,4 @@ -//! The pci of kxos +//! The pci of jinux #![no_std] #![forbid(unsafe_code)] #![allow(dead_code)] @@ -6,8 +6,9 @@ pub mod capability; pub mod msix; pub mod util; extern crate alloc; -use kxos_frame::info; -extern crate kxos_frame_pod_derive; +use jinux_frame::info; +#[macro_use] +extern crate pod_derive; use alloc::{sync::Arc, vec::Vec}; use lazy_static::lazy_static; diff --git a/src/kxos-pci/src/msix.rs b/src/services/comps/jinux-pci/src/msix.rs similarity index 93% rename from src/kxos-pci/src/msix.rs rename to src/services/comps/jinux-pci/src/msix.rs index 803e0291b..a34125ee0 100644 --- a/src/kxos-pci/src/msix.rs +++ b/src/services/comps/jinux-pci/src/msix.rs @@ -1,12 +1,11 @@ use alloc::vec::Vec; use crate::util::{CSpaceAccessMethod, Location, BAR}; -use kxos_frame_pod_derive::Pod; use super::capability::msix::CapabilityMSIXData; -use kxos_frame::{offset_of, IrqAllocateHandle}; -use kxos_util::frame_ptr::InFramePtr; +use jinux_frame::{offset_of, IrqAllocateHandle}; +use jinux_util::frame_ptr::InFramePtr; #[derive(Debug, Default)] pub struct MSIX { @@ -72,7 +71,7 @@ impl MSIX { // let mut value = MSIXTableEntry::default(); value.write_at(offset_of!(MSIXTableEntry, msg_addr), 0xFEE0_0000 as u32); // allocate irq number - let handle = kxos_frame::allocate_irq().expect("not enough irq"); + let handle = jinux_frame::allocate_irq().expect("not enough irq"); value.write_at(offset_of!(MSIXTableEntry, msg_data), handle.num() as u32); value.write_at(offset_of!(MSIXTableEntry, vector_control), 0 as u32); cap.table.push(MSIXEntry { diff --git a/src/kxos-pci/src/util.rs b/src/services/comps/jinux-pci/src/util.rs similarity index 98% rename from src/kxos-pci/src/util.rs rename to src/services/comps/jinux-pci/src/util.rs index 316508052..06315cf62 100644 --- a/src/kxos-pci/src/util.rs +++ b/src/services/comps/jinux-pci/src/util.rs @@ -1,4 +1,4 @@ -extern crate kxos_frame; +extern crate jinux_frame; use crate::capability::Capability; use alloc::vec::Vec; use bitflags::bitflags; @@ -37,9 +37,9 @@ impl CSpaceAccessMethod { ); match self { CSpaceAccessMethod::IO => { - kxos_frame::device::pci::PCI_ADDRESS_PORT + jinux_frame::device::pci::PCI_ADDRESS_PORT .write_u32(loc.encode() | ((offset as u32) & 0b11111100)); - kxos_frame::device::pci::PCI_DATA_PORT.read_u32().to_le() + jinux_frame::device::pci::PCI_DATA_PORT.read_u32().to_le() } //MemoryMapped(ptr) => { // // FIXME: Clarify whether the rules for GEP/GEPi forbid using regular .offset() here. // ::core::intrinsics::volatile_load(::core::intrinsics::arith_offset(ptr, offset as usize)) @@ -71,9 +71,9 @@ impl CSpaceAccessMethod { ); match self { CSpaceAccessMethod::IO => { - kxos_frame::device::pci::PCI_ADDRESS_PORT + jinux_frame::device::pci::PCI_ADDRESS_PORT .write_u32(loc.encode() | (offset as u32 & 0b11111100)); - kxos_frame::device::pci::PCI_ADDRESS_PORT.write_u32(val.to_le()) + jinux_frame::device::pci::PCI_ADDRESS_PORT.write_u32(val.to_le()) } //MemoryMapped(ptr) => { // // FIXME: Clarify whether the rules for GEP/GEPi forbid using regular .offset() here. // ::core::intrinsics::volatile_load(::core::intrinsics::arith_offset(ptr, offset as usize)) diff --git a/src/services/comps/jinux-virtio/Cargo.toml b/src/services/comps/jinux-virtio/Cargo.toml new file mode 100644 index 000000000..07da9189a --- /dev/null +++ b/src/services/comps/jinux-virtio/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "jinux-virtio" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bitflags = "1.3" +spin = "0.9.4" +jinux-frame = {path = "../../../framework/jinux-frame"} +jinux-pci = {path="../jinux-pci"} +jinux-util = {path="../../libs/jinux-util"} +pod = {path = "../../../framework/pod"} +pod-derive = {path = "../../../framework/pod-derive"} + + +[features] + diff --git a/src/kxos-virtio/src/block.rs b/src/services/comps/jinux-virtio/src/block.rs similarity index 91% rename from src/kxos-virtio/src/block.rs rename to src/services/comps/jinux-virtio/src/block.rs index c02127952..ccbd33960 100644 --- a/src/kxos-virtio/src/block.rs +++ b/src/services/comps/jinux-virtio/src/block.rs @@ -1,6 +1,6 @@ -use kxos_pci::capability::vendor::virtio::CapabilityVirtioData; -use kxos_pci::util::BAR; -use kxos_util::frame_ptr::InFramePtr; +use jinux_pci::capability::vendor::virtio::CapabilityVirtioData; +use jinux_pci::util::BAR; +use jinux_util::frame_ptr::InFramePtr; pub const BLK_SIZE: usize = 512; diff --git a/src/kxos-virtio/src/lib.rs b/src/services/comps/jinux-virtio/src/lib.rs similarity index 94% rename from src/kxos-virtio/src/lib.rs rename to src/services/comps/jinux-virtio/src/lib.rs index 88bc3534c..3a6197b59 100644 --- a/src/kxos-virtio/src/lib.rs +++ b/src/services/comps/jinux-virtio/src/lib.rs @@ -1,4 +1,4 @@ -//! The virtio of kxos +//! The virtio of jinux #![no_std] #![forbid(unsafe_code)] #![allow(dead_code)] @@ -6,17 +6,16 @@ extern crate alloc; use alloc::{sync::Arc, vec::Vec}; use bitflags::bitflags; -use kxos_frame::{info, offset_of, TrapFrame}; -use kxos_frame_pod_derive::Pod; -use kxos_pci::util::{PCIDevice, BAR}; -use kxos_util::frame_ptr::InFramePtr; +use jinux_frame::{info, offset_of, TrapFrame}; +use jinux_pci::util::{PCIDevice, BAR}; +use jinux_util::frame_ptr::InFramePtr; use spin::{mutex::Mutex, MutexGuard}; use self::{block::VirtioBLKConfig, queue::VirtQueue}; -use kxos_pci::{capability::vendor::virtio::CapabilityVirtioData, msix::MSIX}; +use jinux_pci::{capability::vendor::virtio::CapabilityVirtioData, msix::MSIX}; #[macro_use] -extern crate kxos_frame_pod_derive; +extern crate pod_derive; pub mod block; pub mod queue; @@ -157,8 +156,8 @@ impl PCIVirtioDevice { let mut common_cfg_frame_ptr_some = None; for cap in dev.capabilities.iter() { match &cap.data { - kxos_pci::capability::CapabilityData::VNDR(vndr_data) => match vndr_data { - kxos_pci::capability::vendor::CapabilityVNDRData::VIRTIO(cap_data) => { + jinux_pci::capability::CapabilityData::VNDR(vndr_data) => match vndr_data { + jinux_pci::capability::vendor::CapabilityVNDRData::VIRTIO(cap_data) => { match cap_data.cfg_type { PCI_VIRTIO_CAP_COMMON_CFG => { common_cfg_frame_ptr_some = @@ -196,10 +195,10 @@ impl PCIVirtioDevice { } }, - kxos_pci::capability::CapabilityData::MSIX(cap_data) => { + jinux_pci::capability::CapabilityData::MSIX(cap_data) => { msix = MSIX::new(&cap_data, bars, loc, cap.cap_ptr); } - kxos_pci::capability::CapabilityData::Unknown(id) => { + jinux_pci::capability::CapabilityData::Unknown(id) => { panic!("unknown capability device:{}", id) } _ => { diff --git a/src/kxos-virtio/src/queue.rs b/src/services/comps/jinux-virtio/src/queue.rs similarity index 97% rename from src/kxos-virtio/src/queue.rs rename to src/services/comps/jinux-virtio/src/queue.rs index e7e1b4c5f..3e2351890 100644 --- a/src/kxos-virtio/src/queue.rs +++ b/src/services/comps/jinux-virtio/src/queue.rs @@ -4,8 +4,8 @@ use super::VitrioPciCommonCfg; use alloc::vec::Vec; use bitflags::bitflags; use core::sync::atomic::{fence, Ordering}; -use kxos_frame::offset_of; -use kxos_util::frame_ptr::InFramePtr; +use jinux_frame::offset_of; +use jinux_util::frame_ptr::InFramePtr; #[derive(Debug)] pub enum QueueError { InvalidArgs, @@ -239,7 +239,7 @@ struct Descriptor { impl Descriptor { fn set_buf(&mut self, buf: &[u8]) { - self.addr = kxos_frame::virt_to_phys(buf.as_ptr() as usize) as u64; + self.addr = jinux_frame::virt_to_phys(buf.as_ptr() as usize) as u64; self.len = buf.len() as u32; } } @@ -247,7 +247,7 @@ impl Descriptor { fn set_buf(inframe_ptr: &InFramePtr, buf: &[u8]) { inframe_ptr.write_at( offset_of!(Descriptor, addr), - kxos_frame::virt_to_phys(buf.as_ptr() as usize) as u64, + jinux_frame::virt_to_phys(buf.as_ptr() as usize) as u64, ); inframe_ptr.write_at(offset_of!(Descriptor, len), buf.len() as u32); } diff --git a/src/kxos-rights-proc/Cargo.toml b/src/services/libs/jinux-rights-proc/Cargo.toml similarity index 91% rename from src/kxos-rights-proc/Cargo.toml rename to src/services/libs/jinux-rights-proc/Cargo.toml index 2ae1454c2..81c8dd134 100644 --- a/src/kxos-rights-proc/Cargo.toml +++ b/src/services/libs/jinux-rights-proc/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-rights-proc" +name = "jinux-rights-proc" version = "0.1.0" edition = "2021" diff --git a/src/kxos-rights-proc/src/lib.rs b/src/services/libs/jinux-rights-proc/src/lib.rs similarity index 96% rename from src/kxos-rights-proc/src/lib.rs rename to src/services/libs/jinux-rights-proc/src/lib.rs index 12cf35291..8058aac48 100644 --- a/src/kxos-rights-proc/src/lib.rs +++ b/src/services/libs/jinux-rights-proc/src/lib.rs @@ -1,5 +1,5 @@ -//!This crate defines the require procedural macros to implement capability for kxos. -//! When use this crate, kxos-typeflags and kxos-typeflags-util should also be added as dependency. +//!This crate defines the require procedural macros to implement capability for jinux. +//! When use this crate, typeflags and typeflags-util should also be added as dependency. //! //! The require macro are used to ensure that an object has the enough capability to call the function. //! The **require** macro can accept constrait [SomeRightSet] > [SomeRight], diff --git a/src/kxos-rights-proc/src/require_attr.rs b/src/services/libs/jinux-rights-proc/src/require_attr.rs similarity index 92% rename from src/kxos-rights-proc/src/require_attr.rs rename to src/services/libs/jinux-rights-proc/src/require_attr.rs index 24f50e6f1..7c22b0c73 100644 --- a/src/kxos-rights-proc/src/require_attr.rs +++ b/src/services/libs/jinux-rights-proc/src/require_attr.rs @@ -98,10 +98,10 @@ fn set_contain_where_clause( let type_set = require_attr.type_set.clone(); let mut where_predicates = Vec::new(); where_predicates.push(parse_quote!( - #type_set: ::kxos_typeflags_util::SetContain<#required_type> + #type_set: ::typeflags_util::SetContain<#required_type> )); where_predicates.push(parse_quote!( - ::kxos_typeflags_util::SetContainOp<#type_set, #required_type>: ::kxos_typeflags_util::IsTrue + ::typeflags_util::SetContainOp<#type_set, #required_type>: ::typeflags_util::IsTrue )); let comma = parse_quote!(,); @@ -150,14 +150,14 @@ fn set_include_where_clause( let mut additional_where_prediates = Vec::new(); additional_where_prediates.push(parse_quote!( - #required_type_set: ::kxos_typeflags_util::Set + #required_type_set: ::typeflags_util::Set )); additional_where_prediates.push(parse_quote!( - #type_set: ::kxos_typeflags_util::SetInclude<#required_type_set> + #type_set: ::typeflags_util::SetInclude<#required_type_set> )); additional_where_prediates.push(parse_quote!( - ::kxos_typeflags_util::SetIncludeOp<#type_set, #required_type_set>: ::kxos_typeflags_util::IsTrue - )); + ::typeflags_util::SetIncludeOp<#type_set, #required_type_set>: ::typeflags_util::IsTrue + )); match old_where_clause { None => { diff --git a/src/kxos-std/Cargo.toml b/src/services/libs/jinux-std/Cargo.toml similarity index 52% rename from src/kxos-std/Cargo.toml rename to src/services/libs/jinux-std/Cargo.toml index a8dc8db24..138d83c33 100644 --- a/src/kxos-std/Cargo.toml +++ b/src/services/libs/jinux-std/Cargo.toml @@ -1,18 +1,19 @@ [package] -name = "kxos-std" +name = "jinux-std" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -kxos-frame = {path = "../kxos-frame"} -kxos-frame-pod-derive = {path = "../kxos-frame-pod-derive"} -kxos-pci = {path="../kxos-pci"} -kxos-virtio = {path="../kxos-virtio"} -kxos-typeflags = {path="../kxos-typeflags"} -kxos-typeflags-util = {path="../kxos-typeflags-util"} -kxos-rights-proc = {path="../kxos-rights-proc"} +jinux-frame = {path = "../../../framework/jinux-frame"} +pod = {path = "../../../framework/pod"} +pod-derive = {path = "../../../framework/pod-derive"} +jinux-pci = {path="../../comps/jinux-pci"} +jinux-virtio = {path="../../comps/jinux-virtio"} +typeflags = {path="../typeflags"} +typeflags-util = {path="../typeflags-util"} +jinux-rights-proc = {path="../jinux-rights-proc"} # parse elf file xmas-elf = "0.8.0" diff --git a/src/kxos-std/src/driver/mod.rs b/src/services/libs/jinux-std/src/driver/mod.rs similarity index 100% rename from src/kxos-std/src/driver/mod.rs rename to src/services/libs/jinux-std/src/driver/mod.rs diff --git a/src/kxos-std/src/driver/pci/mod.rs b/src/services/libs/jinux-std/src/driver/pci/mod.rs similarity index 72% rename from src/kxos-std/src/driver/pci/mod.rs rename to src/services/libs/jinux-std/src/driver/pci/mod.rs index 2afba6e5f..ca2290a14 100644 --- a/src/kxos-std/src/driver/pci/mod.rs +++ b/src/services/libs/jinux-std/src/driver/pci/mod.rs @@ -1,10 +1,10 @@ pub mod virtio; -use kxos_frame::info; +use jinux_frame::info; pub fn init() { - kxos_pci::init(); - for index in 0..kxos_pci::device_amount() { - let pci_device = kxos_pci::get_pci_devices(index) + jinux_pci::init(); + for index in 0..jinux_pci::device_amount() { + let pci_device = jinux_pci::get_pci_devices(index) .expect("initialize pci device failed: pci device is None"); if pci_device.id.vendor_id == 0x1af4 && (pci_device.id.device_id == 0x1001 || pci_device.id.device_id == 0x1042) diff --git a/src/kxos-std/src/driver/pci/virtio/block.rs b/src/services/libs/jinux-std/src/driver/pci/virtio/block.rs similarity index 97% rename from src/kxos-std/src/driver/pci/virtio/block.rs rename to src/services/libs/jinux-std/src/driver/pci/virtio/block.rs index 981dbc3c5..bec9f7486 100644 --- a/src/kxos-std/src/driver/pci/virtio/block.rs +++ b/src/services/libs/jinux-std/src/driver/pci/virtio/block.rs @@ -3,16 +3,16 @@ use core::hint::spin_loop; use crate::process::Process; use alloc::sync::Arc; use alloc::vec::Vec; -use kxos_frame::info; -use kxos_pci::PCIDevice; -use kxos_virtio::PCIVirtioDevice; +use jinux_frame::info; +use jinux_pci::PCIDevice; +use jinux_virtio::PCIVirtioDevice; use lazy_static::lazy_static; use spin::mutex::Mutex; use super::BlockDevice; pub const BLK_SIZE: usize = 512; -use kxos_frame::Pod; -use kxos_frame::TrapFrame; +use jinux_frame::TrapFrame; +use pod::Pod; pub struct VirtioBlockDevice { virtio_device: PCIVirtioDevice, } diff --git a/src/kxos-std/src/driver/pci/virtio/mod.rs b/src/services/libs/jinux-std/src/driver/pci/virtio/mod.rs similarity index 100% rename from src/kxos-std/src/driver/pci/virtio/mod.rs rename to src/services/libs/jinux-std/src/driver/pci/virtio/mod.rs diff --git a/src/kxos-std/src/error.rs b/src/services/libs/jinux-std/src/error.rs similarity index 92% rename from src/kxos-std/src/error.rs rename to src/services/libs/jinux-std/src/error.rs index 7f2c91f83..7792ca993 100644 --- a/src/kxos-std/src/error.rs +++ b/src/services/libs/jinux-std/src/error.rs @@ -178,17 +178,17 @@ impl From for Error { } } -impl From for Error { - fn from(frame_error: kxos_frame::Error) -> Self { +impl From for Error { + fn from(frame_error: jinux_frame::Error) -> Self { match frame_error { - kxos_frame::Error::AccessDenied => Error::new(Errno::EFAULT), - kxos_frame::Error::NoMemory => Error::new(Errno::ENOMEM), - kxos_frame::Error::InvalidArgs => Error::new(Errno::EINVAL), - kxos_frame::Error::IoError => Error::new(Errno::EIO), - kxos_frame::Error::NotEnoughResources => Error::new(Errno::EBUSY), - kxos_frame::Error::PageFault => Error::new(Errno::EFAULT), - kxos_frame::Error::InvalidVmpermBits => Error::new(Errno::EINVAL), - kxos_frame::Error::NoChild => Error::new(Errno::ECHILD), + jinux_frame::Error::AccessDenied => Error::new(Errno::EFAULT), + jinux_frame::Error::NoMemory => Error::new(Errno::ENOMEM), + jinux_frame::Error::InvalidArgs => Error::new(Errno::EINVAL), + jinux_frame::Error::IoError => Error::new(Errno::EIO), + jinux_frame::Error::NotEnoughResources => Error::new(Errno::EBUSY), + jinux_frame::Error::PageFault => Error::new(Errno::EFAULT), + jinux_frame::Error::InvalidVmpermBits => Error::new(Errno::EINVAL), + jinux_frame::Error::NoChild => Error::new(Errno::ECHILD), } } } diff --git a/src/kxos-std/src/fs/events.rs b/src/services/libs/jinux-std/src/fs/events.rs similarity index 100% rename from src/kxos-std/src/fs/events.rs rename to src/services/libs/jinux-std/src/fs/events.rs diff --git a/src/kxos-std/src/fs/fcntl.rs b/src/services/libs/jinux-std/src/fs/fcntl.rs similarity index 100% rename from src/kxos-std/src/fs/fcntl.rs rename to src/services/libs/jinux-std/src/fs/fcntl.rs diff --git a/src/kxos-std/src/fs/file.rs b/src/services/libs/jinux-std/src/fs/file.rs similarity index 100% rename from src/kxos-std/src/fs/file.rs rename to src/services/libs/jinux-std/src/fs/file.rs diff --git a/src/kxos-std/src/fs/file_table.rs b/src/services/libs/jinux-std/src/fs/file_table.rs similarity index 100% rename from src/kxos-std/src/fs/file_table.rs rename to src/services/libs/jinux-std/src/fs/file_table.rs diff --git a/src/kxos-std/src/fs/ioctl/mod.rs b/src/services/libs/jinux-std/src/fs/ioctl/mod.rs similarity index 100% rename from src/kxos-std/src/fs/ioctl/mod.rs rename to src/services/libs/jinux-std/src/fs/ioctl/mod.rs diff --git a/src/kxos-std/src/fs/mod.rs b/src/services/libs/jinux-std/src/fs/mod.rs similarity index 100% rename from src/kxos-std/src/fs/mod.rs rename to src/services/libs/jinux-std/src/fs/mod.rs diff --git a/src/kxos-std/src/fs/poll.rs b/src/services/libs/jinux-std/src/fs/poll.rs similarity index 100% rename from src/kxos-std/src/fs/poll.rs rename to src/services/libs/jinux-std/src/fs/poll.rs diff --git a/src/kxos-std/src/fs/stat.rs b/src/services/libs/jinux-std/src/fs/stat.rs similarity index 100% rename from src/kxos-std/src/fs/stat.rs rename to src/services/libs/jinux-std/src/fs/stat.rs diff --git a/src/kxos-std/src/fs/stdio.rs b/src/services/libs/jinux-std/src/fs/stdio.rs similarity index 100% rename from src/kxos-std/src/fs/stdio.rs rename to src/services/libs/jinux-std/src/fs/stdio.rs diff --git a/src/kxos-std/src/lib.rs b/src/services/libs/jinux-std/src/lib.rs similarity index 90% rename from src/kxos-std/src/lib.rs rename to src/services/libs/jinux-std/src/lib.rs index c56094f57..af17bb177 100644 --- a/src/kxos-std/src/lib.rs +++ b/src/services/libs/jinux-std/src/lib.rs @@ -1,4 +1,4 @@ -//! The std library of kxos +//! The std library of jinux #![no_std] #![forbid(unsafe_code)] #![allow(dead_code)] @@ -12,7 +12,7 @@ #![feature(extend_one)] use crate::{prelude::*, user_apps::UserApp}; -use kxos_frame::{info, println}; +use jinux_frame::{info, println}; use process::Process; use crate::{ @@ -38,7 +38,7 @@ mod user_apps; mod util; pub mod vm; #[macro_use] -extern crate kxos_frame_pod_derive; +extern crate pod_derive; pub fn init() { driver::init(); @@ -57,7 +57,7 @@ pub fn init_process() { info!("current ppid = {}", ppid); }); info!( - "[kxos-std/lib.rs] spawn kernel process, pid = {}", + "[jinux-std/lib.rs] spawn kernel process, pid = {}", process.pid() ); @@ -68,7 +68,7 @@ pub fn init_process() { argv, envp, } = app; - info!("[kxos-std/lib.rs] spwan {:?} process", app_name); + info!("[jinux-std/lib.rs] spwan {:?} process", app_name); print!("\n"); print!("BusyBox v1.35.0 built-in shell (ash)\n\n"); Process::spawn_user_process(app_name.clone(), app_content, argv, Vec::new()); diff --git a/src/kxos-std/src/memory/mod.rs b/src/services/libs/jinux-std/src/memory/mod.rs similarity index 97% rename from src/kxos-std/src/memory/mod.rs rename to src/services/libs/jinux-std/src/memory/mod.rs index 3849085ee..51565e051 100644 --- a/src/kxos-std/src/memory/mod.rs +++ b/src/services/libs/jinux-std/src/memory/mod.rs @@ -1,5 +1,6 @@ use crate::prelude::*; -use kxos_frame::vm::{Pod, VmIo}; +use jinux_frame::vm::VmIo; +use pod::Pod; pub mod vm_page; diff --git a/src/kxos-std/src/memory/vm_page.rs b/src/services/libs/jinux-std/src/memory/vm_page.rs similarity index 98% rename from src/kxos-std/src/memory/vm_page.rs rename to src/services/libs/jinux-std/src/memory/vm_page.rs index cfafc4ec4..6553b716f 100644 --- a/src/kxos-std/src/memory/vm_page.rs +++ b/src/services/libs/jinux-std/src/memory/vm_page.rs @@ -1,7 +1,7 @@ //! A Page in virtual address space use crate::prelude::*; use core::ops::Range; -use kxos_frame::vm::{VmAllocOptions, VmFrameVec, VmIo, VmMapOptions, VmPerm, VmSpace}; +use jinux_frame::vm::{VmAllocOptions, VmFrameVec, VmIo, VmMapOptions, VmPerm, VmSpace}; /// A set of **CONTINUOUS** virtual pages in VmSpace pub struct VmPageRange { diff --git a/src/kxos-std/src/prelude.rs b/src/services/libs/jinux-std/src/prelude.rs similarity index 82% rename from src/kxos-std/src/prelude.rs rename to src/services/libs/jinux-std/src/prelude.rs index 7a80a5708..05784017e 100644 --- a/src/kxos-std/src/prelude.rs +++ b/src/services/libs/jinux-std/src/prelude.rs @@ -11,9 +11,9 @@ pub(crate) use alloc::vec; pub(crate) use alloc::vec::Vec; pub(crate) use bitflags::bitflags; pub(crate) use core::ffi::CStr; -pub(crate) use kxos_frame::config::PAGE_SIZE; -pub(crate) use kxos_frame::vm::Vaddr; -pub(crate) use kxos_frame::{debug, error, info, print, println, trace, warn}; +pub(crate) use jinux_frame::config::PAGE_SIZE; +pub(crate) use jinux_frame::vm::Vaddr; +pub(crate) use jinux_frame::{debug, error, info, print, println, trace, warn}; pub(crate) use spin::Mutex; #[macro_export] diff --git a/src/kxos-std/src/process/clone.rs b/src/services/libs/jinux-std/src/process/clone.rs similarity index 99% rename from src/kxos-std/src/process/clone.rs rename to src/services/libs/jinux-std/src/process/clone.rs index 7a17af55a..9aace2982 100644 --- a/src/kxos-std/src/process/clone.rs +++ b/src/services/libs/jinux-std/src/process/clone.rs @@ -1,4 +1,4 @@ -use kxos_frame::{ +use jinux_frame::{ cpu::CpuContext, user::UserSpace, vm::{VmIo, VmSpace}, diff --git a/src/kxos-std/src/process/elf/aux_vec.rs b/src/services/libs/jinux-std/src/process/elf/aux_vec.rs similarity index 100% rename from src/kxos-std/src/process/elf/aux_vec.rs rename to src/services/libs/jinux-std/src/process/elf/aux_vec.rs diff --git a/src/kxos-std/src/process/elf/elf.rs b/src/services/libs/jinux-std/src/process/elf/elf.rs similarity index 99% rename from src/kxos-std/src/process/elf/elf.rs rename to src/services/libs/jinux-std/src/process/elf/elf.rs index 1f6d215aa..6fb402e6d 100644 --- a/src/kxos-std/src/process/elf/elf.rs +++ b/src/services/libs/jinux-std/src/process/elf/elf.rs @@ -6,7 +6,7 @@ use crate::{ prelude::*, }; use core::{cmp::Ordering, ops::Range}; -use kxos_frame::vm::{VmAllocOptions, VmFrameVec, VmIo, VmPerm, VmSpace}; +use jinux_frame::vm::{VmAllocOptions, VmFrameVec, VmIo, VmPerm, VmSpace}; use xmas_elf::{ header, program::{self, ProgramHeader, ProgramHeader64, SegmentData}, diff --git a/src/kxos-std/src/process/elf/init_stack.rs b/src/services/libs/jinux-std/src/process/elf/init_stack.rs similarity index 99% rename from src/kxos-std/src/process/elf/init_stack.rs rename to src/services/libs/jinux-std/src/process/elf/init_stack.rs index 3c951085b..82caea531 100644 --- a/src/kxos-std/src/process/elf/init_stack.rs +++ b/src/services/libs/jinux-std/src/process/elf/init_stack.rs @@ -4,7 +4,7 @@ use crate::{memory::vm_page::VmPageRange, prelude::*}; use core::mem; -use kxos_frame::{ +use jinux_frame::{ vm::{VmIo, VmPerm, VmSpace}, AlignExt, }; diff --git a/src/kxos-std/src/process/elf/mod.rs b/src/services/libs/jinux-std/src/process/elf/mod.rs similarity index 96% rename from src/kxos-std/src/process/elf/mod.rs rename to src/services/libs/jinux-std/src/process/elf/mod.rs index 0f889928c..0dcb86cc7 100644 --- a/src/kxos-std/src/process/elf/mod.rs +++ b/src/services/libs/jinux-std/src/process/elf/mod.rs @@ -2,7 +2,7 @@ pub mod aux_vec; pub mod elf; pub mod init_stack; -use kxos_frame::vm::VmSpace; +use jinux_frame::vm::VmSpace; use self::elf::ElfLoadInfo; use crate::prelude::*; diff --git a/src/kxos-std/src/process/exception.rs b/src/services/libs/jinux-std/src/process/exception.rs similarity index 93% rename from src/kxos-std/src/process/exception.rs rename to src/services/libs/jinux-std/src/process/exception.rs index 394b9820d..a183cebc9 100644 --- a/src/kxos-std/src/process/exception.rs +++ b/src/services/libs/jinux-std/src/process/exception.rs @@ -1,4 +1,4 @@ -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use crate::{prelude::*, process::signal::signals::fault::FaultSignal}; diff --git a/src/kxos-std/src/process/fifo_scheduler.rs b/src/services/libs/jinux-std/src/process/fifo_scheduler.rs similarity index 92% rename from src/kxos-std/src/process/fifo_scheduler.rs rename to src/services/libs/jinux-std/src/process/fifo_scheduler.rs index 9ba6f41c9..21a07e33e 100644 --- a/src/kxos-std/src/process/fifo_scheduler.rs +++ b/src/services/libs/jinux-std/src/process/fifo_scheduler.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use kxos_frame::task::{set_scheduler, Scheduler, Task}; +use jinux_frame::task::{set_scheduler, Scheduler, Task}; pub const TASK_INIT_CAPABILITY: usize = 16; diff --git a/src/kxos-std/src/process/mod.rs b/src/services/libs/jinux-std/src/process/mod.rs similarity index 99% rename from src/kxos-std/src/process/mod.rs rename to src/services/libs/jinux-std/src/process/mod.rs index cd5a69c78..a934465cd 100644 --- a/src/kxos-std/src/process/mod.rs +++ b/src/services/libs/jinux-std/src/process/mod.rs @@ -15,8 +15,8 @@ use self::task::create_user_task_from_elf; use crate::fs::file_table::FileTable; use crate::prelude::*; use crate::tty::get_console; -use kxos_frame::sync::WaitQueue; -use kxos_frame::{task::Task, user::UserSpace, vm::VmSpace}; +use jinux_frame::sync::WaitQueue; +use jinux_frame::{task::Task, user::UserSpace, vm::VmSpace}; pub mod clone; pub mod elf; diff --git a/src/kxos-std/src/process/name.rs b/src/services/libs/jinux-std/src/process/name.rs similarity index 100% rename from src/kxos-std/src/process/name.rs rename to src/services/libs/jinux-std/src/process/name.rs diff --git a/src/kxos-std/src/process/process_filter.rs b/src/services/libs/jinux-std/src/process/process_filter.rs similarity index 100% rename from src/kxos-std/src/process/process_filter.rs rename to src/services/libs/jinux-std/src/process/process_filter.rs diff --git a/src/kxos-std/src/process/process_group.rs b/src/services/libs/jinux-std/src/process/process_group.rs similarity index 100% rename from src/kxos-std/src/process/process_group.rs rename to src/services/libs/jinux-std/src/process/process_group.rs diff --git a/src/kxos-std/src/process/process_vm/mmap_area.rs b/src/services/libs/jinux-std/src/process/process_vm/mmap_area.rs similarity index 98% rename from src/kxos-std/src/process/process_vm/mmap_area.rs rename to src/services/libs/jinux-std/src/process/process_vm/mmap_area.rs index 8d990d284..ab64fe833 100644 --- a/src/kxos-std/src/process/process_vm/mmap_area.rs +++ b/src/services/libs/jinux-std/src/process/process_vm/mmap_area.rs @@ -1,7 +1,7 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use crate::{memory::vm_page::VmPageRange, prelude::*, process::elf::init_stack::INIT_STACK_BASE}; -use kxos_frame::vm::{VmPerm, VmSpace}; +use jinux_frame::vm::{VmPerm, VmSpace}; // The definition of MMapFlags is from occlum bitflags! { diff --git a/src/kxos-std/src/process/process_vm/mod.rs b/src/services/libs/jinux-std/src/process/process_vm/mod.rs similarity index 100% rename from src/kxos-std/src/process/process_vm/mod.rs rename to src/services/libs/jinux-std/src/process/process_vm/mod.rs diff --git a/src/kxos-std/src/process/process_vm/user_heap.rs b/src/services/libs/jinux-std/src/process/process_vm/user_heap.rs similarity index 98% rename from src/kxos-std/src/process/process_vm/user_heap.rs rename to src/services/libs/jinux-std/src/process/process_vm/user_heap.rs index 82599ee09..e100de35c 100644 --- a/src/kxos-std/src/process/process_vm/user_heap.rs +++ b/src/services/libs/jinux-std/src/process/process_vm/user_heap.rs @@ -4,7 +4,7 @@ use crate::{ memory::vm_page::{VmPage, VmPageRange}, prelude::*, }; -use kxos_frame::vm::{VmPerm, VmSpace}; +use jinux_frame::vm::{VmPerm, VmSpace}; pub const USER_HEAP_BASE: Vaddr = 0x0000_0000_1000_0000; diff --git a/src/kxos-std/src/process/signal/c_types.rs b/src/services/libs/jinux-std/src/process/signal/c_types.rs similarity index 98% rename from src/kxos-std/src/process/signal/c_types.rs rename to src/services/libs/jinux-std/src/process/signal/c_types.rs index d9fc0a6cd..88fdadafe 100644 --- a/src/kxos-std/src/process/signal/c_types.rs +++ b/src/services/libs/jinux-std/src/process/signal/c_types.rs @@ -1,7 +1,7 @@ #![allow(non_camel_case_types)] use core::mem; -use kxos_frame::cpu::GpRegs; +use jinux_frame::cpu::GpRegs; use crate::prelude::*; diff --git a/src/kxos-std/src/process/signal/constants.rs b/src/services/libs/jinux-std/src/process/signal/constants.rs similarity index 100% rename from src/kxos-std/src/process/signal/constants.rs rename to src/services/libs/jinux-std/src/process/signal/constants.rs diff --git a/src/kxos-std/src/process/signal/mod.rs b/src/services/libs/jinux-std/src/process/signal/mod.rs similarity index 98% rename from src/kxos-std/src/process/signal/mod.rs rename to src/services/libs/jinux-std/src/process/signal/mod.rs index f38d70714..590419b47 100644 --- a/src/kxos-std/src/process/signal/mod.rs +++ b/src/services/libs/jinux-std/src/process/signal/mod.rs @@ -9,8 +9,8 @@ pub mod signals; use core::mem; -use kxos_frame::AlignExt; -use kxos_frame::{cpu::CpuContext, task::Task}; +use jinux_frame::AlignExt; +use jinux_frame::{cpu::CpuContext, task::Task}; use self::c_types::siginfo_t; use self::sig_mask::SigMask; diff --git a/src/kxos-std/src/process/signal/sig_action.rs b/src/services/libs/jinux-std/src/process/signal/sig_action.rs similarity index 99% rename from src/kxos-std/src/process/signal/sig_action.rs rename to src/services/libs/jinux-std/src/process/signal/sig_action.rs index 5aabca9a9..ef4d94cbc 100644 --- a/src/kxos-std/src/process/signal/sig_action.rs +++ b/src/services/libs/jinux-std/src/process/signal/sig_action.rs @@ -1,7 +1,7 @@ use super::{c_types::sigaction_t, constants::*, sig_mask::SigMask, sig_num::SigNum}; use crate::prelude::*; use bitflags::bitflags; -use kxos_frame::warn; +use jinux_frame::warn; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum SigAction { diff --git a/src/kxos-std/src/process/signal/sig_disposition.rs b/src/services/libs/jinux-std/src/process/signal/sig_disposition.rs similarity index 100% rename from src/kxos-std/src/process/signal/sig_disposition.rs rename to src/services/libs/jinux-std/src/process/signal/sig_disposition.rs diff --git a/src/kxos-std/src/process/signal/sig_mask.rs b/src/services/libs/jinux-std/src/process/signal/sig_mask.rs similarity index 100% rename from src/kxos-std/src/process/signal/sig_mask.rs rename to src/services/libs/jinux-std/src/process/signal/sig_mask.rs diff --git a/src/kxos-std/src/process/signal/sig_num.rs b/src/services/libs/jinux-std/src/process/signal/sig_num.rs similarity index 100% rename from src/kxos-std/src/process/signal/sig_num.rs rename to src/services/libs/jinux-std/src/process/signal/sig_num.rs diff --git a/src/kxos-std/src/process/signal/sig_queues.rs b/src/services/libs/jinux-std/src/process/signal/sig_queues.rs similarity index 100% rename from src/kxos-std/src/process/signal/sig_queues.rs rename to src/services/libs/jinux-std/src/process/signal/sig_queues.rs diff --git a/src/kxos-std/src/process/signal/signals/fault.rs b/src/services/libs/jinux-std/src/process/signal/signals/fault.rs similarity index 96% rename from src/kxos-std/src/process/signal/signals/fault.rs rename to src/services/libs/jinux-std/src/process/signal/signals/fault.rs index 3bc336441..d72468d8b 100644 --- a/src/kxos-std/src/process/signal/signals/fault.rs +++ b/src/services/libs/jinux-std/src/process/signal/signals/fault.rs @@ -1,5 +1,5 @@ -use kxos_frame::cpu::TrapInformation; -use kxos_frame::trap::{ +use jinux_frame::cpu::TrapInformation; +use jinux_frame::trap::{ ALIGNMENT_CHECK, BOUND_RANGE_EXCEEDED, DIVIDE_BY_ZERO, GENERAL_PROTECTION_FAULT, INVALID_OPCODE, PAGE_FAULT, SIMD_FLOATING_POINT_EXCEPTION, X87_FLOATING_POINT_EXCEPTION, }; diff --git a/src/kxos-std/src/process/signal/signals/kernel.rs b/src/services/libs/jinux-std/src/process/signal/signals/kernel.rs similarity index 100% rename from src/kxos-std/src/process/signal/signals/kernel.rs rename to src/services/libs/jinux-std/src/process/signal/signals/kernel.rs diff --git a/src/kxos-std/src/process/signal/signals/mod.rs b/src/services/libs/jinux-std/src/process/signal/signals/mod.rs similarity index 100% rename from src/kxos-std/src/process/signal/signals/mod.rs rename to src/services/libs/jinux-std/src/process/signal/signals/mod.rs diff --git a/src/kxos-std/src/process/signal/signals/user.rs b/src/services/libs/jinux-std/src/process/signal/signals/user.rs similarity index 100% rename from src/kxos-std/src/process/signal/signals/user.rs rename to src/services/libs/jinux-std/src/process/signal/signals/user.rs diff --git a/src/kxos-std/src/process/status.rs b/src/services/libs/jinux-std/src/process/status.rs similarity index 100% rename from src/kxos-std/src/process/status.rs rename to src/services/libs/jinux-std/src/process/status.rs diff --git a/src/kxos-std/src/process/table.rs b/src/services/libs/jinux-std/src/process/table.rs similarity index 100% rename from src/kxos-std/src/process/table.rs rename to src/services/libs/jinux-std/src/process/table.rs diff --git a/src/kxos-std/src/process/task.rs b/src/services/libs/jinux-std/src/process/task.rs similarity index 99% rename from src/kxos-std/src/process/task.rs rename to src/services/libs/jinux-std/src/process/task.rs index 55a6da14d..ea5ac7aec 100644 --- a/src/kxos-std/src/process/task.rs +++ b/src/services/libs/jinux-std/src/process/task.rs @@ -1,6 +1,6 @@ use core::sync::atomic::AtomicUsize; -use kxos_frame::{ +use jinux_frame::{ cpu::CpuContext, task::Task, user::{UserEvent, UserMode, UserSpace}, diff --git a/src/kxos-std/src/process/wait.rs b/src/services/libs/jinux-std/src/process/wait.rs similarity index 97% rename from src/kxos-std/src/process/wait.rs rename to src/services/libs/jinux-std/src/process/wait.rs index 309240267..d6de2e02b 100644 --- a/src/kxos-std/src/process/wait.rs +++ b/src/services/libs/jinux-std/src/process/wait.rs @@ -41,7 +41,7 @@ pub fn wait_child_exit( drop(children_lock); if unwaited_children.len() == 0 { - return Some(Err(kxos_frame::Error::NoChild)); + return Some(Err(jinux_frame::Error::NoChild)); } // return immediately if we find a zombie child diff --git a/src/kxos-std/src/rights.rs b/src/services/libs/jinux-std/src/rights.rs similarity index 53% rename from src/kxos-std/src/rights.rs rename to src/services/libs/jinux-std/src/rights.rs index ff12228bc..b7296abe1 100644 --- a/src/kxos-std/src/rights.rs +++ b/src/services/libs/jinux-std/src/rights.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use kxos_typeflags::type_flags; +use typeflags::typeflags; bitflags! { /// Value-based access rights. @@ -23,33 +23,25 @@ bitflags! { const SIGNAL = 1 << 7; } } -/// Type-based access rights. -/// -/// Similar to value-based access rights (`Rights`), but represented in -/// types. -/// -/// pub trait TRights: u32 { -/// /// Allows duplicating a capability. -/// struct Dup: u32 = Rights::DUP; -/// /// Allows reading data from a data source (files, VM objects, etc.) or -/// /// creating readable memory mappings. -/// struct Read: u32 = Rights::READ; -/// /// Allows writing data to a data sink (files, VM objects, etc.) or -/// /// creating writable memory mappings. -/// struct Write: u32 = Rights::WRITE; -/// /// Allows creating executable memory mappings. -/// struct Exec: u32 = Rights::EXEC; -/// /// Allows sending notifications or signals. -/// struct Signal: u32 = Rights::SIGNAL; -/// } -/// -type_flags! { + +typeflags! { + /// Type-based access rights. + /// + /// Similar to value-based access rights (`Rights`), but represented in + /// types. pub trait TRights: u32 { - pub struct Dup = 1 <<0; - pub struct Read = 1 <<1; - pub struct Write = 1 <<2; - pub struct Exec = 1 <<3; - pub struct Signal = 1 <<7; + /// Allows duplicating a capability. + pub struct Dup = Rights::DUP.bits; + /// Allows reading data from a data source (files, VM objects, etc.) or + /// creating readable memory mappings. + pub struct Read = Rights::READ.bits; + /// Allows writing data to a data sink (files, VM objects, etc.) or + /// creating writable memory mappings. + pub struct Write = Rights::WRITE.bits; + /// Allows creating executable memory mappings. + pub struct Exec = Rights::EXEC.bits; + /// Allows sending notifications or signals. + pub struct Signal = Rights::SIGNAL.bits; } } diff --git a/src/kxos-std/src/syscall/access.rs b/src/services/libs/jinux-std/src/syscall/access.rs similarity index 100% rename from src/kxos-std/src/syscall/access.rs rename to src/services/libs/jinux-std/src/syscall/access.rs diff --git a/src/kxos-std/src/syscall/arch_prctl.rs b/src/services/libs/jinux-std/src/syscall/arch_prctl.rs similarity index 97% rename from src/kxos-std/src/syscall/arch_prctl.rs rename to src/services/libs/jinux-std/src/syscall/arch_prctl.rs index b437d6d79..83b7cfa0b 100644 --- a/src/kxos-std/src/syscall/arch_prctl.rs +++ b/src/services/libs/jinux-std/src/syscall/arch_prctl.rs @@ -1,4 +1,4 @@ -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use crate::prelude::*; use crate::syscall::SYS_ARCH_PRCTL; diff --git a/src/kxos-std/src/syscall/brk.rs b/src/services/libs/jinux-std/src/syscall/brk.rs similarity index 100% rename from src/kxos-std/src/syscall/brk.rs rename to src/services/libs/jinux-std/src/syscall/brk.rs diff --git a/src/kxos-std/src/syscall/clone.rs b/src/services/libs/jinux-std/src/syscall/clone.rs similarity index 97% rename from src/kxos-std/src/syscall/clone.rs rename to src/services/libs/jinux-std/src/syscall/clone.rs index 1758104b0..73b592220 100644 --- a/src/kxos-std/src/syscall/clone.rs +++ b/src/services/libs/jinux-std/src/syscall/clone.rs @@ -1,4 +1,4 @@ -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use crate::process::clone::{clone_child, CloneArgs, CloneFlags}; use crate::{prelude::*, syscall::SYS_CLONE}; diff --git a/src/kxos-std/src/syscall/close.rs b/src/services/libs/jinux-std/src/syscall/close.rs similarity index 100% rename from src/kxos-std/src/syscall/close.rs rename to src/services/libs/jinux-std/src/syscall/close.rs diff --git a/src/kxos-std/src/syscall/constants.rs b/src/services/libs/jinux-std/src/syscall/constants.rs similarity index 100% rename from src/kxos-std/src/syscall/constants.rs rename to src/services/libs/jinux-std/src/syscall/constants.rs diff --git a/src/kxos-std/src/syscall/execve.rs b/src/services/libs/jinux-std/src/syscall/execve.rs similarity index 98% rename from src/kxos-std/src/syscall/execve.rs rename to src/services/libs/jinux-std/src/syscall/execve.rs index b2415734b..aeee32c31 100644 --- a/src/kxos-std/src/syscall/execve.rs +++ b/src/services/libs/jinux-std/src/syscall/execve.rs @@ -1,4 +1,4 @@ -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use super::{constants::*, SyscallReturn}; use crate::memory::{read_cstring_from_user, read_val_from_user}; diff --git a/src/kxos-std/src/syscall/exit.rs b/src/services/libs/jinux-std/src/syscall/exit.rs similarity index 100% rename from src/kxos-std/src/syscall/exit.rs rename to src/services/libs/jinux-std/src/syscall/exit.rs diff --git a/src/kxos-std/src/syscall/exit_group.rs b/src/services/libs/jinux-std/src/syscall/exit_group.rs similarity index 100% rename from src/kxos-std/src/syscall/exit_group.rs rename to src/services/libs/jinux-std/src/syscall/exit_group.rs diff --git a/src/kxos-std/src/syscall/fcntl.rs b/src/services/libs/jinux-std/src/syscall/fcntl.rs similarity index 100% rename from src/kxos-std/src/syscall/fcntl.rs rename to src/services/libs/jinux-std/src/syscall/fcntl.rs diff --git a/src/kxos-std/src/syscall/fork.rs b/src/services/libs/jinux-std/src/syscall/fork.rs similarity index 96% rename from src/kxos-std/src/syscall/fork.rs rename to src/services/libs/jinux-std/src/syscall/fork.rs index cfc0858b4..28e4756ca 100644 --- a/src/kxos-std/src/syscall/fork.rs +++ b/src/services/libs/jinux-std/src/syscall/fork.rs @@ -2,7 +2,7 @@ use crate::{ prelude::*, process::clone::{clone_child, CloneArgs}, }; -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use crate::{process::Process, syscall::SYS_FORK}; diff --git a/src/kxos-std/src/syscall/fstat.rs b/src/services/libs/jinux-std/src/syscall/fstat.rs similarity index 95% rename from src/kxos-std/src/syscall/fstat.rs rename to src/services/libs/jinux-std/src/syscall/fstat.rs index 45d88b7ec..fa2f2e551 100644 --- a/src/kxos-std/src/syscall/fstat.rs +++ b/src/services/libs/jinux-std/src/syscall/fstat.rs @@ -1,4 +1,4 @@ -use kxos_frame::vm::VmIo; +use jinux_frame::vm::VmIo; use crate::fs::stat::Stat; use crate::prelude::*; diff --git a/src/kxos-std/src/syscall/futex.rs b/src/services/libs/jinux-std/src/syscall/futex.rs similarity index 99% rename from src/kxos-std/src/syscall/futex.rs rename to src/services/libs/jinux-std/src/syscall/futex.rs index 49e79024c..5053ada9a 100644 --- a/src/kxos-std/src/syscall/futex.rs +++ b/src/services/libs/jinux-std/src/syscall/futex.rs @@ -5,7 +5,7 @@ use crate::syscall::SyscallReturn; use crate::{memory::read_val_from_user, syscall::SYS_FUTEX}; use crate::prelude::*; -use kxos_frame::cpu::num_cpus; +use jinux_frame::cpu::num_cpus; type FutexBitSet = u32; type FutexBucketRef = Arc>; diff --git a/src/kxos-std/src/syscall/getcwd.rs b/src/services/libs/jinux-std/src/syscall/getcwd.rs similarity index 100% rename from src/kxos-std/src/syscall/getcwd.rs rename to src/services/libs/jinux-std/src/syscall/getcwd.rs diff --git a/src/kxos-std/src/syscall/getegid.rs b/src/services/libs/jinux-std/src/syscall/getegid.rs similarity index 100% rename from src/kxos-std/src/syscall/getegid.rs rename to src/services/libs/jinux-std/src/syscall/getegid.rs diff --git a/src/kxos-std/src/syscall/geteuid.rs b/src/services/libs/jinux-std/src/syscall/geteuid.rs similarity index 100% rename from src/kxos-std/src/syscall/geteuid.rs rename to src/services/libs/jinux-std/src/syscall/geteuid.rs diff --git a/src/kxos-std/src/syscall/getgid.rs b/src/services/libs/jinux-std/src/syscall/getgid.rs similarity index 100% rename from src/kxos-std/src/syscall/getgid.rs rename to src/services/libs/jinux-std/src/syscall/getgid.rs diff --git a/src/kxos-std/src/syscall/getpgrp.rs b/src/services/libs/jinux-std/src/syscall/getpgrp.rs similarity index 100% rename from src/kxos-std/src/syscall/getpgrp.rs rename to src/services/libs/jinux-std/src/syscall/getpgrp.rs diff --git a/src/kxos-std/src/syscall/getpid.rs b/src/services/libs/jinux-std/src/syscall/getpid.rs similarity index 100% rename from src/kxos-std/src/syscall/getpid.rs rename to src/services/libs/jinux-std/src/syscall/getpid.rs diff --git a/src/kxos-std/src/syscall/getppid.rs b/src/services/libs/jinux-std/src/syscall/getppid.rs similarity index 100% rename from src/kxos-std/src/syscall/getppid.rs rename to src/services/libs/jinux-std/src/syscall/getppid.rs diff --git a/src/kxos-std/src/syscall/gettid.rs b/src/services/libs/jinux-std/src/syscall/gettid.rs similarity index 100% rename from src/kxos-std/src/syscall/gettid.rs rename to src/services/libs/jinux-std/src/syscall/gettid.rs diff --git a/src/kxos-std/src/syscall/getuid.rs b/src/services/libs/jinux-std/src/syscall/getuid.rs similarity index 100% rename from src/kxos-std/src/syscall/getuid.rs rename to src/services/libs/jinux-std/src/syscall/getuid.rs diff --git a/src/kxos-std/src/syscall/ioctl.rs b/src/services/libs/jinux-std/src/syscall/ioctl.rs similarity index 100% rename from src/kxos-std/src/syscall/ioctl.rs rename to src/services/libs/jinux-std/src/syscall/ioctl.rs diff --git a/src/kxos-std/src/syscall/kill.rs b/src/services/libs/jinux-std/src/syscall/kill.rs similarity index 100% rename from src/kxos-std/src/syscall/kill.rs rename to src/services/libs/jinux-std/src/syscall/kill.rs diff --git a/src/kxos-std/src/syscall/lseek.rs b/src/services/libs/jinux-std/src/syscall/lseek.rs similarity index 100% rename from src/kxos-std/src/syscall/lseek.rs rename to src/services/libs/jinux-std/src/syscall/lseek.rs diff --git a/src/kxos-std/src/syscall/lstat.rs b/src/services/libs/jinux-std/src/syscall/lstat.rs similarity index 100% rename from src/kxos-std/src/syscall/lstat.rs rename to src/services/libs/jinux-std/src/syscall/lstat.rs diff --git a/src/kxos-std/src/syscall/mmap.rs b/src/services/libs/jinux-std/src/syscall/mmap.rs similarity index 98% rename from src/kxos-std/src/syscall/mmap.rs rename to src/services/libs/jinux-std/src/syscall/mmap.rs index 141a38d85..863c680a2 100644 --- a/src/kxos-std/src/syscall/mmap.rs +++ b/src/services/libs/jinux-std/src/syscall/mmap.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use crate::process::process_vm::mmap_area::MMapFlags; -use kxos_frame::vm::VmPerm; +use jinux_frame::vm::VmPerm; use crate::syscall::SYS_MMAP; diff --git a/src/kxos-std/src/syscall/mod.rs b/src/services/libs/jinux-std/src/syscall/mod.rs similarity index 99% rename from src/kxos-std/src/syscall/mod.rs rename to src/services/libs/jinux-std/src/syscall/mod.rs index ea797868b..d3cdebcbe 100644 --- a/src/kxos-std/src/syscall/mod.rs +++ b/src/services/libs/jinux-std/src/syscall/mod.rs @@ -45,7 +45,7 @@ use crate::syscall::wait4::sys_wait4; use crate::syscall::waitid::sys_waitid; use crate::syscall::write::sys_write; use crate::syscall::writev::sys_writev; -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; mod access; mod arch_prctl; diff --git a/src/kxos-std/src/syscall/mprotect.rs b/src/services/libs/jinux-std/src/syscall/mprotect.rs similarity index 95% rename from src/kxos-std/src/syscall/mprotect.rs rename to src/services/libs/jinux-std/src/syscall/mprotect.rs index 65400cb37..d5610cc49 100644 --- a/src/kxos-std/src/syscall/mprotect.rs +++ b/src/services/libs/jinux-std/src/syscall/mprotect.rs @@ -1,4 +1,4 @@ -use kxos_frame::vm::VmPerm; +use jinux_frame::vm::VmPerm; use crate::prelude::*; diff --git a/src/kxos-std/src/syscall/munmap.rs b/src/services/libs/jinux-std/src/syscall/munmap.rs similarity index 81% rename from src/kxos-std/src/syscall/munmap.rs rename to src/services/libs/jinux-std/src/syscall/munmap.rs index 9a6e556f5..a8730e62a 100644 --- a/src/kxos-std/src/syscall/munmap.rs +++ b/src/services/libs/jinux-std/src/syscall/munmap.rs @@ -4,7 +4,7 @@ use super::SyscallReturn; use super::SYS_MUNMAP; pub fn sys_munmap(addr: Vaddr, len: usize) -> Result { - debug!("[syscall][id={}][SYS_READ]", SYS_MUNMAP); + debug!("[syscall][id={}][SYS_MUNMAP]", SYS_MUNMAP); debug!("addr = 0x{:x}, len = {}", addr, len); //TODO: do munmap Ok(SyscallReturn::Return(0)) diff --git a/src/kxos-std/src/syscall/openat.rs b/src/services/libs/jinux-std/src/syscall/openat.rs similarity index 100% rename from src/kxos-std/src/syscall/openat.rs rename to src/services/libs/jinux-std/src/syscall/openat.rs diff --git a/src/kxos-std/src/syscall/poll.rs b/src/services/libs/jinux-std/src/syscall/poll.rs similarity index 100% rename from src/kxos-std/src/syscall/poll.rs rename to src/services/libs/jinux-std/src/syscall/poll.rs diff --git a/src/kxos-std/src/syscall/prctl.rs b/src/services/libs/jinux-std/src/syscall/prctl.rs similarity index 100% rename from src/kxos-std/src/syscall/prctl.rs rename to src/services/libs/jinux-std/src/syscall/prctl.rs diff --git a/src/kxos-std/src/syscall/read.rs b/src/services/libs/jinux-std/src/syscall/read.rs similarity index 100% rename from src/kxos-std/src/syscall/read.rs rename to src/services/libs/jinux-std/src/syscall/read.rs diff --git a/src/kxos-std/src/syscall/readlink.rs b/src/services/libs/jinux-std/src/syscall/readlink.rs similarity index 100% rename from src/kxos-std/src/syscall/readlink.rs rename to src/services/libs/jinux-std/src/syscall/readlink.rs diff --git a/src/kxos-std/src/syscall/rt_sigaction.rs b/src/services/libs/jinux-std/src/syscall/rt_sigaction.rs similarity index 100% rename from src/kxos-std/src/syscall/rt_sigaction.rs rename to src/services/libs/jinux-std/src/syscall/rt_sigaction.rs diff --git a/src/kxos-std/src/syscall/rt_sigprocmask.rs b/src/services/libs/jinux-std/src/syscall/rt_sigprocmask.rs similarity index 98% rename from src/kxos-std/src/syscall/rt_sigprocmask.rs rename to src/services/libs/jinux-std/src/syscall/rt_sigprocmask.rs index 34844ef5a..f3f73eaa6 100644 --- a/src/kxos-std/src/syscall/rt_sigprocmask.rs +++ b/src/services/libs/jinux-std/src/syscall/rt_sigprocmask.rs @@ -1,4 +1,4 @@ -use kxos_frame::vm::VmIo; +use jinux_frame::vm::VmIo; use crate::{ prelude::*, diff --git a/src/kxos-std/src/syscall/rt_sigreturn.rs b/src/services/libs/jinux-std/src/syscall/rt_sigreturn.rs similarity index 95% rename from src/kxos-std/src/syscall/rt_sigreturn.rs rename to src/services/libs/jinux-std/src/syscall/rt_sigreturn.rs index 3c0b6180d..4f7d5e217 100644 --- a/src/kxos-std/src/syscall/rt_sigreturn.rs +++ b/src/services/libs/jinux-std/src/syscall/rt_sigreturn.rs @@ -1,5 +1,5 @@ use crate::{memory::read_val_from_user, prelude::*, process::signal::c_types::ucontext_t}; -use kxos_frame::cpu::CpuContext; +use jinux_frame::cpu::CpuContext; use super::{SyscallReturn, SYS_RT_SIGRETRUN}; diff --git a/src/kxos-std/src/syscall/sched_yield.rs b/src/services/libs/jinux-std/src/syscall/sched_yield.rs similarity index 100% rename from src/kxos-std/src/syscall/sched_yield.rs rename to src/services/libs/jinux-std/src/syscall/sched_yield.rs diff --git a/src/kxos-std/src/syscall/setpgid.rs b/src/services/libs/jinux-std/src/syscall/setpgid.rs similarity index 100% rename from src/kxos-std/src/syscall/setpgid.rs rename to src/services/libs/jinux-std/src/syscall/setpgid.rs diff --git a/src/kxos-std/src/syscall/tgkill.rs b/src/services/libs/jinux-std/src/syscall/tgkill.rs similarity index 92% rename from src/kxos-std/src/syscall/tgkill.rs rename to src/services/libs/jinux-std/src/syscall/tgkill.rs index feb967adb..5b6ff1831 100644 --- a/src/kxos-std/src/syscall/tgkill.rs +++ b/src/services/libs/jinux-std/src/syscall/tgkill.rs @@ -8,7 +8,7 @@ use crate::syscall::SYS_TGKILL; use super::SyscallReturn; /// tgkill send a signal to a thread with pid as its thread id, and tgid as its thread group id. -/// Since kxos only supports one-thread process now, tgkill will send signal to process with pid as its process id, +/// Since jinuxx only supports one-thread process now, tgkill will send signal to process with pid as its process id, /// and tgid as its process group id. pub fn sys_tgkill(tgid: Pgid, pid: Pid, sig_num: u8) -> Result { debug!("[syscall][id={}][SYS_TGKILL]", SYS_TGKILL); diff --git a/src/kxos-std/src/syscall/uname.rs b/src/services/libs/jinux-std/src/syscall/uname.rs similarity index 100% rename from src/kxos-std/src/syscall/uname.rs rename to src/services/libs/jinux-std/src/syscall/uname.rs diff --git a/src/kxos-std/src/syscall/wait4.rs b/src/services/libs/jinux-std/src/syscall/wait4.rs similarity index 100% rename from src/kxos-std/src/syscall/wait4.rs rename to src/services/libs/jinux-std/src/syscall/wait4.rs diff --git a/src/kxos-std/src/syscall/waitid.rs b/src/services/libs/jinux-std/src/syscall/waitid.rs similarity index 100% rename from src/kxos-std/src/syscall/waitid.rs rename to src/services/libs/jinux-std/src/syscall/waitid.rs diff --git a/src/kxos-std/src/syscall/write.rs b/src/services/libs/jinux-std/src/syscall/write.rs similarity index 100% rename from src/kxos-std/src/syscall/write.rs rename to src/services/libs/jinux-std/src/syscall/write.rs diff --git a/src/kxos-std/src/syscall/writev.rs b/src/services/libs/jinux-std/src/syscall/writev.rs similarity index 100% rename from src/kxos-std/src/syscall/writev.rs rename to src/services/libs/jinux-std/src/syscall/writev.rs diff --git a/src/kxos-std/src/tty/line_discipline.rs b/src/services/libs/jinux-std/src/tty/line_discipline.rs similarity index 100% rename from src/kxos-std/src/tty/line_discipline.rs rename to src/services/libs/jinux-std/src/tty/line_discipline.rs diff --git a/src/kxos-std/src/tty/mod.rs b/src/services/libs/jinux-std/src/tty/mod.rs similarity index 99% rename from src/kxos-std/src/tty/mod.rs rename to src/services/libs/jinux-std/src/tty/mod.rs index 8a548d4f6..d055cca99 100644 --- a/src/kxos-std/src/tty/mod.rs +++ b/src/services/libs/jinux-std/src/tty/mod.rs @@ -1,4 +1,4 @@ -use kxos_frame::receive_char; +use jinux_frame::receive_char; use self::line_discipline::LineDiscipline; use crate::fs::events::IoEvents; diff --git a/src/kxos-std/src/tty/termio.rs b/src/services/libs/jinux-std/src/tty/termio.rs similarity index 100% rename from src/kxos-std/src/tty/termio.rs rename to src/services/libs/jinux-std/src/tty/termio.rs diff --git a/src/services/libs/jinux-std/src/user_apps.rs b/src/services/libs/jinux-std/src/user_apps.rs new file mode 100644 index 000000000..5f0ac1bcb --- /dev/null +++ b/src/services/libs/jinux-std/src/user_apps.rs @@ -0,0 +1,121 @@ +use crate::prelude::*; + +pub struct UserApp { + pub app_name: CString, + pub app_content: &'static [u8], + pub argv: Vec, + pub envp: Vec, +} + +impl UserApp { + pub fn new(app_name: &str, app_content: &'static [u8]) -> Self { + let app_name = CString::new(app_name).unwrap(); + UserApp { + app_name, + app_content, + argv: Vec::new(), + envp: Vec::new(), + } + } + + pub fn set_argv(&mut self, argv: Vec) { + self.argv = argv; + } + + pub fn set_envp(&mut self, envp: Vec) { + self.envp = envp; + } +} + +pub fn get_all_apps() -> Vec { + let mut res = Vec::with_capacity(16); + + // Most simple hello world, written in assembly + let asm_hello_world = UserApp::new("hello_world", read_hello_world_content()); + res.push(asm_hello_world); + + // Hello world, written in C language. + // Since glibc requires the app name starts with "/", and we don't have filesystem now. + // So we manually add a leading "/" for app written in C language. + let hello_c = UserApp::new("/hello_c", read_hello_c_content()); + res.push(hello_c); + + // Fork process, written in assembly + let asm_fork = UserApp::new("fork", read_fork_content()); + res.push(asm_fork); + + // Execve, written in C language. + let execve_c = UserApp::new("/execve", read_execve_content()); + res.push(execve_c); + + // Fork new process, written in C language. (Fork in glibc uses syscall clone actually) + let fork_c = UserApp::new("/fork", read_fork_c_content()); + res.push(fork_c); + + // signal test + let signal_test = UserApp::new("/signal_test", read_signal_test_content()); + res.push(signal_test); + + // busybox + let mut busybox = UserApp::new("/busybox", read_busybox_content()); + // -l option means the busybox is running as logging shell + let argv = ["/busybox", "sh", "-l"]; + let envp = [ + "SHELL=/bin/sh", + "PWD=/", + "LOGNAME=root", + "HOME=/", + "USER=root", + "PATH=", + "OLDPWD=/", + ]; + + let argv = to_vec_cstring(&argv).unwrap(); + let envp = to_vec_cstring(&envp).unwrap(); + busybox.set_argv(argv); + busybox.set_envp(envp); + res.push(busybox); + + res +} + +fn read_hello_world_content() -> &'static [u8] { + include_bytes!("../../../../apps/hello_world/hello_world") +} + +fn read_hello_c_content() -> &'static [u8] { + include_bytes!("../../../../apps/hello_c/hello") +} + +fn read_fork_content() -> &'static [u8] { + include_bytes!("../../../../apps/fork/fork") +} + +fn read_execve_content() -> &'static [u8] { + include_bytes!("../../../../apps/execve/execve") +} + +pub fn read_execve_hello_content() -> &'static [u8] { + include_bytes!("../../../../apps/execve/hello") +} + +fn read_fork_c_content() -> &'static [u8] { + include_bytes!("../../../../apps/fork_c/fork") +} + +fn read_signal_test_content() -> &'static [u8] { + include_bytes!("../../../../apps/signal_c/signal_test") +} + +fn read_busybox_content() -> &'static [u8] { + include_bytes!("../../../../apps/busybox/busybox") +} + +fn to_vec_cstring(raw_strs: &[&str]) -> Result> { + let mut res = Vec::new(); + for raw_str in raw_strs { + let cstring = CString::new(*raw_str)?; + res.push(cstring); + } + Ok(res) +} diff --git a/src/kxos-std/src/util/mod.rs b/src/services/libs/jinux-std/src/util/mod.rs similarity index 100% rename from src/kxos-std/src/util/mod.rs rename to src/services/libs/jinux-std/src/util/mod.rs diff --git a/src/kxos-std/src/vm/mod.rs b/src/services/libs/jinux-std/src/vm/mod.rs similarity index 81% rename from src/kxos-std/src/vm/mod.rs rename to src/services/libs/jinux-std/src/vm/mod.rs index 440c45bc5..caecd5528 100644 --- a/src/kxos-std/src/vm/mod.rs +++ b/src/services/libs/jinux-std/src/vm/mod.rs @@ -10,8 +10,8 @@ //! [Zircon](https://fuchsia.dev/fuchsia-src/reference/kernel_objects/vm_object). //! As capabilities, the two abstractions are aligned with our goal //! of everything-is-a-capability, although their specifications and -//! implementations in C/C++ cannot apply directly to KxOS. -//! In KxOS, VMARs and VMOs, as well as other capabilities, are implemented +//! implementations in C/C++ cannot apply directly to Jinux. +//! In Jinux, VMARs and VMOs, as well as other capabilities, are implemented //! as zero-cost capabilities. mod vmar; diff --git a/src/kxos-std/src/vm/vmar/dyn_cap.rs b/src/services/libs/jinux-std/src/vm/vmar/dyn_cap.rs similarity index 96% rename from src/kxos-std/src/vm/vmar/dyn_cap.rs rename to src/services/libs/jinux-std/src/vm/vmar/dyn_cap.rs index 7d295a27a..a68fc58a8 100644 --- a/src/kxos-std/src/vm/vmar/dyn_cap.rs +++ b/src/services/libs/jinux-std/src/vm/vmar/dyn_cap.rs @@ -1,8 +1,8 @@ use core::ops::Range; use alloc::sync::Arc; -use kxos_frame::prelude::Result; -use kxos_frame::{vm::VmIo, Error}; +use jinux_frame::prelude::Result; +use jinux_frame::{vm::VmIo, Error}; use crate::{rights::Rights, vm::vmo::Vmo}; @@ -25,8 +25,8 @@ impl Vmar { /// # Example /// /// ``` - /// use kxos_std::prelude::*; - /// use kxos_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; + /// use jinux_std::prelude::*; + /// use jinux_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; /// /// let vmar = Vmar::new().unwrap(); /// let vmo = VmoOptions::new(PAGE_SIZE).alloc().unwrap(); diff --git a/src/kxos-std/src/vm/vmar/mod.rs b/src/services/libs/jinux-std/src/vm/vmar/mod.rs similarity index 94% rename from src/kxos-std/src/vm/vmar/mod.rs rename to src/services/libs/jinux-std/src/vm/vmar/mod.rs index 5a4be03ae..3bb65cb8e 100644 --- a/src/kxos-std/src/vm/vmar/mod.rs +++ b/src/services/libs/jinux-std/src/vm/vmar/mod.rs @@ -8,10 +8,10 @@ use crate::rights::Rights; use alloc::sync::Arc; use bitflags::bitflags; use core::ops::Range; -use kxos_frame::prelude::Result; -use kxos_frame::vm::Vaddr; -use kxos_frame::vm::VmSpace; -use kxos_frame::Error; +use jinux_frame::prelude::Result; +use jinux_frame::vm::Vaddr; +use jinux_frame::vm::VmSpace; +use jinux_frame::Error; use spin::Mutex; /// Virtual Memory Address Regions (VMARs) are a type of capability that manages @@ -36,7 +36,7 @@ use spin::Mutex; /// # Implementation /// /// `Vmar` provides high-level APIs for address space management by wrapping -/// around its low-level counterpart `kx_frame::vm::VmFrames`. +/// around its low-level counterpart `_frame::vm::VmFrames`. /// Compared with `VmFrames`, /// `Vmar` is easier to use (by offering more powerful APIs) and /// harder to misuse (thanks to its nature of being capability). diff --git a/src/kxos-std/src/vm/vmar/options.rs b/src/services/libs/jinux-std/src/vm/vmar/options.rs similarity index 96% rename from src/kxos-std/src/vm/vmar/options.rs rename to src/services/libs/jinux-std/src/vm/vmar/options.rs index 20a83b33c..d6dbd0038 100644 --- a/src/kxos-std/src/vm/vmar/options.rs +++ b/src/services/libs/jinux-std/src/vm/vmar/options.rs @@ -1,7 +1,7 @@ //! Options for allocating child VMARs and creating mappings. -use kxos_frame::prelude::Result; -use kxos_frame::{config::PAGE_SIZE, vm::Vaddr}; +use jinux_frame::prelude::Result; +use jinux_frame::{config::PAGE_SIZE, vm::Vaddr}; use crate::vm::vmo::Vmo; @@ -15,7 +15,7 @@ use super::{VmPerms, Vmar}; /// A child VMAR created from a parent VMAR of _dynamic_ capability is also a /// _dynamic_ capability. /// ``` -/// use kxo_std::vm::{PAGE_SIZE, Vmar}; +/// use jinux_std::vm::{PAGE_SIZE, Vmar}; /// /// let parent_vmar = Vmar::new(); /// let child_size = 10 * PAGE_SIZE; @@ -30,8 +30,8 @@ use super::{VmPerms, Vmar}; /// A child VMO created from a parent VMO of _static_ capability is also a /// _static_ capability. /// ``` -/// use kxos_std::prelude::*; -/// use kxos_std::vm::{PAGE_SIZE, Vmar}; +/// use jinux_std::prelude::*; +/// use jinux_std::vm::{PAGE_SIZE, Vmar}; /// /// let parent_vmar: Vmar = Vmar::new(); /// let child_size = 10 * PAGE_SIZE; diff --git a/src/kxos-std/src/vm/vmar/static_cap.rs b/src/services/libs/jinux-std/src/vm/vmar/static_cap.rs similarity index 96% rename from src/kxos-std/src/vm/vmar/static_cap.rs rename to src/services/libs/jinux-std/src/vm/vmar/static_cap.rs index 9c3adfdd3..6a9a93914 100644 --- a/src/kxos-std/src/vm/vmar/static_cap.rs +++ b/src/services/libs/jinux-std/src/vm/vmar/static_cap.rs @@ -1,9 +1,9 @@ use core::ops::Range; use alloc::sync::Arc; -use kxos_frame::prelude::Result; -use kxos_frame::{vm::VmIo, Error}; -use kxos_rights_proc::require; +use jinux_frame::prelude::Result; +use jinux_frame::{vm::VmIo, Error}; +use jinux_rights_proc::require; use crate::{ rights::{Dup, Read, Rights, TRights}, @@ -33,8 +33,8 @@ impl Vmar { /// # Example /// /// ``` - /// use kxos_std::prelude::*; - /// use kxos_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; + /// use jinux_std::prelude::*; + /// use jinux_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; /// /// let vmar = Vmar::::new().unwrap(); /// let vmo = VmoOptions::new(PAGE_SIZE).alloc().unwrap(); diff --git a/src/kxos-std/src/vm/vmo/dyn_cap.rs b/src/services/libs/jinux-std/src/vm/vmo/dyn_cap.rs similarity index 98% rename from src/kxos-std/src/vm/vmo/dyn_cap.rs rename to src/services/libs/jinux-std/src/vm/vmo/dyn_cap.rs index af46ca900..a94758dca 100644 --- a/src/kxos-std/src/vm/vmo/dyn_cap.rs +++ b/src/services/libs/jinux-std/src/vm/vmo/dyn_cap.rs @@ -1,7 +1,7 @@ use core::ops::Range; -use kxos_frame::prelude::Result; -use kxos_frame::{vm::VmIo, Error}; +use jinux_frame::prelude::Result; +use jinux_frame::{vm::VmIo, Error}; use crate::rights::{Rights, TRights}; diff --git a/src/kxos-std/src/vm/vmo/mod.rs b/src/services/libs/jinux-std/src/vm/vmo/mod.rs similarity index 97% rename from src/kxos-std/src/vm/vmo/mod.rs rename to src/services/libs/jinux-std/src/vm/vmo/mod.rs index 328bcb872..6d1045542 100644 --- a/src/kxos-std/src/vm/vmo/mod.rs +++ b/src/services/libs/jinux-std/src/vm/vmo/mod.rs @@ -5,7 +5,7 @@ use core::ops::Range; use crate::rights::Rights; use alloc::sync::Arc; use bitflags::bitflags; -use kxos_frame::{prelude::Result, vm::Paddr, Error}; +use jinux_frame::{prelude::Result, vm::Paddr, Error}; mod dyn_cap; mod options; @@ -66,7 +66,7 @@ use spin::Mutex; /// # Implementation /// /// `Vmo` provides high-level APIs for address space management by wrapping -/// around its low-level counterpart `kx_frame::vm::VmFrames`. +/// around its low-level counterpart `jinux_frame::vm::VmFrames`. /// Compared with `VmFrames`, /// `Vmo` is easier to use (by offering more powerful APIs) and /// harder to misuse (thanks to its nature of being capability). diff --git a/src/kxos-std/src/vm/vmo/options.rs b/src/services/libs/jinux-std/src/vm/vmo/options.rs similarity index 96% rename from src/kxos-std/src/vm/vmo/options.rs rename to src/services/libs/jinux-std/src/vm/vmo/options.rs index cad075aba..2a2b567f3 100644 --- a/src/kxos-std/src/vm/vmo/options.rs +++ b/src/services/libs/jinux-std/src/vm/vmo/options.rs @@ -4,9 +4,9 @@ use core::marker::PhantomData; use core::ops::Range; use alloc::sync::Arc; -use kxos_frame::prelude::Result; -use kxos_frame::vm::Paddr; -use kxos_rights_proc::require; +use jinux_frame::prelude::Result; +use jinux_frame::vm::Paddr; +use jinux_rights_proc::require; use crate::rights::{Dup, Rights, TRights}; @@ -27,7 +27,7 @@ use super::{Pager, Vmo, VmoFlags}; /// /// Creating a VMO as a _static_ capability with all access rights: /// ``` -/// use kxos_std::prelude::*; +/// use jinux_std::prelude::*; /// use kxo_std::vm::{PAGE_SIZE, VmoOptions}; /// /// let vmo = VmoOptions::::new(PAGE_SIZE) @@ -39,7 +39,7 @@ use super::{Pager, Vmo, VmoFlags}; /// physically contiguous: /// /// ``` -/// use kxos_std::vm::{PAGE_SIZE, VmoOptions, VmoFlags}; +/// use jinux_std::vm::{PAGE_SIZE, VmoOptions, VmoFlags}; /// /// let vmo = VmoOptions::new(10 * PAGE_SIZE) /// .flags(VmoFlags::RESIZABLE) @@ -132,8 +132,8 @@ impl VmoOptions { /// A child VMO created from a parent VMO of _static_ capability is also a /// _static_ capability. /// ``` -/// use kxos_std::prelude::*; -/// use kxos_std::vm::{PAGE_SIZE, VmoOptions, VmoChildOptions}; +/// use jinux_std::prelude::*; +/// use jinux_std::vm::{PAGE_SIZE, VmoOptions, VmoChildOptions}; /// /// let parent_vmo: Vmo = VmoOptions::new(PAGE_SIZE) /// .alloc() @@ -165,7 +165,7 @@ impl VmoOptions { /// The above rule for COW VMO children also applies to static capabilities. /// /// ``` -/// use kxos_std::vm::{PAGE_SIZE, VmoOptions, VmoChildOptions}; +/// use jinux_std::vm::{PAGE_SIZE, VmoOptions, VmoChildOptions}; /// /// let parent_vmo = VmoOptions::::new(PAGE_SIZE) /// .alloc() diff --git a/src/kxos-std/src/vm/vmo/pager.rs b/src/services/libs/jinux-std/src/vm/vmo/pager.rs similarity index 97% rename from src/kxos-std/src/vm/vmo/pager.rs rename to src/services/libs/jinux-std/src/vm/vmo/pager.rs index 805aa72ae..7b37372fa 100644 --- a/src/kxos-std/src/vm/vmo/pager.rs +++ b/src/services/libs/jinux-std/src/vm/vmo/pager.rs @@ -1,5 +1,5 @@ -use kxos_frame::prelude::Result; -use kxos_frame::vm::VmFrame; +use jinux_frame::prelude::Result; +use jinux_frame::vm::VmFrame; /// Pagers provide frame to a VMO. /// diff --git a/src/kxos-std/src/vm/vmo/static_cap.rs b/src/services/libs/jinux-std/src/vm/vmo/static_cap.rs similarity index 97% rename from src/kxos-std/src/vm/vmo/static_cap.rs rename to src/services/libs/jinux-std/src/vm/vmo/static_cap.rs index 9dfa407dd..4d12cca46 100644 --- a/src/kxos-std/src/vm/vmo/static_cap.rs +++ b/src/services/libs/jinux-std/src/vm/vmo/static_cap.rs @@ -1,8 +1,8 @@ use core::ops::Range; -use kxos_frame::prelude::Result; -use kxos_frame::{vm::VmIo, Error}; -use kxos_rights_proc::require; +use jinux_frame::prelude::Result; +use jinux_frame::{vm::VmIo, Error}; +use jinux_rights_proc::require; use crate::rights::*; diff --git a/src/services/libs/jinux-util/Cargo.toml b/src/services/libs/jinux-util/Cargo.toml new file mode 100644 index 000000000..5d2db4296 --- /dev/null +++ b/src/services/libs/jinux-util/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "jinux-util" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +jinux-frame = {path = "../../../framework/jinux-frame"} +pod-derive = {path = "../../../framework/pod-derive"} +pod = {path = "../../../framework/pod"} + +[features] + diff --git a/src/kxos-util/src/frame_ptr.rs b/src/services/libs/jinux-util/src/frame_ptr.rs similarity index 93% rename from src/kxos-util/src/frame_ptr.rs rename to src/services/libs/jinux-util/src/frame_ptr.rs index 956c98095..1b25d2c72 100644 --- a/src/kxos-util/src/frame_ptr.rs +++ b/src/services/libs/jinux-util/src/frame_ptr.rs @@ -1,10 +1,11 @@ use core::marker::PhantomData; -use kxos_frame::{ +use jinux_frame::{ config::PAGE_SIZE, - vm::{Paddr, Pod, VmAllocOptions, VmFrame, VmFrameVec, VmIo}, + vm::{Paddr, VmAllocOptions, VmFrame, VmFrameVec, VmIo}, Result, }; +use pod::Pod; /// An in-frame pointer to a POD value, enabling safe access /// to a POD value given its physical memory address. diff --git a/src/kxos-util/src/lib.rs b/src/services/libs/jinux-util/src/lib.rs similarity index 71% rename from src/kxos-util/src/lib.rs rename to src/services/libs/jinux-util/src/lib.rs index c97eb8e05..ccbcb5541 100644 --- a/src/kxos-util/src/lib.rs +++ b/src/services/libs/jinux-util/src/lib.rs @@ -1,4 +1,4 @@ -//! The util of kxos +//! The util of jinux #![no_std] #![forbid(unsafe_code)] diff --git a/src/kxos-util/Cargo.toml b/src/services/libs/typeflags-util/Cargo.toml similarity index 69% rename from src/kxos-util/Cargo.toml rename to src/services/libs/typeflags-util/Cargo.toml index 9a8a511e4..7c1cec8a4 100644 --- a/src/kxos-util/Cargo.toml +++ b/src/services/libs/typeflags-util/Cargo.toml @@ -1,12 +1,8 @@ [package] -name = "kxos-util" +name = "typeflags-util" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -kxos-frame = {path = "../kxos-frame"} - -[features] - diff --git a/src/kxos-typeflags-util/src/assert.rs b/src/services/libs/typeflags-util/src/assert.rs similarity index 100% rename from src/kxos-typeflags-util/src/assert.rs rename to src/services/libs/typeflags-util/src/assert.rs diff --git a/src/kxos-typeflags-util/src/bool.rs b/src/services/libs/typeflags-util/src/bool.rs similarity index 100% rename from src/kxos-typeflags-util/src/bool.rs rename to src/services/libs/typeflags-util/src/bool.rs diff --git a/src/kxos-typeflags-util/src/if_.rs b/src/services/libs/typeflags-util/src/if_.rs similarity index 100% rename from src/kxos-typeflags-util/src/if_.rs rename to src/services/libs/typeflags-util/src/if_.rs diff --git a/src/kxos-typeflags-util/src/lib.rs b/src/services/libs/typeflags-util/src/lib.rs similarity index 85% rename from src/kxos-typeflags-util/src/lib.rs rename to src/services/libs/typeflags-util/src/lib.rs index 8df373555..22a823757 100644 --- a/src/kxos-typeflags-util/src/lib.rs +++ b/src/services/libs/typeflags-util/src/lib.rs @@ -1,7 +1,7 @@ //! The content of this crate is from another project CapComp. //! This crate defines common type level operations, like SameAsOp, and Bool type operations. //! Besides, this crate defines operations to deal with type sets, like SetContain and SetInclude. -//! When use kxos-typeflags or kxos-rights-poc, this crate should also be added as a dependency. +//! When use jinux-typeflags or jinux-rights-poc, this crate should also be added as a dependency. #![no_std] pub mod assert; pub mod bool; diff --git a/src/kxos-typeflags-util/src/same.rs b/src/services/libs/typeflags-util/src/same.rs similarity index 100% rename from src/kxos-typeflags-util/src/same.rs rename to src/services/libs/typeflags-util/src/same.rs diff --git a/src/kxos-typeflags-util/src/set.rs b/src/services/libs/typeflags-util/src/set.rs similarity index 100% rename from src/kxos-typeflags-util/src/set.rs rename to src/services/libs/typeflags-util/src/set.rs diff --git a/src/kxos-typeflags/Cargo.toml b/src/services/libs/typeflags/Cargo.toml similarity index 91% rename from src/kxos-typeflags/Cargo.toml rename to src/services/libs/typeflags/Cargo.toml index 03d2c3013..df3f5875d 100644 --- a/src/kxos-typeflags/Cargo.toml +++ b/src/services/libs/typeflags/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "kxos-typeflags" +name = "typeflags" version = "0.1.0" edition = "2021" diff --git a/src/kxos-typeflags/src/flag_set.rs b/src/services/libs/typeflags/src/flag_set.rs similarity index 92% rename from src/kxos-typeflags/src/flag_set.rs rename to src/services/libs/typeflags/src/flag_set.rs index 3a7c181d8..05708eeea 100644 --- a/src/kxos-typeflags/src/flag_set.rs +++ b/src/services/libs/typeflags/src/flag_set.rs @@ -5,8 +5,8 @@ use syn::Expr; use crate::type_flag::TypeFlagDef; -const EMPTY_SET_NAME: &'static str = "::kxos_typeflags_util::Nil"; -const SET_NAME: &'static str = "::kxos_typeflags_util::Cons"; +const EMPTY_SET_NAME: &'static str = "::typeflags_util::Nil"; +const SET_NAME: &'static str = "::typeflags_util::Cons"; /// A flagSet represent the combination of differnt flag item. /// e.g. [Read, Write], [Read], [] are all flag sets. @@ -48,14 +48,14 @@ impl FlagSet { /// the tokens represents the flag set type name pub fn type_name_tokens(&self) -> TokenStream { - let mut res = quote!(::kxos_typeflags_util::Nil); + let mut res = quote!(::typeflags_util::Nil); for item in self.items.iter() { let ident = item.ident.clone(); // insert new item as head let new_res = quote! { - ::kxos_typeflags_util::Cons<#ident, #res> + ::typeflags_util::Cons<#ident, #res> }; res = new_res; } @@ -91,7 +91,7 @@ impl FlagSet { { const BITS: #ty = 0 ; fn new() -> Self { - ::kxos_typeflags_util::Nil + ::typeflags_util::Nil } } ) @@ -100,7 +100,7 @@ impl FlagSet { { const BITS: #ty = #(#item_vals)|* ; fn new() -> Self { - ::kxos_typeflags_util::Cons::new() + ::typeflags_util::Cons::new() } } ) diff --git a/src/kxos-typeflags/src/lib.rs b/src/services/libs/typeflags/src/lib.rs similarity index 81% rename from src/kxos-typeflags/src/lib.rs rename to src/services/libs/typeflags/src/lib.rs index 9484ec9ec..1bf64b3e2 100644 --- a/src/kxos-typeflags/src/lib.rs +++ b/src/services/libs/typeflags/src/lib.rs @@ -1,12 +1,12 @@ -//!This crate defines the procedural macro typeflags to implement capability for kxos. -//! When using this crate, kxos-typeflags-util should also be added as dependency. -//! This is due to kxos-typeflgas is a proc-macro crate, which is only allowed to export proc-macro interfaces. -//! So we leave the common type-level operations and structures defined in kxos-typeflags-util. +//!This crate defines the procedural macro typeflags to implement capability for jinux. +//! When using this crate, typeflags-util should also be added as dependency. +//! This is due to typeflgas is a proc-macro crate, which is only allowed to export proc-macro interfaces. +//! So we leave the common type-level operations and structures defined in typeflags-util. //! -//! type_flag is used to define another declarive macro to define type set. +//! typeflags is used to define another declarive macro to define type set. //! It can be used as the following example. //! ```rust -//! type_flags! { +//! typeflags! { //! pub trait RightSet: u32 { //! struct Read = 1 << 1; //! struct Write = 1 << 2; @@ -25,7 +25,7 @@ //! //! Test Example //! ```rust -//! use kxos_typeflags_util::*; +//! use typeflags_util::*; //! assert_eq!(O::BITS, 0); //! assert_eq!(R::BITS, 2); //! assert_eq!(W::BITS, 4); @@ -57,7 +57,7 @@ mod type_flag; mod util; #[proc_macro] -pub fn type_flags(input: proc_macro::TokenStream) -> proc_macro::TokenStream { +pub fn typeflags(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let type_flags_def = parse_macro_input!(input as TypeFlagDef); expand_type_flag(&type_flags_def).into() } diff --git a/src/kxos-typeflags/src/type_flag.rs b/src/services/libs/typeflags/src/type_flag.rs similarity index 86% rename from src/kxos-typeflags/src/type_flag.rs rename to src/services/libs/typeflags/src/type_flag.rs index 6516c5035..d7c54d357 100644 --- a/src/kxos-typeflags/src/type_flag.rs +++ b/src/services/libs/typeflags/src/type_flag.rs @@ -4,11 +4,12 @@ use syn::{ braced, parse::{Parse, ParseStream}, punctuated::Punctuated, - Expr, Ident, Token, Type, Visibility, + Attribute, Expr, Ident, Token, Type, Visibility, }; /// The content inside typeflag macro pub struct TypeFlagDef { + attributes: Vec, ident: Ident, vis: Visibility, type_: Type, @@ -18,6 +19,7 @@ pub struct TypeFlagDef { /// struct item inside typeflag macro #[derive(Clone)] pub struct TypeFlagItem { + attributes: Vec, vis: Visibility, ident: Ident, value: Expr, @@ -25,6 +27,7 @@ pub struct TypeFlagItem { impl Parse for TypeFlagDef { fn parse(input: syn::parse::ParseStream) -> syn::Result { + let attributes = Attribute::parse_outer(input)?; let vis: Visibility = input.parse()?; let _: Token![trait] = input.parse()?; let ident: Ident = input.parse()?; @@ -36,6 +39,7 @@ impl Parse for TypeFlagDef { let items = content.parse_terminated(TypeFlagItem::parse)?; let res = TypeFlagDef { + attributes, ident, vis, type_, @@ -48,12 +52,18 @@ impl Parse for TypeFlagDef { impl Parse for TypeFlagItem { fn parse(input: ParseStream) -> syn::Result { + let attributes = Attribute::parse_outer(input)?; let vis: Visibility = input.parse()?; let _: Token![struct] = input.parse()?; let ident: Ident = input.parse()?; let _: Token![=] = input.parse()?; let value: Expr = input.parse()?; - let res = TypeFlagItem { vis, ident, value }; + let res = TypeFlagItem { + attributes, + vis, + ident, + value, + }; Ok(res) } } @@ -61,10 +71,12 @@ impl Parse for TypeFlagItem { impl TypeFlagDef { /// tokens to define the trait pub fn trait_def_tokens(&self) -> TokenStream { + let attributes = self.attributes.clone(); let vis = self.vis.clone(); let ident = self.ident.clone(); let type_ = self.type_.clone(); quote!( + #(#attributes)* #vis trait #ident : Sync + Send{ const BITS: #type_; @@ -111,9 +123,11 @@ impl TypeFlagDef { impl TypeFlagItem { /// the token stream to define such item fn item_def_tokens(&self) -> TokenStream { + let attributes = self.attributes.clone(); let vis = self.vis.clone(); let ident = self.ident.clone(); quote!( + #(#attributes)* #vis struct #ident {} ) } diff --git a/src/kxos-typeflags/src/util.rs b/src/services/libs/typeflags/src/util.rs similarity index 92% rename from src/kxos-typeflags/src/util.rs rename to src/services/libs/typeflags/src/util.rs index bea77b2ae..b1d1c7d0f 100644 --- a/src/kxos-typeflags/src/util.rs +++ b/src/services/libs/typeflags/src/util.rs @@ -29,11 +29,11 @@ pub fn expand_type_flag(type_flags_def: &TypeFlagDef) -> TokenStream { all_tokens } -/// import crate kxos_typeflags_util +/// import crate typeflags_util pub fn import_util() -> TokenStream { quote!( #[macro_use] - use ::kxos_typeflags_util::*; + use ::typeflags_util::*; ) } @@ -63,8 +63,8 @@ pub fn impl_same_as(type_flags_def: &TypeFlagDef) -> TokenStream { let ident1 = item1.ident(); let ident2 = item2.ident(); let tokens = quote!( - impl ::kxos_typeflags_util::SameAs<#ident1> for #ident2 { - type Output = ::kxos_typeflags_util::False; + impl ::typeflags_util::SameAs<#ident1> for #ident2 { + type Output = ::typeflags_util::False; } ); all_tokens.append_all(tokens); diff --git a/src/src/main.rs b/src/src/main.rs index 4c4cfc9dc..a3a68486e 100644 --- a/src/src/main.rs +++ b/src/src/main.rs @@ -2,24 +2,24 @@ #![no_main] #![feature(custom_test_frameworks)] #![forbid(unsafe_code)] -#![test_runner(kxos_frame::test_runner)] +#![test_runner(jinux_frame::test_runner)] #![reexport_test_harness_main = "test_main"] -extern crate kxos_frame; +extern crate jinux_frame; use bootloader::{entry_point, BootInfo}; use core::panic::PanicInfo; -use kxos_frame::println; +use jinux_frame::println; entry_point!(kernel_main); fn kernel_main(boot_info: &'static mut BootInfo) -> ! { #[cfg(test)] test_main(); - kxos_frame::init(boot_info); - println!("[kernel] finish init kxos_frame"); + jinux_frame::init(boot_info); + println!("[kernel] finish init jinux_frame"); - kxos_std::init(); - kxos_std::run_first_process(); + jinux_std::init(); + jinux_std::run_first_process(); } #[cfg(not(test))] #[panic_handler] @@ -31,7 +31,7 @@ fn panic(info: &PanicInfo) -> ! { #[cfg(test)] #[panic_handler] fn panic(info: &PanicInfo) -> ! { - kxos_frame::test_panic_handler(info); + jinux_frame::test_panic_handler(info); } #[test_case] diff --git a/src/tests/test_example.rs b/src/tests/test_example.rs index bfde06d49..ec75ca4ce 100644 --- a/src/tests/test_example.rs +++ b/src/tests/test_example.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] #![feature(custom_test_frameworks)] -#![test_runner(kxos_frame::test_runner)] +#![test_runner(jinux_frame::test_runner)] #![reexport_test_harness_main = "test_main"] use bootloader::{entry_point, BootInfo}; use core::panic::PanicInfo; @@ -9,17 +9,17 @@ use core::panic::PanicInfo; entry_point!(kernel_test_main); fn kernel_test_main(boot_info: &'static mut BootInfo) -> ! { - kxos_frame::init(boot_info); + jinux_frame::init(boot_info); test_main(); loop {} } #[panic_handler] fn panic(info: &PanicInfo) -> ! { - kxos_frame::test_panic_handler(info) + jinux_frame::test_panic_handler(info) } #[test_case] fn test_println() { - kxos_frame::println!("test_println output"); + jinux_frame::println!("test_println output"); } diff --git a/src/tests/timer_test.rs b/src/tests/timer_test.rs index e0e3bc771..4eb58f709 100644 --- a/src/tests/timer_test.rs +++ b/src/tests/timer_test.rs @@ -1,35 +1,35 @@ #![no_std] #![no_main] #![feature(custom_test_frameworks)] -#![test_runner(kxos_frame::test_runner)] +#![test_runner(jinux_frame::test_runner)] #![reexport_test_harness_main = "test_main"] use bootloader::{entry_point, BootInfo}; -use kxos_frame::timer::Timer; +use jinux_frame::timer::Timer; extern crate alloc; use alloc::sync::Arc; use core::panic::PanicInfo; use core::time::Duration; -use kxos_frame::println; +use jinux_frame::println; static mut TICK: usize = 0; entry_point!(kernel_test_main); fn kernel_test_main(boot_info: &'static mut BootInfo) -> ! { - kxos_frame::init(boot_info); + jinux_frame::init(boot_info); test_main(); loop {} } #[panic_handler] fn panic(info: &PanicInfo) -> ! { - kxos_frame::test_panic_handler(info) + jinux_frame::test_panic_handler(info) } #[test_case] fn test_timer() { println!( - "If you want to pass this test, you may need to enable the interrupt in kxos_frame/lib.rs" + "If you want to pass this test, you may need to enable the interrupt in jinux_frame/lib.rs" ); println!("make sure the Timer irq number 32 handler won't panic"); unsafe { diff --git a/src/x86_64-custom.json b/src/x86_64-custom.json index 0c734cc6c..759749973 100644 --- a/src/x86_64-custom.json +++ b/src/x86_64-custom.json @@ -11,7 +11,7 @@ "linker": "rust-lld", "pre-link-args": { "ld.lld": [ - "-Tkxos-frame/src/linker.ld" + "-Tframework/jinux-frame/src/linker.ld" ] }, "panic-strategy": "abort",