2756 Commits

Author SHA1 Message Date
vasilito a240e73e44 0.3.0: refresh Cargo.lock for latest compatible dependencies 2026-07-06 20:41:35 +03:00
vasilito ec8e88c364 0.3.0: kernel build fixes - syscall aliases and FADT length type cast
- Add SYS_OPENAT/SYS_DUP aliases in local syscall fork for upstream 0.9.0 renamed constants.

- Cast FADT_MIN_SIZE_ACPI_2_0 to u32 to match sdt.length() return type.

- Keep Cargo.lock based on upstream master with only redox_syscall sourced from local fork.
2026-07-06 18:57:41 +03:00
vasilito ca67b1da37 0.3.0: converge kernel onto upstream master
- Rebase all Red Bear kernel changes onto upstream master (4d5d36d4).
- Update version to 0.5.12+rb0.3.0 and add Red Bear author attribution.
- Switch redox_syscall direct dependency to local fork path (../syscall).
- Bump rust-toolchain.toml to nightly-2026-05-24.
- Regenerate Cargo.lock for +rb0.3.0 suffixes and path deps.
2026-07-06 18:43:52 +03:00
R Aadarsh 4d5d36d44e Extract code that is common to both x86 and ARM to srat::init 2026-07-05 20:16:00 +05:30
R Aadarsh 35340a80c4 * Add ACPI-NUMA parsing code for ARM
* Fix bug in the x86 code that caused incorrect cpu-node mapping

* Remove the usage of page mappers. Instead use the already existing
  linear mapping
2026-07-05 15:01:48 +05:30
R Aadarsh cb88ed59a2 Parse ACPI tables for NUMA information without allocating from the heap 2026-07-03 20:19:46 +05:30
Wildan M 372cd19b6f Remove irq from handles on close 2026-07-02 08:41:11 +07:00
R Aadarsh aa7e7d2f44 Fix the bug in RxsdtIter that caused u32 pointers to be used regardless of ACPI table kind 2026-07-01 10:36:07 -06:00
R Aadarsh a03c545f3c Fix build failure for ARM 2026-07-01 10:36:07 -06:00
R Aadarsh a2a3df33c6 Split acpi::init to perform two stage initialisation 2026-07-01 10:36:07 -06:00
Ibuki Omatsu 6c3d5d28c6 refactor: Move fd allocation logic into userspace 2026-07-01 08:02:47 -06:00
R Aadarsh 8171dc616b Fix panic due to using uninitialised NUMA_NODES 2026-06-21 14:30:07 +05:30
R Aadarsh 2ad76496c4 * Store addresses as pointers
* Remove lots of unsafe code by initialising in the closure passed to
  `call_once`

* Remove `NUMBER_OF_DOMAINS` as size can always be inferred from the
  hashmap's len
2026-06-21 14:03:49 +05:30
R Aadarsh 4106dcbbfa Gate behind a feature flag 2026-06-21 14:03:49 +05:30
R Aadarsh 969c905d8e Account for the case when distance information is not available 2026-06-21 14:03:49 +05:30
R Aadarsh 9ecc75029c * Correctly put cpus and memories for adoption
* Test on x86_64 (works)
2026-06-21 14:03:49 +05:30
R Aadarsh 16c59588b0 * Fix endianness
* Remove ITS affinity and numa
2026-06-21 14:03:49 +05:30
R Aadarsh ee2a61088e * Parse SLIT for distance information
* Order by distance, reorganise domains into nodes
2026-06-21 14:03:49 +05:30
R Aadarsh 63d1171ffb Initial commit 2026-06-21 14:03:49 +05:30
Wildan M 002fff546d Clear cloexec flag on Dup2 2026-06-20 06:35:01 +07:00
Wildan M ed31b800c4 Revert "Use weak context for Proc" 2026-06-19 17:36:41 +07:00
Wildan M 622a4fb3cd Solve context leak when switching 2026-06-19 17:33:46 +07:00
Wildan M 101f090ef9 Fmt 2026-06-19 16:50:14 +07:00
Akshit Gaur b93260ed2d Migrating run_queue to BTreeMap 2026-06-18 10:39:33 +05:30
4lDO2 56947e1a0f Revert drop of kstack in exit_this_context. 2026-06-04 13:37:57 +02:00
4lDO2 bd6d9acd3c Compile on other arches. 2026-06-03 19:06:12 +02:00
4lDO2 c27568e1fe profiling: allow walking across syscall boundaries 2026-06-03 19:01:35 +02:00
4lDO2 42613ddc06 WIP: simultaneous NMI-based user+kernel profiling. 2026-06-03 19:01:35 +02:00
R Aadarsh f8bc19747a Make necessary changes to the kernel in order for relibc to support posix_spawn and posix_spawnp
* `syscall::sendfd`, now, when called with a `ContextHandle::FileTable` adds the fd to the filetable removing it from the calling process's filetable

* Files can now be added to, removed from another process, and can be duplicated using `ProcScheme::kcall`

* Files of another process with the flag O_CLOEXEC can now be closed by using `kcall`
2026-06-03 15:29:02 +05:30
4lDO2 8011f3f648 Simplify acpi scheme. 2026-06-02 16:23:08 +02:00
4lDO2 6fc2d32497 Remove redundant methods from KernelScheme. 2026-06-02 11:24:37 +02:00
4lDO2 da3d235af5 remove syscall debug for removed syscalls 2026-06-02 11:24:37 +02:00
4lDO2 3e210ff169 Remove 5 obsolete syscalls. 2026-06-02 11:24:37 +02:00
Wildan M 8701e8165b Fix compilation for aarch64 after rust update 2026-05-31 06:55:02 +07:00
4lDO2 cee451af38 Use ArrayVec for kcall fd nums, 8% better perf! 2026-05-31 20:24:57 +02:00
Wildan M 973ac667e3 Use syscall time helper functions 2026-05-30 12:29:38 +07:00
Wildan M a47b3a8d57 Add timeout for events 2026-05-30 13:44:31 -06:00
Wildan M ec1395b554 Wrap unmap loop with handle_notify_files 2026-05-30 08:40:49 -06:00
Akshit Gaur 58283f63fe EEVDF 2026-05-30 08:39:48 -06:00
Ibuki Omatsu e847768f2b feat: Implement multiple fds variant for call and std_fs_call 2026-05-29 13:07:36 +02:00
bjorn3 91ab8301f2 Fix warnings after updating rustc
Couple of features got stabilized, cpuid was made safe and there is a
new lint for function item to integer casts.
2026-05-27 20:53:10 +02:00
Jeremy Soller d254309fdb Support nightly 2026-05-24 2026-05-25 17:41:48 -06:00
Wildan M f70905d439 Resolve warnings 2026-05-23 00:04:34 +07:00
Wildan M 40e76875d7 Prevent kstack from leaking 2026-05-20 13:35:47 +07:00
Wildan M 805f921e10 Use weak context for Proc and Futex 2026-05-20 12:57:37 +07:00
Wildan M 7c653c5182 Possible fix to race condition to EBADF 2026-05-15 22:46:03 +07:00
Wildan M 8c9def2d73 Lazily clean up futex 2026-05-13 20:49:02 +07:00
Wildan M ff11f47404 Add futex, pipe, timeout subscribers 2026-05-13 10:46:38 +07:00
Wildan M bd44956e96 Capture event stat, change stat source for contexts 2026-05-12 12:24:49 +07:00
Wildan M 97bd0fb4a6 Don't compare QueueKey data to fix epoll ctl del 2026-05-10 17:33:04 +07:00
bjorn3 3dab161d30 Copy the flags set from physmap MemoryType over on scheme mmap
Propagating flags like uncachable or writecombining is necessary both
for correctness and for performance.
2026-05-06 21:05:16 +02:00
Speedy_Lex 678a8c5631 Fail softly on bad RSDP 2026-05-05 19:35:33 +02:00
Speedy_Lex 6b55ffea38 Make rsdp pointer NonNull 2026-05-05 19:35:33 +02:00
Speedy_Lex 6af9afb75d Fix check
Co-Author: 4lDO2
2026-05-05 19:35:33 +02:00
Speedy_Lex 6e539f9cd9 Fix bit check in src/profiling.rs 2026-05-05 19:35:33 +02:00
Speedy_Lex f49c7d991a RSDP validation and fixing a few clippy lints 2026-05-05 19:35:31 +02:00
Wildan M 51f32e9edb Allow cd to sys scheme 2026-05-02 18:25:44 +07:00
Wildan M 85c98314a9 Unwrap select_next_context result 2026-05-02 06:23:13 -06:00
Wildan M abb429d0c5 Revert "Split wait queue mutex" 2026-05-02 05:55:27 +07:00
Wildan M a297bfcc82 Use smallvec for memory and notify_files 2026-04-30 22:00:35 +07:00
Wildan M 1070efaec8 Solve some lock ordering 2026-04-30 21:59:19 +07:00
Wildan M 3914801f1e Speed up vector removal 2026-04-30 21:59:19 +07:00
Wildan M 00232b456c Optimize new mmap grant 2026-04-30 11:12:01 -06:00
Wildan M fb137f8001 Avoid reaccessing AddrSpace when switching 2026-04-30 11:09:59 -06:00
Wildan M 844f393ae8 Downgrade context sigcontrol to read 2026-04-29 21:48:31 +07:00
Wildan M ba28216ae8 Downgrade locks to read 2026-04-29 21:26:44 +07:00
Wildan M ab08d47aa8 Add commented out switch debug print 2026-04-29 11:21:20 +07:00
Wildan M e7ac009f31 Fix deadlock on contended switch 2026-04-29 11:21:02 +07:00
Wildan M fd5a04a121 Use status helpers 2026-04-29 11:20:43 +07:00
Wildan M baf329c120 Fix dead contexts clobber idle pools 2026-04-29 11:20:21 +07:00
Wildan M 866dfad0af Lower WaitQueue incoming lock level 2026-04-27 06:51:45 -06:00
Wildan M b8615790ea Lock wait queue together when receive_into_user 2026-04-27 06:51:45 -06:00
Wildan M 746c158465 Split wait queue mutex 2026-04-27 06:51:45 -06:00
Wildan M b3a6154445 Move dst_space_lock lower to Solve AddrSpaceWrapper lock 2026-04-27 06:50:20 -06:00
Wildan M 8dcb508413 Make AddrSpaceWrapper lock lower without solving borrow checker 2026-04-27 06:50:20 -06:00
Wildan M 2bca47923c Avoid reaccessing AddrSpace when switching 2026-04-27 02:18:42 +07:00
Wildan M c2b20abc03 Avoid locking current context on capture_inner 2026-04-27 01:54:43 +07:00
Wildan M e9f50698dd Remove ContextRef upgrade 2026-04-26 15:37:40 +07:00
Wildan M 2df7467d13 Use weak ContextRef for run contexts 2026-04-26 12:08:24 +07:00
Wildan M ea1d915bbc Make wake up optional 2026-04-26 07:15:10 +07:00
Wildan M 643726852b Reduce deadlock cap 2026-04-26 06:49:55 +07:00
Wildan M 0534ab6377 Replace enqueue with dedicated idle contexts 2026-04-26 06:49:55 +07:00
Wildan M de7926e05e Do not push idle context to queue 2026-04-26 06:49:54 +07:00
Wildan M 7adceb6e80 Add idle context 2026-04-26 06:49:54 +07:00
bjorn3 7827cb6c78 Unify context list again now that we have a run queue
This simplifies code and ensures that exiting a context will properly
remove it from the list of contexts.
2026-04-26 06:49:54 +07:00
Wildan M af1bc5d5e2 Fix relibc CI 2026-04-25 09:48:34 -06:00
Wildan M 58660a9170 Handle AddrSpace munmap 2026-04-24 17:52:05 +07:00
Wildan M f773d3e50d don't loop from idle to kernel context 2026-04-23 16:40:12 +07:00
Wildan M 8262fa7da9 Don't account idle time 2026-04-23 16:33:15 +07:00
Wildan M 2ca610193b Add kernel version to relibc CI test 2026-04-20 10:50:42 +07:00
Wildan Mubarok df07d65c05 Apply 1 suggestion(s) to 1 file(s)
Co-authored-by: bjorn3 <4397-bjorn3@users.noreply.gitlab.redox-os.org>
2026-04-19 08:46:05 -06:00
Wildan M bbfbe30445 Exclude PhysBorrowed from counting shared memory 2026-04-19 08:46:05 -06:00
Wildan M aee49d747a Update relibc test in CI 2026-04-19 16:52:29 +07:00
aarch e80379e6c6 Actually switch to Sv39 2026-04-18 18:49:21 +02:00
aarch f7c48049f5 RISCV64: Change VA scheme to Sv39 for real hardware support + Sv57 definitions 2026-04-18 09:46:34 -06:00
bjorn3 30b967022f Fix a couple of warnings 2026-04-17 20:20:16 +02:00
Akshit Gaur 976756991a Deficit Weighted Round Robin Scheduler 2026-04-17 06:52:03 -06:00
Wildan M 4531e15ba1 Add shared memory stats to contexts 2026-04-16 09:53:30 +07:00
bjorn3 219d707362 Introduce HandleMap helper type 2026-04-13 20:51:24 +02:00
bjorn3 f673afa839 Fix a duplicate log
This got moved into allocate, but forgot to save the change.
2026-04-13 20:22:18 +02:00
bjorn3 2174f86543 Fix debugger 2026-04-13 19:43:44 +02:00
bjorn3 4929783030 Improve fdstat 2026-04-13 19:43:44 +02:00
bjorn3 3a2200198a Always compile the code of sys_fdstat 2026-04-13 19:43:44 +02:00
bjorn3 3ff7872cd6 Fix warnings for sys_fdstat 2026-04-13 19:43:44 +02:00
bjorn3 38f36d406b Use cfg!() instead of #[cfg] for most profiling code
This makes it less likely that it breaks again in the future as most
code gets checked by the compiler even when profiling support is not
enabled.
2026-04-13 19:43:43 +02:00
Jacob Lorentzon 142871660e profiling: infer number of CPUs dynamically 2026-04-13 06:44:27 -06:00
bjorn3 2405a7ebb3 Move kmain and kmain_ap to startup/mod.rs 2026-04-12 18:41:00 +02:00
bjorn3 572bb4ce1f Avoid re-exporting arch specific modules in the crate root 2026-04-12 18:25:52 +02:00
Jacob Lorentzon 141c87650f Fix profiling and add check to CI 2026-04-12 06:51:26 -06:00
bjorn3 2f39aade30 Use mmap_anywhere in a couple of places 2026-04-10 20:23:01 +02:00
bjorn3 f792faf571 Avoid a Once for event::REGISTRY 2026-04-10 20:22:58 +02:00
bjorn3 a46f37976b Use div_ceil in LogicalCpuSet Display impl 2026-04-10 20:22:58 +02:00
bjorn3 aab33e46c3 Fix a couple of warnings 2026-04-10 20:22:26 +02:00
Wildan M 8f54fd8cb2 Fix displaying affinity in sys/context 2026-04-09 15:24:36 -06:00
bjorn3 654ee6ca3e size_of and align_of are part of the prelude nowadays 2026-04-09 15:23:34 -06:00
bjorn3 2e784dfe46 Remove unused feature gate 2026-04-09 15:23:34 -06:00
bjorn3 89a29f4e56 Reduce usage of wildcard imports 2026-04-09 15:23:34 -06:00
bjorn3 b0b0ec2d71 Deduplicate definition of FLAG_SINGLESTEP between x86 and x86_64 2026-04-09 15:23:34 -06:00
bjorn3 e98e12780e Inline BorrowedHtBuf::tail 2026-04-09 15:23:34 -06:00
bjorn3 bdf82a958a Use call instead of call_inner for fmap_inner 2026-04-09 15:23:34 -06:00
Wildan M cd3b18068f Improve mem precision in sys/context 2026-04-09 15:22:38 -06:00
Wildan M ce08b60502 Solve lock token and contexts for fdstat and debugger 2026-04-09 15:22:38 -06:00
Wildan M 0ad905f26e Fix sys stats to reveal contexts in all CPU 2026-04-09 15:22:38 -06:00
Speedy_Lex ee1260363c Fix many clippy lints 2026-04-08 19:40:41 +01:00
bjorn3 b7456d5bcc Avoid PHYS_OFFSET in dtb/serial.rs 2026-04-04 21:53:34 +02:00
bjorn3 d029ccfe20 Deduplicate a bunch of serial port initialization between arm64 and riscv 2026-04-04 16:36:30 +02:00
bjorn3 bbb9d98570 Unconditionally compile part of the DTB code 2026-04-04 14:01:19 +02:00
bjorn3 8eefc8a6a6 Remove unused dependency 2026-04-04 13:52:26 +02:00
bjorn3 f339467372 Remove dead_code lint allow for ACPI 2026-04-04 13:50:48 +02:00
bjorn3 62f220b1b9 Use cfg! rather than #[cfg] for ACPI enabling 2026-04-04 13:49:07 +02:00
bjorn3 49d005b450 Use RmmA::phys_to_virt instead of PHYS_OFFSET in the acpi code 2026-04-04 13:33:26 +02:00
bjorn3 2fba663274 Fix expect message 2026-04-04 13:14:14 +02:00
bjorn3 7aa7aa463f Use map_device_memory where possible 2026-04-04 13:10:05 +02:00
bjorn3 dee230ffca Use map_linearly in many places 2026-04-04 13:10:04 +02:00
bjorn3 a1b6bd965e Fix rmm example 2026-04-04 12:02:07 +02:00
bjorn3 50c68cd746 Remove ACPI search from the kernel
The bootloader provides the RSDP address to the kernel. If the
bootloader can't find it, there is no RSDP.
2026-04-04 11:50:24 +02:00
bjorn3 1352fafd00 Remove unused InactiveFlusher 2026-04-03 22:15:00 +02:00
bjorn3 ab4abf63c9 Deduplicate Page and other paging related things between architectures 2026-04-03 22:15:00 +02:00
bjorn3 b805336cfc Fix a bunch of warnings 2026-04-03 22:15:00 +02:00
bjorn3 3cbce1b9ac Move BSP_READY and AP_READY to platform-independent code 2026-04-02 20:29:36 +02:00
bjorn3 0f540e6f15 Don't physmap the kernel itself
We don't actually need to and this is a bit safer against memory corruption.
2026-04-02 20:29:36 +02:00
bjorn3 49eb21ce0e Use KERNEL_OFFSET from linker script 2026-04-02 20:29:36 +02:00
bjorn3 dc7e823f70 Deduplicate kernel page flags 2026-04-02 20:29:36 +02:00
bjorn3 980f1c6af8 Remove unused and deduplicate identical arch specific consts 2026-04-02 20:29:36 +02:00
bjorn3 10b1ae2ecc Remove unused arch consts 2026-04-02 20:29:36 +02:00
bjorn3 2ce7621a80 Fix a bunch of warnings masked by #[allow(unused)] 2026-04-02 20:29:36 +02:00
Wildan M d835a3d8f0 Solve all borrow checker leaving some violation 2026-04-01 08:42:18 -06:00
Wildan M a42ec44dbf Partially solve borrow rules 2026-04-01 08:42:18 -06:00
Wildan M 3161a44c25 Solve borrow rules for memory.rs 2026-04-01 08:42:18 -06:00
Wildan M 55e6fe9add Remove remnants of AddrSpace::used_by 2026-04-01 08:42:18 -06:00
Wildan M ca2a7048d0 Move spin loop hint to crate lock 2026-04-01 08:42:18 -06:00
Wildan M 3b5a0e4c60 Apply ordered lock to AddrSpaceWrapper without solving borrow checker 2026-04-01 08:42:18 -06:00
Wildan M 2989b5375f Add deadlock debug to AddrSpaceWrapper 2026-04-01 08:42:18 -06:00
Akshit Gaur 004509587d Fix ForceKill 2026-04-01 13:58:27 +05:30
Wildan M 6e0143cf0d Store context to per cpu 2026-03-31 15:29:47 +07:00
bjorn3 efa6b00189 rmm: Remove magic constants for x86 PAT indices 2026-03-30 22:18:10 +02:00
bjorn3 c8879531ae rmm: Add device_memory and uncachable flags to PageFlags 2026-03-30 20:34:45 +02:00
bjorn3 e311b41821 rmm: Make it a bit easier to change the MAIR_EL1 config on arm64 2026-03-30 20:34:45 +02:00
bjorn3 a5fd001dcb Use PageFlags::write_combining instead of custom flag 2026-03-30 20:34:45 +02:00
bjorn3 c0065bc893 rmm: Add some comments to init_pat 2026-03-30 20:34:44 +02:00
bjorn3 6b00f4ca25 Move MAIR_EL1 initialization to rmm
Rmm needs to know the exact MAIR_EL1 configuration to produce the
correct bits in the page table.
2026-03-30 19:26:41 +02:00
bjorn3 6e5c25b7a0 Move PAT initialization to rmm
Rmm needs to know the exact PAT configuration to produce the correct
bits in the page table.
2026-03-30 18:59:42 +02:00
bjorn3 c4b064ea44 Move arch specific EntryFlags into rmm 2026-03-30 18:49:15 +02:00
bjorn3 04645353f2 rmm: Fix EmulateArch compilation 2026-03-30 18:46:53 +02:00
bjorn3 8b217edac0 Fix two unsafe block related warnings 2026-03-30 18:42:38 +02:00
bjorn3 2fc2d5897a Fix a couple of unused import warnings 2026-03-30 18:38:25 +02:00
bjorn3 675ba2ea51 rmm: Make a couple more methods safe 2026-03-29 17:00:36 +02:00
bjorn3 c51aa1ef86 rmm: Make a couple of methods safe 2026-03-29 14:16:53 +02:00
bjorn3 a5aeea9cfc rmm: Remove PageMapper::{map,unmap}
There is already (un)map_phys.
2026-03-29 14:16:53 +02:00
bjorn3 a876d66648 rmm: Reduce visibility of PageTable methods
This disallows direct manipulation of the page tables. Only manipulation
through PageMapper is allowed.
2026-03-29 14:16:53 +02:00
bjorn3 abf710b4a2 Move handling of kernel page table entry copying to RMM
This way it can ensure those page table entries never get unmapped,
ensuring they are kept in sync between all processes.
2026-03-29 14:16:53 +02:00
bjorn3 604e1729cb Rustfmt 2026-03-29 14:16:53 +02:00
bjorn3 882007f827 Remove unused UserSlice::read_u64
This fixes a warning. It can always be re-introduced if we ever need it.
2026-03-29 14:16:36 +02:00
bjorn3 f5aff74fc9 Explicitly ignore field of PageQueueEntry::Other
This fixes a warning
2026-03-29 14:16:35 +02:00
bjorn3 b5603422be Check at compile time that KernelMapper is writable if necessary 2026-03-28 23:22:19 +01:00
bjorn3 0d578775f9 rmm: Indicate which PageMapper methods can allocate 2026-03-28 22:51:32 +01:00
bjorn3 d02312055e rmm: Couple of minor cleanups 2026-03-28 22:35:26 +01:00
bjorn3 3593c53146 rmm: Remove Arch::init
No architectures implement it.
2026-03-28 22:07:48 +01:00
bjorn3 db85237114 rmm: Partially hard code main.rs to EmulateArch 2026-03-28 22:06:24 +01:00
bjorn3 d06ade297d rmm: Remove fallback impl of invalidate_all
It doesn't work on all non-x86 architectures.
2026-03-28 22:02:34 +01:00
bjorn3 a913414c7f rmm: Nicer formatting of unsafe blocks 2026-03-28 22:00:43 +01:00
bjorn3 cc20bcd405 rmm: Fix warnings on x86 2026-03-28 21:57:51 +01:00
bjorn3 a3843f8fb5 rmm: Assert constants at compile time 2026-03-28 21:57:41 +01:00
bjorn3 5c480806be Add rmm to the workspace 2026-03-28 21:39:34 +01:00
bjorn3 ef508cc0ba Add 'rmm/' from commit 'e543cbe621b21875549c9d12a73810633f3d0c63'
git-subtree-dir: rmm
git-subtree-mainline: 76b0691e14
git-subtree-split: e543cbe621
2026-03-28 20:44:33 +01:00
bjorn3 76b0691e14 Remove rmm submodule 2026-03-28 20:43:48 +01:00
bjorn3 f8d93023dd Fix a couple of warnings 2026-03-28 17:07:33 +01:00
Philipp Bartsch 5865ec0790 /scheme/sys/cpu: Add aarch64 feature detection
This only lists features from ID_AA64ISAR0_EL1 and ID_AA64ISAR1_EL1.
For other features one would have to evaluate more registers.
2026-03-26 22:15:03 +01:00
Philipp Bartsch 2d5e2b39f5 Drop extra debug print 2026-03-26 00:49:33 +01:00
Philipp Bartsch a60cc25015 Update aarch64 implementers list
Two vendors were missing compared to ARM's official list.

https://developer.arm.com/documentation/ddi0601/2025-12/AArch64-Registers/MIDR-EL1--Main-ID-Register
2026-03-26 00:49:11 +01:00
Ron Williams fde164b2a0 Revert "Deficit based Weighted Round Robin Scheduler"
This reverts commit b7dabfc3c2.
2026-03-22 18:44:41 +00:00
Akshit Gaur b7dabfc3c2 Deficit based Weighted Round Robin Scheduler 2026-03-22 07:00:31 -06:00
Wildan M 74895c4f0f Fix ecpect file 2026-03-17 19:30:17 +07:00
Wildan M c70035865e Fix expect files 2026-03-17 19:24:10 +07:00
Wildan M 727f9658ed Fix CI sysroot 2026-03-17 18:57:21 +07:00
Wildan M bbcb3d19be Try using uname, fix relibc 2026-03-17 18:44:28 +07:00
Wildan M 65bd8e3264 Add boot check to CI 2026-03-17 18:32:51 +07:00
Wildan M 52d9fcc962 Try use relibc tests 2026-03-17 18:20:47 +07:00
Wildan M d317f84cd4 Change uname to kernel commit, Fix CI build 2026-03-17 17:51:29 +07:00
Connor-GH d81ba0645b /scheme/sys/uname: use commit hash instead of time for reproducibility 2026-03-15 17:21:46 -05:00
Connor-GH ea47151757 /scheme/sys/uname: include the "version" info
With this change, we use the recently-added `COOKBOOK_TIME_IDENT`
environment variable at compile time to get the "version" info for the
uname scheme. This field is unspecified by POSIX what it should have,
but most kernels (including Linux, XNU, NetBSD, etc.) put the build
time here.
2026-03-15 15:53:02 -05:00
Wildan M 44b6a58032 Add more context to deadlock debug messages 2026-03-14 08:49:40 -06:00
Ibuki.O 3934ea454d feat: Implement translation of std_fs_call to each function 2026-03-14 11:37:07 +09:00
Connor-GH 8f468ec106 syscall: remove comment about test vs bt x86 instructions
According to Agner Fog's documentation
(https://agner.org/optimize/instruction_tables.pdf), the following information
is true:

These instructions have identical latency and throughput, except for Zen
5, which lists `test` as having reciprocal throughput of 0.25 cycles,
and `bt` having reciprocal throughput of 0.33 cycles. This rules out the
`bt` instruction for being the ideal instruction.

The other `test` instructions were removed as candidates because,
regardless of the size of the memory fetched at the address, at least 64
bytes will need to be fetched because it will be stored in the cache
line. The WORD and DWORD cases can be ruled out because we cannot assume
that `rsp + 16` or `rsp + 17` will not be on a 64-byte alignment
boundary, which would cause two cachelines to be essentially filled with
garbage we don't care about. The best case scenario is that we only need
to fill one cache line with garbage, which is what the BYTE version does
every time.
2026-03-12 09:41:29 -05:00
Wildan M 84754dfc5d Solve borrow checking by downgrading waitqueue lock 2026-03-11 09:42:06 +07:00
Wildan M f07725682f Add ordered lock for WaitQueue mutex without solving borrow check 2026-03-11 09:24:45 +07:00
Wildan M 60573e24f3 Solve borrow checking by downgrading condition.wait lock 2026-03-11 09:07:52 +07:00
Wildan M 046c8ced0d Add lock token to pipe queue without solving borrow checker 2026-03-11 08:12:07 +07:00
Wildan M 7ebb5f2a3d Solve borrow checking by downgrading locks 2026-03-11 08:00:48 +07:00
Wildan M 44f2214971 Partially solve borrow checking with WaitQueue 2026-03-11 07:27:21 +07:00
Wildan M 771ebdb39f Partially solve borrow checking with PreemptGuard L1 2026-03-11 06:34:37 +07:00
Wildan M 73c2df9e33 Add lock token to user states, without solving borrow check 2026-03-10 23:56:15 +07:00
Wildan M eeb03bdcb1 Revert "Add ordered lock for WaitQueue mutex"
This reverts commit 735c68ec30.
2026-03-10 12:11:09 +07:00
Wildan M d5ed9d8007 Optimize context spawn and init 2026-03-10 05:59:35 +07:00
Wildan M c4e86bfffd Change time offset to RwLock 2026-03-10 05:58:26 +07:00
Wildan M 7fa253cf6a Add deadlock detection 2026-03-09 16:32:11 +07:00
Wildan M 6307446ede Solve borrow rules to LockedFdTbl 2026-03-09 15:57:38 +07:00
Wildan M 8412321568 Add lock token to FdTbl without borrow check 2026-03-09 13:12:19 +07:00
Wildan M 206f82709a Demote LockedFileDescription to solve borrow rules 2026-03-09 12:29:24 +07:00
Wildan M 8f270795da Partialy solve borrow checking 2026-03-09 11:47:07 +07:00
Wildan M f40b84a5cc Add lock token to FileDescription, without borrow check 2026-03-09 11:23:51 +07:00
bjorn3 6085c8935c Remove unused WaitQueue::receive method 2026-03-07 21:44:29 +01:00
bjorn3 6a10af6f77 Fully remove the broken support for unmounting schemes
It has been broken since we moved namespaces into userspace. Fixing it
can be done entirely inside userspace. Either by introducing a SYS_CALL
for the root capability or by treating closing the last fd as unmount.
2026-03-07 21:42:46 +01:00
Wildan M fd9c651410 Do not allocate on unneeded Vec 2026-03-07 09:15:20 -07:00
Wildan M 547722767a Optimize sys/stat a bit 2026-03-07 20:42:25 +07:00
Wildan M a5adc0cc69 Avoid heap allocation on event 2026-03-07 06:33:52 -07:00
bjorn3 4ccc521156 Show grant flags in the debugger 2026-03-07 12:19:40 +01:00
bjorn3 ea847f428f Fix compilation with the debugger feature enabled 2026-03-07 12:19:24 +01:00
auronandace 4c734e461a prefer saturating methods over direct arithetic 2026-03-05 10:58:45 +00:00
auronandace fc6ffd59ff avoid direct indexing in MemoryMap register function 2026-03-03 17:22:44 +00:00
auronandace 14b8c2b0c1 enforce two lints and collapse some ifs 2026-03-03 14:51:32 +00:00
auronandace f0f158e5d6 eliminate 2 unwraps in syscall fs 2026-03-02 17:11:51 -07:00
auronandace f7b0f5ec37 eliminate an unwrap in gdt for x86_shared 2026-03-02 10:56:28 +00:00
Ibuki Omatsu 4faa1bad45 feat: Implment std_fs_call kfstatvfs handling to memory scheme 2026-02-28 08:06:47 -07:00
Marsman 507d899587 fix: validate timespec in nanosleep 2026-02-28 07:02:30 +00:00
Wildan M fbe129918c Handle address release on flink 2026-02-27 15:43:19 +07:00
Wildan M 1b74bea620 EventQueue may dropped at trigger_inner 2026-02-27 15:29:58 +07:00
Wildan M 2e759a9cc5 Prevent drop on BorrowedHtBuf 2026-02-27 13:54:05 +07:00
Wildan M 437f762339 Prevent drop on WaitCondition 2026-02-27 12:34:13 +07:00
Wildan M 159e67f26d Add lock token for global REGISTRY 2026-02-27 11:16:57 +07:00
Wildan M c72e0a67f9 Prevent drop on AddrSpace 2026-02-27 10:47:45 +07:00
Jeremy Soller d34090f352 Accurately strip ANSI escape sequences in graphical debug display 2026-02-26 10:33:46 -07:00
Wildan M ac0bd2af74 Fix compilation 2026-02-26 04:33:10 +07:00
Anhad Singh ba94676fe4 chore: update redox_syscall
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-25 08:21:36 -07:00
Anhad Singh 8eb6d22ab4 misc(scheme/user): remove some debug logs
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-25 08:21:36 -07:00
Anhad Singh 955b4b2a1c feat(stdfscall): flocking
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-25 08:21:36 -07:00
Wildan M 14349d1649 Propagate ordered lock of event trigger 2026-02-25 11:42:31 +07:00
Wildan M 3c2b1a11c5 Add ordered lock for time offset mutex 2026-02-25 11:42:17 +07:00
Wildan M 735c68ec30 Add ordered lock for WaitQueue mutex 2026-02-25 09:48:13 +07:00
auronandace bf396c7f61 replace manual stripping 2026-02-23 15:49:32 +00:00
auronandace 8138826200 avoid direct indexing in wait_condition 2026-02-23 06:34:20 -07:00
auronandace 7770a9452c avoid direct indexing futexes 2026-02-23 11:57:28 +00:00
auronandace a19be5da11 avoid direct indexing in AlignedBox 2026-02-22 13:43:37 +00:00
auronandace aeb75d577f add assert to ensure both arrays are equal length 2026-02-21 20:37:08 +00:00
auronandace 8689e31674 remove an instance of direct indexing 2026-02-21 15:28:55 +00:00
auronandace df469ddcb3 apply is_multiple_of lint 2026-02-21 08:39:26 +00:00
auronandace 02a68d3c87 change static_mut_refs back to warn 2026-02-20 16:06:16 +00:00
auronandace 28ba26cc2b move lints to Cargo.toml file 2026-02-20 15:59:27 +00:00
Anhad Singh fc60dcced0 misc(main): add feature btree_cursors
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-21 00:59:24 +11:00
Anhad Singh a8699a7e72 feat(memory): handle grant merges when mutating
This commit fixes the following panic when running nodejs:
```
KERNEL PANIC: panicked at src/context/memory.rs:267:18:
grant cannot magically disappear while we hold the lock!
  FP ffff80002021f650: PC ffffffff8005e45b
    FFFFFFFF8005E2E0+017B
    kernel::panic::panic_handler_inner
  FP ffff80002021f730: PC ffffffff80057559
  FP ffff80002021f740: PC ffffffff8009a0ff
  FP ffff80002021f770: PC ffffffff8009c214
  FP ffff80002021f7d0: PC ffffffff80010997
    FFFFFFFF8000FDD0+0BC7
    kernel::context::memory::AddrSpaceWrapper::mprotect
  FP ffff80002021fd40: PC ffffffff8008cb0b
    FFFFFFFF8008CA40+00CB
    kernel::syscall::process::mprotect
  FP ffff80002021fd70: PC ffffffff8006ce6c
    FFFFFFFF8006CBE0+028C
    kernel::syscall::syscall
  FP ffff80002021fe90: PC ffffffff8008d3cf
    FFFFFFFF8008D320+00AF
    __inner_syscall_instruction
  FP ffff80002021ff50: PC ffffffff800830c3
    FFFFFFFF80083080+0043
    kernel::arch::x86_64::interrupt::syscall::syscall_instruction
  00007ffffffffaf0: GUARD PAGE
CPU #1, CID 0xffffff7f8015b910
NAME: /usr/bin/node, DEBUG ID: 74
SYSCALL: mprotect(0x203C0000, 262144, Some(MapFlags(0x0)))
HALT
```

The grant did not magically disappear. When going through the
`grant_span_res` regions, the function adds (and removes) grants to the
`self.grants` tree. The insertion and deletion functions also merge
adjacent grants together when possible. This is an issue since we can no
longer use the keys we established before we started iterating. This
commit modifies the places where `remove` is used in this fashion to use
`remove_containing` instead. The `remove_containing` function will
remove the grant that *contains* the page.

Should it be done this way (requires unstable feature `btree_cursors`)?

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-21 00:59:24 +11:00
auronandace 6853592ce4 add precedence clippy lint 2026-02-20 13:15:32 +00:00
Anhad Singh b85c2d7889 misc(rmm): update submodule
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-20 00:26:47 +11:00
Jeremy Soller e543cbe621 Merge branch 'master' into 'master'
feat(mapper/remap_with_full): conditional remap

See merge request redox-os/rmm!20
2026-02-19 06:23:39 -07:00
Anhad Singh 124b74e816 fix(context/memory): Grant::remap delegate write
`Grant::remap` should not directly mark entries as writeable because the
entry could be private and requires Copy-On-Write (COW) handling. This
bug fixes the random panics that occur when running programs that
incorrectly mark private memory regions as writeable. This also
inadvertently caused other systems to crash. This is because The Zeroed
Frame is mapped instead of allocating a new zeroed memory region every
time. Only after the first write is the frame actually allocated. This
means that with this bug one could remap a freshly mmap'ed ANONYMOUS
region with the write flag and rewrite the contents of The Zeroed Frame,
which is a big problem. This means that any program that allocated
memory with the ANONYMOUS flag after this would not receive zeroed
memory.

Example of `make` hitting this bug when the shared `ld.so` patches are
applied:
```
....
[page at 0x48bd000] is mapped to the zeroed frame with PageFlags { present: true, write: false, executable: false, user: true, bits: 0x8000000000000005 }
[page at 0x49b1000] is mapped to the zeroed frame with PageFlags { present: true, write: true, executable: false, user: true, bits: 0x8000000000000007 }
[page at 0x49b2000] is mapped to the zeroed frame with PageFlags { present: true, write: true, executable: false, user: true, bits: 0x8000000000000007 }
[page at 0x49b3000] is mapped to the zeroed frame with PageFlags { present: true, write: true, executable: false, user: true, bits: 0x8000000000000007 }
[page at 0x49b4000] is mapped to the zeroed frame with PageFlags { present: true, write: true, executable: false, user: true, bits: 0x8000000000000007 }
0x43ff000..0x49b5000 :: MapFlags(PROT_WRITE | PROT_READ)
[page at 0x49b5000] is mapped to the zeroed frame with PageFlags { present: true, write: false, executable: false, user: true, bits: 0x8000000000000005 }
[page at 0x49b6000] is mapped to the zeroed frame with PageFlags { present: true, write: false, executable: false, user: true, bits: 0x8000000000000005 }
....
```

and causing the following crash:

```
Page fault: 0000000000001718 P | WR | US
RFLAG: 0000000000010202
CS:    000000000000002b
RIP:   00000000004125fd
RSP:   00007fffffffdd80
SS:    0000000000000023
FSBASE  00000000003f6000
GSBASE  0000000000000000
KGSBASE ffff80007a800000
RAX:   0000000000001718
RCX:   0000000000000000
RDX:   ffffffffffffffff
RDI:   000000000043b5a0
RSI:   00000000004537e0
R8:    0000000000000030
R9:    000000000043b5a0
R10:   0000000000000030
R11:   00000000000000ff
RBX:   0000000000000000
RBP:   00007fffffffddb0
R12:   000000000043b5a0
R13:   00000000004537e0
R14:   00000000004537e0
R15:   000000000043b5a0
  FP 00007fffffffddb0: PC 000000000042614a
  FP 00007fffffffde40: PC 0000000000411ae9
  FP 00007fffffffde80: PC 0000000000417187
  FP 00007fffffffdee0: PC 0000000000411d39
  FP 00007fffffffdf90: PC 000000000041207d
  FP 00007fffffffe020: PC 000000000040bc4c
  FP 00007fffffffe0c0: PC 000000000040c7c9
  FP 00007fffffffe0f0: PC 00000000004276ba
  FP 00007fffffffe1a0: PC 0000000000428087
  FP 00007fffffffe210: PC 000000000041eb6a
  FP 00007fffffffe400: PC 00000000004205c3
  FP 00007fffffffe490: PC 00000000004208dd
  FP 00007fffffffe4d0: PC 000000000040747e
  FP 00007ffffffffd60: PC 000000000092111c
  <Invalid next frame pointer 0x0000000000438490; stack walk ended>
  FP ffff80001b5bfe80: PC ffffffff80046dad
    FFFFFFFF80046BD0+01DD
    kernel::arch::x86_shared::interrupt::exception::page::inner
  FP ffff80001b5bff50: PC ffffffff8003ffbb
    FFFFFFFF8003FF84+0037
    kernel::arch::x86_shared::interrupt::exception::page
  00007fffffffddb0: GUARD PAGE
kernel::context::signal:INFO -- UNHANDLED EXCEPTION, CPU #1, PID 6548, NAME /usr/bin/make, CONTEXT 0xffffff7f8013fdc0
```

Also the crash info would vary every time you run the program since the
contents of The Zeroed Frame would have been mutated. Sneaky bug :^)

This also fixes the crashes that happen when running node.js (and maybe
other programs): https://gitlab.redox-os.org/redox-os/relibc/-/issues/229

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-19 19:54:14 +11:00
Anhad Singh d82ba37de8 feat(mapper/remap_with_full): conditional remap
This commit modifies the transform function (`f`) argument of
`remap_with_full` to return an `Option`. This allows the caller to skip
remaps based on the previous frame and page flags. It can alternatively
be done by first translating the address and then remapping based on
that but that would mean we have to walk the page tables twice :|

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-19 19:50:00 +11:00
Anhad Singh f299c885e6 feat(lib): implement Debug for PhysicalAddress
Make it consistent with the debug output for `VirtualAddress`

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-02-19 19:32:10 +11:00
Ibuki Omatsu 5a8858ff81 refactor: Initialize sys schem resources when they are first accessed. 2026-02-12 06:24:43 -07:00
Jeremy Soller 934162f35a Implement stdfscall 2026-02-11 12:12:49 -07:00
bjorn3 858b712df5 Use naked_asm!() instead of global_asm!() where possible 2026-02-09 22:28:38 +01:00
bjorn3 d51fe0c7e0 Avoid concat!() in inline asm
It is no longer necessary in modern rustc versions.
2026-02-09 22:12:20 +01:00
bjorn3 6bd204e1a3 Remove always true supports_on_close field 2026-02-08 17:23:50 +01:00
bjorn3 4c2c2b6757 Remove Option from State::Waiting.fds 2026-02-08 17:08:59 +01:00
bjorn3 0576db1fb4 Inline UserInner::call and rename call_extended to call 2026-02-08 13:01:14 +01:00
bjorn3 3d1188cf1e Introduce Response::as_regular 2026-02-08 12:54:04 +01:00
bjorn3 99ff55ee1b Demux results as soon as we receive them from a user scheme 2026-02-08 12:50:53 +01:00
bjorn3 f88cbf96ee Remove unnecessary clones and pass CallerCtx to call() 2026-02-08 12:46:08 +01:00
bjorn3 5c6af01a9a Remove two unnecessary uses of spin::Once 2026-02-07 13:14:48 +01:00
bjorn3 e14a20aae2 Mark two functions as private 2026-02-07 12:59:24 +01:00
bjorn3 4e41ed987a Fix /scheme/sys/context header 2026-02-07 12:31:42 +01:00
bjorn3 2f8a3b3d67 Remove unused SchemeNamespace type 2026-02-06 22:05:42 +01:00
bjorn3 f334e760bb Remove ens field from Context
It is no longer used due to the capability rework.
2026-02-06 22:00:18 +01:00
bjorn3 9f218c5b3a Fix assertion in Args::args() 2026-02-06 21:07:16 +01:00
bjorn3 7ff1898765 Fix a couple of warnings 2026-02-06 20:54:42 +01:00
bjorn3 6ddd0a9098 Replace scheme::schemes() with scheme::get_scheme()
We never need to iterate over all schemes. We only ever need to access
individual schemes.
2026-02-06 20:54:42 +01:00
bjorn3 ace9038720 Reduce visibility of a couple of methods 2026-02-06 20:34:16 +01:00
Jeremy Soller 2055a205f1 Remove legacy path message 2026-01-29 10:12:04 -07:00
Ibuki Omatsu 5ac00f5533 Remove namespace management from the kernel. 2026-01-20 20:43:34 -07:00
Jeremy Soller 1c850605d0 Only read time once during context switch 2026-01-20 14:18:33 -07:00
Jeremy Soller 81a49d211b Fix potential preempt guard deadlock 2026-01-20 13:58:31 -07:00
Anhad Singh 7d42e8d966 fix(switch): deadlock
During the snapshot shown, interrupts would be _disabled_ on both CPUs and both
would have have the _same_ address space (i.e.
`PercpuBlock::current().current_addrsp`).

```rs
// CPU 0                                                                                             CPU 1 (inside `context::switch()`)
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// let guard = current_addrsp.acquire_write()
// let flusher = Flusher::with_cpu_set(&addrsp.used_by, &current_addrsp.tlb_ack);
// ...
// drop(flusher); // Flusher::flush()
//     // send IPI to CPU 1 as it is in the `active_set`
//     shootdown_tlb_ipi(Some(1));
//                                                                                                    percpu::switch_arch_hook();
//     // spin until TLB shootdown IPI has been acknowledged by CPU 1                                 // acquire_read() to remove the CPU from the `used_by` set in `prev_addrsp`
//     while ackword < affected_cpu_count                                                             prev_addrsp.acquire_read()
//         PercpuBlock::current().maybe_handle_tlb_shootdown();
//         spin_loop();
//     }
// drop(guard);
```

Now CPU 0 will spin _until_ CPU 1 has acknowledged the IPI. However, CPU 1 has
interrupts disabled and is in the middle of a context switch. To complete the
context switch it needs to remove itself from the `used_by` set in
`prev_addrsp` (which is the current address space atm). To do that it needs to
`acquire_read()` lock but it cannot since it is held by CPU 0 and won't release
it until CPU 1 has acknowledged the IPI; creating a deadlock.

Also note:

```rs
// src/context/memory.rs
// NOTE: Lock must be held, which must be guaranteed by the caller.
pub fn flush(&mut self) {
```

Here is some output from GDB to back this up:

```
pwndbg> info threads
  Id   Target Id                    Frame
  1    Thread 1.1 (CPU#0 [running]) core::sync::atomic::atomic_compare_exchange_weak<usize> (dst=0xffffff7f801972f0, old=0, new=1, success=core::sync::atomic::Ordering::Acquire, failure=core::sync::atomic::Ordering::Relaxed)
    at /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:4100
  2    Thread 1.2 (CPU#1 [running]) kernel::context::memory::Flusher::flush (self=0xffff80004212f4b8) at src/context/memory.rs:2827
  3    Thread 1.3 (CPU#2 [running]) spin::rwlock::RwLock<kernel::context::context::Context, spin::relax::Spin>::write<kernel::context::context::Context, spin::relax::Spin> (self=0xffffff7f801a99c0)
    at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/spin-0.9.8/src/rwlock.rs:239
* 4    Thread 1.4 (CPU#3 [running]) 0xffffffff80059cf9 in kernel::context::memory::AddrSpaceWrapper::acquire_read (self=0xffffff7f80188110)
    at /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs:25
pwndbg> p kernel::context::arch::CONTEXT_SWITCH_LOCK
$1 = core::sync::atomic::AtomicBool {
  v: core::cell::UnsafeCell<u8> {
    value: 1
  }
}
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[0].p.value).wants_tlb_shootdown.v.value
$2 = 0
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[1].p.value).wants_tlb_shootdown.v.value
$3 = 0
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[2].p.value).wants_tlb_shootdown.v.value
$4 = 1
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[3].p.value).wants_tlb_shootdown.v.value
$5 = 0
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[3].p.value).current_addrsp
$6 = core::cell::RefCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
  borrow: core::cell::Cell<isize> {
    value: core::cell::UnsafeCell<isize> {
      value: 0
    }
  },
  value: core::cell::UnsafeCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
    value: core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>::Some(alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global> {
        ptr: core::ptr::non_null::NonNull<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>> {
          pointer: 0xffffff7f80188100
        },
        phantom: core::marker::PhantomData<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>>,
        alloc: alloc::alloc::Global
      })
  }
}
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[2].p.value).current_addrsp
$7 = core::cell::RefCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
  borrow: core::cell::Cell<isize> {
    value: core::cell::UnsafeCell<isize> {
      value: 0
    }
  },
  value: core::cell::UnsafeCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
    value: core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>::Some(alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global> {
        ptr: core::ptr::non_null::NonNull<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>> {
          pointer: 0xffffff7f80188100
        },
        phantom: core::marker::PhantomData<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>>,
        alloc: alloc::alloc::Global
      })
  }
}
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[1].p.value).current_addrsp
$8 = core::cell::RefCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
  borrow: core::cell::Cell<isize> {
    value: core::cell::UnsafeCell<isize> {
      value: 0
    }
  },
  value: core::cell::UnsafeCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
    value: core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>::Some(alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global> {
        ptr: core::ptr::non_null::NonNull<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>> {
          pointer: 0xffffff7f80188100
        },
        phantom: core::marker::PhantomData<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>>,
        alloc: alloc::alloc::Global
      })
  }
}
pwndbg> p (*kernel::percpu::ALL_PERCPU_BLOCKS[0].p.value).current_addrsp
$9 = core::cell::RefCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
  borrow: core::cell::Cell<isize> {
    value: core::cell::UnsafeCell<isize> {
      value: 0
    }
  },
  value: core::cell::UnsafeCell<core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>> {
    value: core::option::Option<alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global>>::Some(alloc::sync::Arc<kernel::context::memory::AddrSpaceWrapper, alloc::alloc::Global> {
        ptr: core::ptr::non_null::NonNull<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>> {
          pointer: 0xffffff7f80133ac8
        },
        phantom: core::marker::PhantomData<alloc::sync::ArcInner<kernel::context::memory::AddrSpaceWrapper>>,
        alloc: alloc::alloc::Global
      })
  }
}
```

```
pwndbg> thread 4
[Switching to thread 4 (Thread 1.4)]
25	in /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs
pwndbg> info threads
  Id   Target Id                    Frame
  1    Thread 1.1 (CPU#0 [running]) core::sync::atomic::atomic_compare_exchange_weak<usize> (dst=0xffffff7f801972f0, old=0, new=1, success=core::sync::atomic::Ordering::Acquire, failure=core::sync::atomic::Ordering::Relaxed)
    at /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:4100
  2    Thread 1.2 (CPU#1 [running]) kernel::context::memory::Flusher::flush (self=0xffff80004212f4b8) at src/context/memory.rs:2827
  3    Thread 1.3 (CPU#2 [running]) spin::rwlock::RwLock<kernel::context::context::Context, spin::relax::Spin>::write<kernel::context::context::Context, spin::relax::Spin> (self=0xffffff7f801a99c0)
    at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/spin-0.9.8/src/rwlock.rs:239
* 4    Thread 1.4 (CPU#3 [running]) 0xffffffff80059cf9 in kernel::context::memory::AddrSpaceWrapper::acquire_read (self=0xffffff7f80188110)
    at /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs:25
pwndbg> thread 4
[Switching to thread 4 (Thread 1.4)]
25	in /mnt/redox/prefix/x86_64-unknown-redox/sysroot/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs
pwndbg> bt
```

This is *after* everything freezes.

For relibc tests, if I run `while true; do
/root/relibc-tests/pthread/once; done` it eventually does freeze up and
does so at the same location:

```
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[ THREADS (4 TOTAL) ]──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ► 1   "" stopped: 0xffffffff800750a2 <kernel::context::switch::switch+1282>
    4   "" stopped: 0xffffffff80074d5a <kernel::context::switch::switch+442>
    3   "" stopped: 0xffffffff80059cf9 <kernel::context::context::Context::set_addr_space+217>
    2   "" stopped: 0xffffffff80020839 <kernel::context::memory::Flusher::flush+361>
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
```

Related: https://gitlab.redox-os.org/redox-os/kernel/-/issues/175

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-19 15:21:13 +11:00
Pascal Reich a919d2626b Inline Documentation Fixes 2026-01-10 16:19:34 -07:00
Jeremy Soller ea06685903 Do not allow recursively registering the same event queue 2026-01-09 12:08:16 -07:00
Anhad Singh a245e49e75 fix(syscalls/futex): premature timeout
Previously, if a futex with a timeout was woken up (even via
`futex_wake`), it was treated as though the timeout had expired. When
the timeout expires, the scheduler sets `wake` to `None` and unblocks
the process. Hence if `wake` is `None` and if a timeout was given to
futex, it has expired. Otherwise the process was woken up by
`futex_wake`.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-07 14:45:01 +11:00
Anhad Singh 5ccd2414af fix(context/memory): incorrect remaining_src_span
The `AddrSpaceWrapper::r#move` is used by `mremap` to move, expand or
shrink existing mappings.

`src_span.count`: Size of old region in pages
`new_page_count`: Size of new region in pages

Fixes the following panic when running `cargo`:

```
KERNEL PANIC: panicked at src/context/memory.rs:1969:9:
assertion failed: self.info.can_extract(false)
  FP ffff80000cbbf2c0: PC ffffffff8004ced5
    FFFFFFFF8004CD50+0185
    kernel::panic::panic_handler_inner
  FP ffff80000cbbf3a0: PC ffffffff8004ac99
  FP ffff80000cbbf3b0: PC ffffffff800a34df
  FP ffff80000cbbf3e0: PC ffffffff800a34b4
  FP ffff80000cbbf430: PC ffffffff8001c029
    FFFFFFFF8001BF10+0119
    kernel::context::memory::Grant::extract
  FP ffff80000cbbf4a0: PC ffffffff800181ac
    FFFFFFFF80016D30+147C
    kernel::context::memory::AddrSpaceWrapper::move
  FP ffff80000cbbfd30: PC ffffffff80037c08
    FFFFFFFF80035660+25A8
    kernel::syscall::syscall
  FP ffff80000cbbfe90: PC ffffffff8008efbf
    FFFFFFFF8008EF10+00AF
    __inner_syscall_instruction
  FP ffff80000cbbff50: PC ffffffff80085d33
    FFFFFFFF80085CF0+0043
    kernel::arch::x86_64::interrupt::syscall::syscall_instruction
  0000000000004455: GUARD PAGE
CPU #2, CID 0xffffff7f80133690
NAME: /scheme/initfs/bin/redoxfs, DEBUG ID: 43
SYSCALL: mremap(0x2177F000, 0x8000, 0x0, 0xC7000, 0x60000)
HALT
```

```
mremap_flags = MremapFlags(
    0x0,
)
prot_flags = MapFlags(
    PROT_WRITE | PROT_READ,
)
```

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2026-01-03 22:56:03 +11:00
Wildan M 92132132c1 Implement clock_getres and handle path to time scheme 2025-12-21 05:24:13 +07:00
Ibuki Omatsu e30ed9ab6a Introduce syscall6. Add unlinkat and remove unlink and rmdir. 2025-12-17 18:31:04 -07:00
Anhad Singh d9eae6bb75 fix(sync/wait_condition): deadlock in WaitCondition::wait
Instead of using a simple switch to determine if preemption is enabled
(`is_preemptable: bool`), a counter is used instead. This handles the
case where a function holding a `PreemptGuard` calls another function
that creates a new `PreemptGuard`.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-12-15 13:05:29 +11:00
bjorn3 62a572a0f0 Use compiler-builtins for the memcpy family of functions 2025-12-14 16:38:04 +01:00
bjorn3 c089667ade Remove support for the legacy packet user schemes 2025-12-13 15:52:30 +01:00
bjorn3 3091f40c13 Warn against opening a legacy scheme version 2025-12-13 15:12:01 +01:00
Wildan M e06f908b1b Add CI workflow 2025-12-11 01:07:33 +07:00
bjorn3 3bf880e008 Correctly handle MAP_FIXED with a zero address 2025-12-09 23:09:19 +01:00
bjorn3 5a11067f10 Support non-fixed and anonymous remote mmap 2025-12-09 20:55:19 +01:00
Jeremy Soller d33fc3b5b0 Merge branch 'mmu_flags' into 'master'
Set RISCV MMU marker flags by default

See merge request redox-os/rmm!18
2025-12-09 06:28:44 -07:00
aarch 5b149b7fe4 Set RISCV MMU marker flags by default 2025-12-09 06:28:44 -07:00
bjorn3 58a362844a Add a binary variant for the filetable read operation
This is a lot easier to parse in no_alloc scenarios than the current
textual format. This would help with moving the cloexec handling from
relibc to redox-rt.
2025-12-08 21:55:03 +01:00
Anhad Singh ac713a061c misc(scheme/user): treat all spurious wakeups as signal
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-11-28 15:24:32 +11:00
Anhad Singh 45aae5f963 misc(scheme/user): use preempt guard
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-11-27 16:23:31 +11:00
Anhad Singh b2c9e5defd misc(scheme/user): unblock the process *after* setting the state
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-11-27 16:21:03 +11:00
Anhad Singh 4ff82ad8b5 fix(scheme/user): deadlocks inside call_extended_inner
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-11-27 14:39:14 +11:00
Jeremy Soller 27465b6132 Make CPU announcements debug level 2025-11-23 07:41:09 -07:00
Jeremy Soller 7ffc046d46 Enable serial interrupts on aarch64 ACPI 2025-11-21 08:39:38 -07:00
Jeremy Soller e3cafc975f Format 2025-11-17 17:41:04 -07:00
Jeremy Soller 91ba44e2fa Implement F_DUPFD_CLOEXEC 2025-11-17 17:40:39 -07:00
aarch 2bdc5d2109 Implement kfpath for dtb kernel scheme 2025-11-15 17:45:39 +00:00
Jeremy Soller e14f935063 Ensure pipe is_alive is set before triggering event or condition 2025-11-14 20:59:44 -07:00
Jeremy Soller 2d9f2015d0 Add upper table fds to kernel.proc filetable 2025-11-14 15:06:37 -07:00
Jeremy Soller 42f9f04188 Require kfpath implementation, add to acpi scheme 2025-11-14 14:19:33 -07:00
Jeremy Soller 61ad67fbfe Improve display of upper table in iostat 2025-11-14 13:55:55 -07:00
4lDO2 33dbf2458e only clear RC_USED_NOT_FREE with freelist locked 2025-11-14 20:06:18 +01:00
4lDO2 96552163f6 Clear RC_USED_NOT_FREE even for contention case. 2025-11-14 20:06:18 +01:00
4lDO2 dc33c67997 Fix potential refcount underflow from fetch_sub. 2025-11-14 20:06:18 +01:00
Jeremy Soller cbea1aca3d Implement kfpath on more schemes 2025-11-14 11:36:49 -07:00
Jeremy Soller 64ea4251ee Debug SYS_MREMAP 2025-11-13 15:55:02 -07:00
Jeremy Soller e6edef2d8e Downgrade addrspace outside futex loop 2025-11-12 10:34:18 -07:00
Jeremy Soller 7834392dba Use hashmap for futex 2025-11-12 08:03:24 -07:00
Jeremy Soller f9d9a3414b Update rmm 2025-11-12 07:37:14 -07:00
Jeremy Soller 409a1c02f5 Derive Hash for PhysicalAddress 2025-11-12 07:36:54 -07:00
4lDO2 70256a5b2f Revert "Fix i686 using cmpxchg8b-based AtomicU64 for stats."
This reverts commit 21f2d8f3e4.
2025-11-12 11:07:09 +01:00
4lDO2 21f2d8f3e4 Fix i686 using cmpxchg8b-based AtomicU64 for stats. 2025-11-12 10:59:51 +01:00
bjorn3 00fdfaf11c Remove -Csoft-float from clippy.sh
It doesn't do anything and will be removed in a future rustc version.
Usage was already removed from the Makefile previously.
2025-11-11 13:40:48 +00:00
Jeremy Soller 01ec650b1e Add support for userspace stack traces using usercopy 2025-11-10 08:54:06 -07:00
Jeremy Soller c66423cec6 Sort target json and allow AtomicU64 on i586/i686 2025-11-10 08:53:47 -07:00
Jeremy Soller 531dfaa3e1 Format 2025-11-06 22:14:25 -07:00
Jeremy Soller 8ae1ced55d Recursively trigger event queues 2025-11-06 22:14:13 -07:00
Jeremy Soller c3437ab6eb Ignore any opens with event: or time: 2025-11-06 09:15:52 -07:00
Jeremy Soller 60af085356 Improve cpu stat accuracy 2025-11-03 20:42:08 -07:00
Jeremy Soller aa50069e15 Remove unnecessary log 2025-11-01 20:49:06 -06:00
Jeremy Soller 91b835d29f Reduce logging significantly 2025-11-01 20:24:11 -06:00
Jeremy Soller 64f2314e2c Fix makefile ifeq 2025-11-01 14:02:34 -06:00
bjorn3 301f163112 Handle building for i586-unknown-redox 2025-11-01 19:30:40 +01:00
bjorn3 65273ea898 Replace all Arc::try_new with Arc::new
The global allocator panics when out of memory rather than returning an
errors. In addition there are plenty of other places where we don't
handle allocation failure anyway. At some point in the future we should
systematically handle out of memory conditions, but until then let's not
pretend we do and get rid of the usage of the unstable allocator_api
feature that is unlikely to get stabilized any time soon.
2025-10-26 12:44:52 -06:00
bjorn3 e101629377 Inline a bunch of functions in KernelMapper 2025-10-26 12:44:52 -06:00
bjorn3 85b5487b5b Couple minor cleanups to the global allocator 2025-10-26 12:44:52 -06:00
bjorn3 3b1fd27431 Remove byteorder dependency 2025-10-26 12:43:08 -06:00
bjorn3 bc3a59abb3 Minor simplification to profiling::nmi_handler 2025-10-26 18:27:29 +01:00
bjorn3 0f7b16d89d Partially use cfg!() rather than #[cfg] for controlling the profiling module
This only adds a pointer worth of overhead per cpu core in the
PerCpuBlock struct.

Also fix a bunch of unsafe_op_in_unsafe_fn warnings in the profiling
code.
2025-10-26 18:27:29 +01:00
bjorn3 53640e67b7 Remove rustc_cfg dependency 2025-10-26 16:32:42 +01:00
bjorn3 8367462abe Update rmm submodule 2025-10-26 16:25:01 +01:00
Jeremy Soller 7e14945bc5 Merge branch 'stable' into 'master'
Remove all nighly feature gates

See merge request redox-os/rmm!17
2025-10-26 09:18:30 -06:00
bjorn3 4b89feab41 Fix a couple of dead code warnings 2025-10-26 12:07:56 +01:00
bjorn3 075d52f153 Fix example binary 2025-10-26 11:58:43 +01:00
bjorn3 e6d42dda19 Fix compilation of EmulateArch 2025-10-26 11:55:42 +01:00
bjorn3 5b5bbe5643 Remove VirtualAddress::is_canonical
This way the last remaining feature gate can be removed. It also matches
how other architectures handle this functionality.
2025-10-25 20:02:55 +02:00
bjorn3 e371f47f51 Remove let_chain feature gate
It is now stable.
2025-10-25 20:01:32 +02:00
bjorn3 1498376360 Unify generic irq handling between x86 and x86_64 2025-10-25 19:44:03 +02:00
bjorn3 3652b693ba Remove usage of iterator_try_collect 2025-10-25 11:34:55 -06:00
bjorn3 164c890830 Remove thread_local feature gate
We use the PerCpuBlock instead of ELF TLS
2025-10-25 11:34:55 -06:00
bjorn3 cb718f767a Remove a bunch of unused __*_start/end symbols 2025-10-25 19:20:01 +02:00
bjorn3 e8acd82074 Directly define __usercopy_{start,end} in the usercopy functions
As opposed to requiring a linker script
2025-10-25 19:12:27 +02:00
bjorn3 cc01d14d3b Unconditionally enable sys_stat 2025-10-25 18:52:07 +02:00
bjorn3 a57c8e410d Avoid warnings from rust-analyzer for the panic handler
Rust-analyzer runs cargo check --all-targets which also checks the test
configuration where previously there would be a bunch of warnings for
unused things due to the panic handler being configured out.
2025-10-19 14:30:53 +02:00
bjorn3 021cdf47f4 Fix a bunch of warnings 2025-10-19 14:27:43 +02:00
bjorn3 9d5ad06b30 Move some code from the trampoline to global_asm!() 2025-10-19 06:23:39 -06:00
bjorn3 4b16e66164 Set arm64 exception handler before entering the rust world 2025-10-19 06:23:39 -06:00
bjorn3 d31e552d08 Set riscv exception handler before entering the rust world 2025-10-19 06:23:39 -06:00
bjorn3 ff65afd003 Don't depend on the stack setup by the bootloader
This way we can choose our own size for the stack and don't have to
identity map it manually. Also this way the bootloader doesn't have to
change the stack pointer right before calling into the kernel (which it
currently does in an unsound way)
2025-10-19 06:23:39 -06:00
bjorn3 b7a69a26ba Reduce indentation in madt x86 init 2025-10-19 06:23:39 -06:00
bjorn3 7ea41f4fee Remove no longer necessary lint allow 2025-10-19 11:49:14 +02:00
bjorn3 b09659ac25 Remove unnecessary unsafe blocks in naked functions 2025-10-19 11:48:46 +02:00
Jeremy Soller 3c3eaa0004 Enable sys_stat by default for sysinfo 2025-10-12 15:49:35 -06:00
Jeremy Soller c9653525a0 Fix compilation with sys_stat feature 2025-10-12 15:45:50 -06:00
Speedy_Lex 0931a7f49f Resolve a huge portion of the clippy lints 2025-10-06 06:30:23 -06:00
Jeremy Soller db8fb14614 Fix compilation on other archs 2025-10-04 11:58:04 -06:00
Jeremy Soller 18bf5d904b Fix aarch64 kernel target 2025-10-04 11:53:51 -06:00
Jeremy Soller e635e7a911 Fix i686 kernel target 2025-10-04 11:53:01 -06:00
Jeremy Soller f7fa2491ac Add rust-toolchain.toml 2025-10-04 09:18:10 -06:00
Jeremy Soller 84385222e2 Use x86-softfloat rustc-abi for x86_64 target 2025-10-04 08:21:00 -06:00
4lDO2 8d50ebd69d Fix target spec int vs string. 2025-10-04 16:12:54 +02:00
Speedy_Lex ea812e8f2a Run cargo fmt 2025-10-04 01:06:15 +02:00
Speedy_Lex d38002969c Fixes for rust update 2025-10-04 00:55:26 +02:00
bjorn3 bc9273057d Remove a bunch of double references from AddrSpaceWrapper::move 2025-10-03 20:53:26 +02:00
bjorn3 db5e6184af Remove unnecessary add_ref in ProcScheme::kfmap
Grant::allocated_shared_one_page already adds a reference. This fixes a
memory leak
2025-09-27 19:44:26 +02:00
bjorn3 6445f04ac4 Avoid overwriting expected count for special frames used by multiple contexts 2025-09-26 23:38:30 +02:00
bjorn3 4db2c919ef Nicer printing of frame refcount mismatch 2025-09-26 23:28:01 +02:00
bjorn3 cd761ee679 Handle all cases in foreach_addrsp 2025-09-26 23:28:01 +02:00
bjorn3 12f908b1ba Take sighandler frames into account during the integrity check 2025-09-26 23:28:01 +02:00
bjorn3 4c85131e36 Always take syscall_head/tail into account during the integrity check
Previously it wouldn't be taken into account if currently used by the
kernel.
2025-09-26 23:28:01 +02:00
bjorn3 ede9a47f9c Move .bss and .data tests to inline asm
If .bss is not properly cleared or .data is incorrectly cleared, there
is no way to tell what will happen if we try to run Rust code.
2025-09-25 09:46:17 -06:00
bjorn3 ac35b7984a Fix kernel debugger 2025-09-25 17:26:31 +02:00
Jeremy Soller 0203ad750a Fix compilation on aarch64/riscv64gc 2025-09-23 13:46:44 -06:00
Jeremy Soller 4526acc259 Drop comment about fixed multi_core issues 2025-09-23 13:09:32 -06:00
Jeremy Soller b0d5fa0993 Copy all higher PML4 entries in setup_new_utable (fixes some AMD CPUs) 2025-09-23 13:09:12 -06:00
Jeremy Soller 89c182cca1 Restore return in percpu::switch_arch_hook 2025-09-23 13:08:34 -06:00
Jeremy Soller b6a5245556 Require passing loopback test for hard-coded serial 2025-09-23 11:33:37 -06:00
Jeremy Soller 6ce2101cf4 Do not mark soc ranges as device memory 2025-09-23 10:31:34 -06:00
Jeremy Soller 5dc6f7c3ba lock ordering 2025-09-22 07:48:48 -06:00
bjorn3 e7358e3e5b Deduplicate a bunch of things that use KernelArgs between archs 2025-09-20 19:10:19 +02:00
bjorn3 3f385ba79d Unify KernelArgs type between architectures 2025-09-20 19:10:19 +02:00
bjorn3 c35c17c67e Merge display.rs into debug.rs 2025-09-20 17:59:19 +02:00
bjorn3 b36deffa61 Replace scrolling with wraparound in graphical debug
Inspired by how Haiku does printing for its kernel debugger, this commit
gets rid of the scrolling when the bootlog reaches the end of the screen
and instead wraps around to the start of the screen. Between the last
written line and the first visible written line there is always a blank
line to provide visual separation.

Getting rid of the scrolling significantly simplifies the implementation
of graphical debug and removes the need for double buffering for
performance as we no longer need to read back the framebuffer when
scrolling which is very expensive on write-combining memory like the
framebuffer.
2025-09-20 17:15:02 +02:00
bjorn3 84ac36ca2f Inline DebugDisplay::write_char 2025-09-20 15:42:08 +02:00
bjorn3 3db8bf878e Remove workaround for Meteor Lake having an AP with hardware cpu id 0 2025-09-20 15:33:08 +02:00
bjorn3 f58bcd584e Separate logical and hardware cpu ids 2025-09-20 15:33:08 +02:00
bjorn3 3a47c3becc Move most HPET logs to the trace log level
This significantly reduces the amount of boot logs produced by the
kernel by default on x86. With this the full kernel boot logs now fit on
a single screen on my system.
2025-09-20 15:21:54 +02:00
bjorn3 99b626845d Cleanup after removing INIT_THREAD 2025-09-20 15:21:38 +02:00
Jeremy Soller 229a5de6ff Remove INIT_THREAD 2025-09-19 20:30:26 -06:00
Jeremy Soller 7abe4e1051 Remove slab allocator 2025-09-19 20:29:53 -06:00
Jeremy Soller eb69d37323 Apply 1 suggestion(s) to 1 file(s)
Co-authored-by: bjorn3 <4397-bjorn3@users.noreply.gitlab.redox-os.org>
2025-09-19 06:43:19 -06:00
Elle Rhumsaa 8255e74ffd fixup: scheme: remove unnecessary braces
Removes unnecessary braces to fix compilation error.

Signed-off-by: Elle Rhumsaa <elle@weathered-steel.dev>
2025-09-19 06:43:19 -06:00
Elle Rhumsaa 0022bd448c dtb: remove allocation for in-memory DTB
Replaces the `Once<Vec<u8>>` with `Once<&'static [u8]>` to avoid an
unnecessary allocation.

Adds some basic documentation.

Signed-off-by: Elle Rhumsaa <elle@weathered-steel.dev>
2025-09-19 06:43:19 -06:00
bjorn3 68526b2af5 Use naked asm for riscv exception handler 2025-09-18 17:29:50 +02:00
bjorn3 081efd6cfa Allocate IDT for APs on the BSP and statically allocate BSP IDT
This allows them to be immediately installed by kstart/kstart_ap without
having to wait for the page tables to be set up correctly. This removes
the initial IDT.
2025-09-17 21:03:36 +02:00
bjorn3 e81db007b7 Couple of cleanups to the IDT handling 2025-09-17 21:03:36 +02:00
bjorn3 742a7f4492 Remove Option around IDTs HashMap 2025-09-17 21:03:36 +02:00
Jeremy Soller 2bf580b260 Reimplement iostat 2025-09-16 20:39:06 -06:00
bjorn3 25d526e9a1 Inline load_segments 2025-09-16 19:58:56 +02:00
bjorn3 647c87c5a0 Allocate PCR for APs on the BSP
This allows them to be immediately installed by kstart_ap without having
to wait for the page tables to be set up correctly. This removes the
initial GDT.
2025-09-16 19:57:31 +02:00
bjorn3 dbe25b78e3 Make it possible to change KernelArgsAp without changing the trampolines 2025-09-16 19:33:07 +02:00
bjorn3 019564ee0e Statically allocate PCR for the BSP 2025-09-15 22:01:15 +02:00
bjorn3 4884d749af Make PercpuBlock const constructable 2025-09-15 19:00:03 +02:00
bjorn3 3329a41121 Unify set_tss_stack and set_userspace_io_allowed signatures between x86 and x86_64 2025-09-15 18:37:27 +02:00
bjorn3 05e344bd9e Unify tss alignment method between x86 and x86_64 2025-09-15 18:23:29 +02:00
bjorn3 9a14f9a80d Unify gdt handling between x86 and x86_64 2025-09-14 20:30:57 +02:00
bjorn3 d1c7177038 Remove unused macro 2025-09-14 20:21:46 +02:00
bjorn3 200aeac2ba Reduce visibility of a couple of idt things 2025-09-14 19:10:09 +02:00
bjorn3 d3b17177b2 Avoid allocating during panics and infer kernel image size without explicitly storing it 2025-09-14 13:11:13 +02:00
bjorn3 9f71f02532 Reduce indentation in stack_trace 2025-09-13 21:34:02 +02:00
bjorn3 6334977090 Inline symbol_trace into strack_trace 2025-09-13 21:34:02 +02:00
bjorn3 30bbafdfa4 Use the object crate for panic backtraces
This increases the kernel image size by about 16kb, but in return
significantly simplifies things.
2025-09-13 21:34:02 +02:00
bjorn3 ad4ea619e8 Fix interrupt race condition on arm64 and riscv64 2025-09-13 20:29:32 +02:00
bjorn3 9e37ccaae8 Fix enable_and_halt on arm64
I accidentally used nop instead of wfi
2025-09-13 19:07:01 +02:00
bjorn3 83b4538d7c Merge two asm blocks
There is no guarantee they will be atomic otherwise
2025-09-13 18:55:16 +02:00
bjorn3 61db2b2ad5 Use core::hint::spin_loop() where possible 2025-09-13 18:55:16 +02:00
bjorn3 711ea9a4ed Move system76_ec::init() into serial::init() 2025-09-13 18:55:16 +02:00
bjorn3 5a6117b5ae Replace the log crate with a custom logging system
This avoids the need to explicitly set a logger early during boot, which
reduces the amount of moving parts that could go wrong slightly. And it
cuts the kernel image size by 13kb.
2025-09-13 18:55:16 +02:00
Jeremy Soller 8a2aa411e2 Explicitly scope all locks, fixing multi_core hangs. Allow contexts on any CPU 2025-09-13 10:10:07 -06:00
bjorn3 da6f7adb42 Use HashMap rather than BTreeMap for scheme handles
According to the comments this previously wasn't done due to hashbrown
not having a const constructor. While it is true that HashMap::new() is
not const, HashMap::with_hasher() is const. HashMap::new() becoming
const is likely blocked on const traits.

This shrinks the kernel image by about 35kb.
2025-09-13 12:00:37 +02:00
bjorn3 9aef07372e Make insert_global panic on errors
All callers unwrap the result anyway
2025-09-12 19:56:14 +02:00
bjorn3 6ae6f571c7 Use cfg!() rather than #[cfg] for configuring lpss_debug 2025-09-12 19:36:17 +02:00
bjorn3 92e5397efa Introduce SerialKind::NotPresent 2025-09-12 19:36:17 +02:00
bjorn3 2394db2dc5 Move most of the arch debug::Writer impls into a common location 2025-09-12 19:36:17 +02:00
bjorn3 fbbe24c82b Use writeln!() rather than print!() + concat!() in println!()
This fixes using format arg captures
2025-09-12 19:36:17 +02:00
bjorn3 b3522b19e6 Replace a writeln!() with println!() 2025-09-12 19:36:16 +02:00
bjorn3 a782c1f9e1 Fix warning about unused function 2025-09-12 19:03:39 +02:00
bjorn3 8aa08e1e3d Unconditionally enable serial_debug on arm64 and riscv64 2025-09-12 18:59:48 +02:00
bjorn3 520453f779 Move x86 serial port assignment to the init function 2025-09-12 18:46:11 +02:00
bjorn3 31cbb3b361 Remove duplicate serial port initialization on x86 2025-09-12 18:41:42 +02:00
bjorn3 7a4dd1a1a9 Use SerialKind on x86 2025-09-12 18:40:21 +02:00
bjorn3 f0eea47896 Fix compilation with lpss_debug feature enabled 2025-09-12 18:33:16 +02:00
bjorn3 eb06f5676f Unify SerialKind between arm64 and riscv64 2025-09-12 18:19:15 +02:00
bjorn3 6ca9a9a806 Move uart_pl011.rs to src/devices 2025-09-12 18:02:30 +02:00
bjorn3 f9a4178898 Always enable graphical_debug
We already gracefully handle a missing framebuffer.
2025-09-11 21:41:30 +02:00
bjorn3 9a2203076a Merge aarch64 and x86/x86_64 debugger implementations
And make the debugger partially work on riscv64.
2025-09-11 20:02:56 +02:00
bjorn3 e131bf219d Merge x86 and x86_64 debugger implementations 2025-09-11 20:02:56 +02:00
bjorn3 d1668e232a Begin deduplicating debugger code between architectures 2025-09-11 20:02:56 +02:00
bjorn3 40605e643e Move stac/clac for SMAP in debugger to just around the stack read loop
This fixes a crash when returning from the debugger on x86_64.
2025-09-11 20:02:56 +02:00
bjorn3 26dd87b1ff Fix debugger feature on arm64
And fix unsafe_op_in_unsafe_fn warnings
2025-09-11 20:02:56 +02:00
bjorn3 38188b0640 Expand a macro invocation 2025-09-10 18:45:13 +02:00
bjorn3 786c9eabcb Share print! and println! between architectures 2025-09-10 18:40:30 +02:00
bjorn3 1268472103 Move arch::x86_64::cpuid into arch::x86_shared::cpuid 2025-09-10 18:35:36 +02:00
bjorn3 ad6c6c5e41 Share external interrupt handlers between x86 and x86_64 2025-09-10 18:31:28 +02:00
bjorn3 5e6d681fcb Share exception interrupt handlers between x86 and x86_64 2025-09-10 18:25:22 +02:00
bjorn3 d6c5d0d268 Move semicolons 2025-09-10 18:25:09 +02:00
bjorn3 35a0f2d440 Remove usage of array_chunks
It has been removed in newer rustc versions
2025-09-10 18:00:02 +02:00
bjorn3 a3700fa446 Remove the unsafe block from the inner function in interrupt!() 2025-09-10 18:00:02 +02:00
Elle Rhumsaa cec902e6be main: refactor unsafe block for C offsets
Uses the `&raw const` syntax to convert the pointer location of static
offsets from C.
2025-09-10 14:55:36 +00:00
bjorn3 fe1c2f460e Fix a bunch of errors and warnings after moving to the 2024 edition 2025-09-10 16:44:36 +02:00
bjorn3 cea93f7647 cargo fix --edition & rustfmt
Or to be precise:
RUST_TARGET_PATH=$(pwd)/targets cargo fix --edition \
--target targets/x86_64-unknown-kernel.json \
--target targets/i686-unknown-kernel.json \
--target targets/aarch64-unknown-kernel.json \
--target targets/riscv64-unknown-kernel.json \
-Zbuild-std=core,alloc --allow-dirty --bin kernel
cargo fmt
2025-09-10 16:44:36 +02:00
bjorn3 ff48830c0b Update rmm submodule 2025-09-10 16:44:33 +02:00
Jeremy Soller 5f983a02fe Merge branch 'edition_2024' into 'master'
Update to the 2024 edition

See merge request redox-os/rmm!16
2025-09-10 08:40:36 -06:00
bjorn3 08c00a434d Update to the 2024 edition
On newer rustc versions let_chain is only allowed with the 2024 edition.
2025-09-10 15:37:19 +02:00
4lDO2 dd366f01c4 Make ForceKilled meaningful, += Dead && SIGKILL. 2025-09-10 13:22:29 +02:00
Paul Sajna 172a0ffd02 remove dtb unwraps 2025-09-07 22:53:39 -07:00
Jeremy Soller 53c3342e9f snps,dw-apb-uart is usually 32-bit mmio 2025-09-07 20:41:28 -06:00
Jeremy Soller f1492729d2 riscv64: support snps,dw-apb-uart serial 2025-09-07 20:36:05 -06:00
bjorn3 5658fc258b Disable debugger feature by default
It currently doesn't compile on aarch64
2025-09-07 13:35:22 +02:00
bjorn3 c404598296 Use cfg!() rather than #[cfg] for the cfg in map_memory 2025-09-07 13:26:04 +02:00
bjorn3 e42fc3811f Fix compiling with profiling feature enabled 2025-09-07 13:20:19 +02:00
bjorn3 b7566e66bd Fix 32bit x86 2025-09-07 13:00:40 +02:00
bjorn3 48f3592bf3 Mostly use cfg!() rather than #[cfg] for controlling syscall_debug
This only adds 40 bytes overhead per cpu core in the PerCpuBlock struct.
2025-09-07 12:38:57 +02:00
bjorn3 fefede0d67 Use cfg!() rather than #[cfg] for controlling self_modifying 2025-09-07 12:30:33 +02:00
bjorn3 b5822ac118 Mostly use cfg!() rather than #[cfg] for controlling sys_stat
This only adds 48 bytes overhead per cpu core in the PerCpuBlock struct.
Also fixes compilation with sys_stat enabled on x86_64.
2025-09-07 12:27:04 +02:00
bjorn3 0a58e9e806 Allow cfg(dtb) for check-cfg 2025-09-07 12:03:37 +02:00
bjorn3 f05be85966 Use cfg!() rather than #[cfg] for controlling multi_core 2025-09-07 12:02:16 +02:00
bjorn3 d6e9022c4a Rustfmt 2025-09-06 17:10:32 +02:00
bjorn3 869a664172 Remove allow(unexpected_cfgs) 2025-09-06 17:06:31 +02:00
bjorn3 cf019ab9a5 Remove some unused unsafe blocks 2025-09-06 16:51:05 +02:00
bjorn3 c4c605630a Remove an allow(unused) for the elf module 2025-09-06 16:49:45 +02:00
bjorn3 7975d2aa8f Remove Unique
It is only used for AlignedBox which can just directly implement Send
and Sync. Additionally make the Send and Sync impls more restrictive by
requiring the inner type to be Send cq Sync, previously AlignedBox was
always Send and Sync, which is not sound.
2025-09-06 16:23:30 +02:00
bjorn3 afed3bc84b Fix a couple of warnings 2025-09-06 16:17:05 +02:00
bjorn3 7f63a5c8f0 Don't mark irq_trigger as no_mangle 2025-09-01 17:19:09 +00:00
Jeremy Soller c6f38f05e4 Disable multi_core again (for demo) 2025-08-28 10:00:16 -06:00
Wildan Mubarok 7d91390f04 Detect if ARM virtual timer should be used 2025-08-16 12:58:09 +00:00
Wildan Mubarok e071bdcef4 Use ARM virtual timer to fix HVF acceleration 2025-08-16 11:20:48 +00:00
Wildan M 39cb82d91d Optimize graphical debug scrolling 2025-08-09 18:30:51 +07:00
lebakassemmerl 6bf8c0c26c fix build-error on aarch64 and probably on riscv 2025-08-04 20:39:02 +02:00
Wildan Mubarok 1ff46c8482 Fix Linter CI 2025-08-04 06:34:31 -06:00
Jeremy Soller af7591bc26 Clarify vector number in IPI 2025-08-03 20:56:18 -06:00
Jeremy Soller 5d06ad4e6a Ensure that APIC ID is uses for all IPIs, enable multi_core feature 2025-08-03 20:53:58 -06:00
Jeremy Soller b4f566dab2 Rebuild if Cargo.toml or Cargo.lock change 2025-08-03 16:04:49 -06:00
Wildan Mubarok c67fc7b099 Backfill aarch64 serial log 2025-07-31 03:22:52 +00:00
Ibuki Omatsu e3d8ae1b79 feat: Introduce FdTbl and make Context.files use it for separate file tables. 2025-07-30 15:33:06 -06:00
Darley Barreto 66ea2b46ee Adding openat syscall 2025-07-13 06:43:20 -06:00
bjorn3 caf5fa955b Fix freeing of phys_contiguous frames
Previously the deallocation would be rounded to the next power of two
preventing partial deallocation. But more importantly previously trying
to free phys_contiguous frames while another processes still borrows
them. Now this should just cause the deallocation to be delayed.
2025-07-06 16:13:13 +02:00
bjorn3 08ea1da2f9 Trigger read event for user schemes when an fd is closed 2025-07-05 17:54:19 +02:00
bjorn3 7a440bcd67 Merge close and on_close scheme calls 2025-07-05 16:59:08 +02:00
bjorn3 48ad866d02 Add some explanation to the multi_core todo 2025-06-28 20:16:29 +02:00
bjorn3 751803553f Unify paging between x86 and x86_64 2025-06-28 20:09:16 +02:00
bjorn3 ba66388ca7 Unify rmm.rs between x86 and x86_64 2025-06-28 20:03:06 +02:00
bjorn3 b06aa61676 Remove reference to no longer existing 3dnow target feature
This silences a lot of warnings.
2025-06-28 19:58:15 +02:00
bjorn3 219dedda32 Unify start.rs between x86 and x86_64 2025-06-28 19:57:52 +02:00
bjorn3 ba051b781f Shorten the message about the RSDP 2025-06-28 19:37:56 +02:00
bjorn3 1864f12913 Make the HPET debug logs more compact 2025-06-28 19:37:56 +02:00
bjorn3 2a2139c46e Fix a couple of warnings 2025-06-28 19:37:56 +02:00
bjorn3 e77257bb6e Remove unused core_intrinsics feature gate 2025-06-28 19:37:56 +02:00
Ibuki Omatsu 90643abbad feat: Store caller's PID in Sqe during SYS_CALL 2025-06-25 08:44:51 -06:00
Wildan Mubarok fa907f02ae Move aarch64 interrupt init func 2025-06-25 08:37:50 -06:00
Jeremy Soller f32d018d85 Format 2025-06-13 20:26:41 -06:00
Jeremy Soller 5b88d1a845 Debug using pid 2025-06-13 20:26:35 -06:00
Jeremy Soller 22cc551450 Sort /scheme/sys files 2025-06-13 20:26:21 -06:00
Ivan Tan e67cca7bce raspi3b+: sloved programs can not be waken up on time from sleep 2025-05-19 15:27:35 +08:00
Ivan Tan f5aeb0b43a implement monotonic for aarch64 2025-05-13 15:30:45 +08:00
Jeremy Soller 407c0c1403 Disable syscall debug 2025-05-06 08:21:09 -06:00
Jeremy Soller d712ff5158 Add flink 2025-05-03 12:25:46 -06:00
4lDO2 4a1cd73da4 Fix same-thread scheme use-after-free. 2025-04-26 16:33:10 +02:00
bjorn3 03ebb3491b Show pid of process on unhandled exceptions 2025-04-24 20:53:50 +02:00
bjorn3 8e6ff4341e Don't crash on GICv3
Serial input is still broken though.
2025-04-21 16:56:12 +02:00
bjorn3 75edd1d34c Fix infinite panicking when panicking during early boot 2025-04-21 16:44:27 +02:00
4lDO2 9be617132a Fix 'sys:exe' as required by libstd. 2025-04-20 14:09:31 +02:00
4lDO2 98999e76b2 Fix sendfd error handling. 2025-04-20 13:57:37 +02:00
4lDO2 952b1483d8 Pass the sendfd arg: u64 to userspace. 2025-04-20 12:36:33 +02:00
4lDO2 f7d413e1bb Use redox-os/syscall for git dep. 2025-04-19 19:23:57 +02:00
4lDO2 e6df56cf1b Use saner debug IDs for kmain. 2025-04-19 16:30:49 +02:00
4lDO2 6ed49d2ecb Reduce outdated header in sys/context. 2025-04-19 16:30:49 +02:00
4lDO2 1e3e961b78 Simplify context debug names. 2025-04-19 16:30:49 +02:00
4lDO2 22afbde451 Fix being_sigkilled todo! 2025-04-19 16:30:49 +02:00
4lDO2 1227f2222e Fix compilation on riscv64gc. 2025-04-19 16:30:48 +02:00
4lDO2 4d49f1a8e4 Refer to NLnet funding. 2025-04-19 16:30:48 +02:00
4lDO2 9447986889 Remove ksignal from aarch64. 2025-04-19 16:30:48 +02:00
4lDO2 b13ef6ada3 Fix i686. 2025-04-19 16:30:48 +02:00
4lDO2 2e6122bc7e Allow procmgr to recognize unhandled exceptions. 2025-04-19 16:30:48 +02:00
4lDO2 020b8ad415 Compile on aarch64. 2025-04-19 16:30:48 +02:00
4lDO2 10c53aef10 Remove RtSigInfo import. 2025-04-19 16:30:48 +02:00
4lDO2 10ef631fc3 Remove WaitMap from existence. 2025-04-19 16:30:48 +02:00
4lDO2 f3af1be69f Never return from ForceKill caller. 2025-04-19 16:30:48 +02:00
4lDO2 3a17f50ea8 Remove ContextHandle::Signal. 2025-04-19 16:30:47 +02:00
4lDO2 fa6dee36da Report all being_sigkilled contexts as Dead. 2025-04-19 16:30:47 +02:00
4lDO2 5df7031eb1 Add Interrupt ContextVerb. 2025-04-19 16:30:47 +02:00
4lDO2 ab11e6b346 Support stopping contexts, by procmgr. 2025-04-19 16:30:47 +02:00
4lDO2 2f977bbc52 Support getting intra-page off and mapping sig [tp]ctl. 2025-04-19 16:30:47 +02:00
4lDO2 e002d0be33 Remove commented-out syscalls and SigState.rtqs 2025-04-19 16:30:47 +02:00
4lDO2 cb1a838f05 Start moving kill to procmgr. 2025-04-19 16:30:47 +02:00
4lDO2 d0e09d9e87 Remove SYS_IOPL and SYS_VIRTTOPHYS debug. 2025-04-19 16:30:47 +02:00
4lDO2 ef78ac57b0 Add fd-based virttophys replacement. 2025-04-19 16:30:47 +02:00
4lDO2 b4b2ac312b Add interface for setting iopl. 2025-04-19 16:30:46 +02:00
4lDO2 2815800164 Support reading context status. 2025-04-19 16:30:46 +02:00
4lDO2 7b06ca16b1 Make thread kill API async. 2025-04-19 16:30:46 +02:00
4lDO2 f40ec48b3e Send event on thread death. 2025-04-19 16:30:46 +02:00
4lDO2 db5931504d Remove nonexisted import. 2025-04-19 16:30:46 +02:00
4lDO2 ce77a018ec Reach init again, with proc mgr. 2025-04-19 16:30:46 +02:00
4lDO2 a9fb2dcb93 Simplify proc scheme security. 2025-04-19 16:30:46 +02:00
4lDO2 0ccc825bfb Patch syscall. 2025-04-19 16:30:46 +02:00
4lDO2 a78d36f7f2 Reach init in userspace. 2025-04-19 16:30:46 +02:00
4lDO2 6d1a3e9a4c Convert Handle::Context -> Handle. 2025-04-19 16:30:45 +02:00
4lDO2 2a5bd36899 Reimplement context creation. 2025-04-19 16:30:45 +02:00
4lDO2 8883818501 Make kernel compile. 2025-04-19 16:30:45 +02:00
4lDO2 1d5f8fd46d Move proc code to userspace. 2025-04-19 16:30:42 +02:00
Andrey Turkin 1b9fcbf593 riscv: Remove SBI logger
SBI needs a physical address; it used to work before because of the buggy code by sheer chance.
Rather than trying to fix it the right way (find a mapping from virtual to physical both before
and after RMM) let's just throw it away. Serial logger works just fine for the early init logging.
2025-04-19 10:03:35 +03:00
Jeremy Soller e5f4795024 Fix riscv64 ABI 2025-04-17 20:01:14 -06:00
Jeremy Soller fab76e7dca Fix compilation on riscv64 2025-04-17 15:34:24 -06:00
4lDO2 5d41cd7c53 Remove unimplemented itimer scheme. 2025-04-13 18:13:00 +02:00
bjorn3 f5f877ca22 Fix saving and restoring of float registers on arm64 2025-04-12 17:11:04 +02:00
Jeremy Soller a926baefaf aarch64 fp_load/fp_save do not need to be naked
There is a bug with LLVM and Rust causing naked functions to not support
target_enable directives.

https://github.com/rust-lang/rust/issues/136280
2025-04-12 08:14:38 -06:00
Jeremy Soller 551443d641 Revert "aarch64 must have fp-armv8 feature to use some instructions"
This reverts commit a24192235e.
2025-04-12 08:05:55 -06:00
Jeremy Soller 0140e2a382 Fix compilation of emergency_stop on x86 2025-04-11 20:55:56 -06:00
Jeremy Soller a24192235e aarch64 must have fp-armv8 feature to use some instructions 2025-04-11 18:26:09 -06:00
Jeremy Soller 25f422b53f Update data layout for aarch64 2025-04-11 18:20:35 -06:00
4lDO2 f4d643e87c Fixes for netstack cancellation to work. 2025-04-10 19:32:41 +00:00
bjorn3 8f589f7b88 Disable graphical debug only once writing to the fd
This allows obtaining an fd for this before calling setrens while doing
the actual disabling after calling it.
2025-04-06 17:13:26 +02:00
4lDO2 81374e6f7b Add support for CallFlags::CONSUME. 2025-04-06 15:50:32 +02:00
Jeremy Soller ceccc40a1d Disable multi_core feature 2025-04-04 14:25:26 -06:00
4lDO2 ef5de94150 Use sys scheme for kstop rather than signals. 2025-03-31 14:59:00 +02:00
4lDO2 92fcb4472b Use more reliable triple fault for emerg..._reset. 2025-03-31 14:58:05 +02:00
4lDO2 3ae117b812 Outsource x86 RTC handling to rtcd. 2025-03-30 15:28:25 +02:00
Jeremy Soller ce60a7939e Update redox_syscall in Cargo.lock 2025-03-20 10:50:39 -06:00
bjorn3 23fd308745 Reduce verbosity of debug logs during booting
A bunch of things are now printed a bit more compactly or without
interleaving of logs on a single line. Also a bunch of not that useful
logs are no longer printed by default at all.
2025-03-15 20:52:06 +01:00
bjorn3 81210b9ed0 Update and re-enable the legacy scheme deprecation warnings
I've tested booting, several cosmic apps and netsurf as not causing any
warning with the new set of exclusions and all my recent MR's merged.
2025-03-13 18:51:37 +01:00
Jacob Lorentzon 4607576006 Implement bidirectional SYS_CALL support 2025-03-03 23:21:56 +00:00
Ribbon 8f24d894eb Fix a typo on the documentation command in the README 2025-03-03 07:41:42 +00:00
Ron Williams ba613ce628 Nanosleep: Return time remaining after interrupt 2025-02-26 21:00:23 +00:00
Majoneza 06f2c93140 chore: validate_region return PageSpan
Changed validate_region function to return PageSpan instead of a tuple. All the code
using validate_region function was updated to use PageSpan as well.
2025-02-25 23:38:38 +01:00
Vincent Berthier 2da88c18c0 Add the sys:stat scheme 2025-02-22 14:27:10 +00:00
4lDO2 84632ab708 Disable warning when opening "old" schemes. 2025-02-21 16:56:53 +01:00
4lDO2 ef0758b9cc Always use close message when available. 2025-02-21 16:50:16 +01:00
4lDO2 7295777985 Add one-way close message for schemes. 2025-02-21 15:56:05 +01:00
4lDO2 f044ffb03b Remove stable #![feature] and most x86_64 static mut. 2025-02-21 14:16:58 +01:00
4lDO2 09eaf12201 Add optional fdstat sys scheme statistic. 2025-02-19 11:55:18 +01:00
Anhad Singh 79de74bf3a fix(scheme/itimer): wrong chunk size
Chunk size of the scheme (`size_of::<ITimerScheme>() == 0`) was being
provided instead of `size_of::<ITimerSpec>()`. This resulted in a kernel
panic (division by zero) when kread was called for this scheme.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2025-01-16 03:10:01 +00:00
Jeremy Soller 7a530cf0ec Update dependencies 2025-01-14 15:59:14 -07:00
Jeremy Soller 668a123b9a Switch to naked_asm 2025-01-14 15:59:07 -07:00
Ribbon 495c3708f3 Document how to contribute and do development in the README 2025-01-09 12:00:00 +00:00
Andrey Turkin 7db6667e6b Better parsing of IRQ specifications in DTB
Fixes Raspberry 3B+ DTB parsing (as generated by Qemu)
2024-12-18 21:11:46 +03:00
Andrey Turkin 7f38f51b20 dtb: Apply bus mappings 2024-12-18 21:11:46 +03:00
Zhouqi Jiang 52763e7e70 arch: riscv64: use sbi-rt crate to process SBI calls, save code sizes 2024-12-18 14:06:08 +00:00
Anhad Singh d4797bbf50 chore: update redox_syscall
Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-12 13:34:49 +11:00
Anhad Singh af36ae12b0 fix(mremap): fix referencing
Before it was first add_ref'ed by `borrow_frame_enforce_rw_allocated`,
manually and then by `allocated_shared_one_page`.

Now it is only done by `borrow_frame_enforce_rw_allocated` and does not
get unref-ed as take() is called on the returned `RaiiFrame`.

Now the page is manually mapped and an `Allocated` type grant is
constructed (synonymous to `MAP_PRIVATE`). Before by using `allocated_shared_one_page`
an `AllocatedShared` provided grant was constructed (synonymous to
`MAP_SHARED`), which was wrong as the TCB would've not got CoW-ed
after fork(), making the Tcb malformed.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
2024-12-11 16:37:01 +11:00
Anhad Singh 08231eb4df feat(mremap): KEEP_OLD
Signed-off-by: Anhad Singh <andypython@protonmail.com>
Co-authored-by: @4lDO2
2024-12-11 16:08:08 +11:00
Andrey Turkin 7af6dd1f88 Restore riscv,plic0 compatible check 2024-11-07 05:09:24 +03:00
Andrey Turkin 9fe8f759af Fix formatting and a warning 2024-11-06 12:13:13 +03:00
Andrey Turkin ee89d02282 Change PLIC compatible string from riscv,plic0 to sifive,plic-1.0.0
Former one is deprecated and apparently only used by QEMU. Latter is used by QEMU as well as others.
2024-11-06 12:09:36 +03:00
Jeremy Soller 99fbdf426c Fix assumption that CPU ID must equal APIC ID 2024-11-04 14:46:46 -07:00
Andrey Turkin 7b1d135057 Use redoxer for CI jobs 2024-11-01 06:51:13 +03:00
Jeremy Soller 4db9673e2a Support SPCR and clean up device memory allocation 2024-10-31 10:53:58 -06:00
Arthur Paulino e19c1404f7 chore: enrich context/switch
* Add documentation and more code comments to `src/context/switch.rs`
* Eliminate a `context.wake.expect(...)` where `context.wake.is_some()`
* Eliminate a TODO item about updating contexts' timestamps in `switch_to`
* Eliminate a dangling `else { continue }` at the end of the loop that iterates
  on contexts
2024-10-31 10:22:21 +00:00
Jeremy Soller df9db9291a Fix AP CPU ID on newer Intel CPUs 2024-10-30 21:09:06 -06:00
Jeremy Soller 9b6d1549b5 Support GTDT for aarch64 2024-10-30 18:17:11 -06:00
Jeremy Soller 34a6a441f1 Initial aarch64 ACPI support 2024-10-30 16:16:24 -06:00
Jeremy Soller b221bb6c51 Make it possible to boot aarch64 with invalid DTB 2024-10-30 12:34:50 -06:00
Jeremy Soller 4dd6a26742 Make it possible to compile acpi system on any arch 2024-10-30 11:43:21 -06:00
Jeremy Soller 939c9567ee Support 16550 uarts for aarch64 debug output 2024-10-29 14:06:00 -06:00
Jeremy Soller 161e578f29 Use null driver for unknown IRQ controllers on aarch64 2024-10-29 08:01:38 -06:00
Jeremy Soller 380532aea5 Improve reliability of aarch64 startup code 2024-10-29 08:00:57 -06:00
Jeremy Soller 15b0133b7b Add arm,gic-400 support to GIC driver 2024-10-29 08:00:17 -06:00
Jeremy Soller e4e55103ad Remove old aarch64 asm code 2024-10-29 07:59:12 -06:00
Arthur Paulino ea0356b26a Address minor warts
* Mention the need to have `nasm` available on the PATH in the README
* Replace the deprecated `hide_parse_errors` by `show_parse_errors` in `rustfmt.toml`
* Mark unused variables in `src/scheme/proc.rs`
2024-10-27 18:14:12 -03:00
Andrey Turkin 8dcf850919 Update rmm 2024-10-23 04:06:26 +03:00
Jeremy Soller 63669069f4 Merge branch 'bump_fix' into 'master'
Fix a bump allocator error

See merge request redox-os/rmm!15
2024-10-22 21:26:17 +00:00
Andrey Turkin 91ccf4e6aa Fix a bump allocator error 2024-10-22 22:14:39 +03:00
Andrey Turkin 505425bec9 Expose riscv64/aarch64 legacy irqs (requiring remapping) to the irq scheme 2024-10-22 20:26:40 +03:00
Andrey Turkin cba02a26fa Rework irqchip to support risc-v irqs, and add risc-v irq chips handling 2024-10-22 19:16:21 +03:00
Andrey Turkin 906259c024 Pull irqchip from aarch64 code into more generic place 2024-10-21 19:56:32 +03:00
Jeremy Soller 6a731d0c84 Delete syscall directory 2024-10-20 07:31:35 -06:00
Andrey Turkin 1921c6814b Initial RISC-V implementation
Has no IRQ handling yet
2024-10-20 16:24:21 +03:00
Andrey Turkin db32f5f7a3 Move some conditionally compiled code from common files into arch-gated files 2024-10-19 21:59:14 +03:00
Andrey Turkin 55041e2eeb Use a custom config flag to conditionally compile DTB-specific areas
Would be great if we could use a feature instead, but Cargo can't do target-specific defaults features
2024-10-19 21:03:43 +03:00
Andrey Turkin 0a6a90415a Refactor initial memory paging 2024-10-19 08:44:46 +03:00
James 3fbd52a212 Made a change in context to the way arrays are resized. Slight change to the logic but resize_with should be slightly more efficient 2024-10-15 21:24:32 +11:00
Ron Williams 865122e92f Fix serial console login 2024-10-10 18:45:14 +00:00
4lDO2 0965c1e22b Allow aarch64 test to fail. 2024-10-07 10:20:51 +02:00
4lDO2 8d4ee26ff1 Fix profiling && + toggle support via debug scheme. 2024-10-07 10:20:51 +02:00
Dmitry Mottl dc1ba28f91 Updates .helix config to the new file format 2024-10-01 14:36:11 +00:00
4lDO2 ad16b747ea Restrict auto-fcntl to non-v2 schemes. 2024-09-27 21:36:22 +02:00
IncompententPirate fc5d246b30 remove wrapper functions 2024-09-26 22:34:55 +00:00
Andrey Turkin 14eb140f7a Refactor panic stack walking 2024-09-26 19:22:21 +03:00
Andrey Turkin 755694494b Factor KernelMapper out of arch
Same implementation on all the platforms. Also remove mutable Deref as it allowed circumventing RO check
2024-09-25 21:51:39 +03:00
4lDO2 539dc5a24e Remove SYS_UMASK. 2024-09-25 19:55:39 +02:00
Andrey Turkin d08861e586 Upgrade fdt library to the very latest
The new helpers remove a lot of boilerplace. Unfortunately some rough edges still remain (in particular issue gh#12 which renders interrupts() helper useless)
2024-09-25 06:51:02 +03:00
4lDO2 32e114885b Update RMM. 2024-09-24 19:33:27 +02:00
4lDO2 0a3ce63d40 Update syscall 2024-09-24 19:18:23 +02:00
4lDO2 71538efc06 Allow thread exit to optionally deallocate stack. 2024-09-24 19:18:23 +02:00
4lDO2 9a0192fc94 Prevent duplicate idempotent signals. 2024-09-24 19:18:23 +02:00
4lDO2 fcb2e2be3a Pass si_uid and si_pid to kill signals. 2024-09-24 19:18:23 +02:00
4lDO2 7def7ce6e3 Extend size of sig{en,de}queue payload. 2024-09-24 19:18:22 +02:00
4lDO2 54b1fbe453 Implement queued signals.
This currently needs to be done in the kernel for synchronization
reasons, but it's possible all delivery parts can later be moved to
userspace.
2024-09-24 19:18:22 +02:00
4lDO2 6d9cf30445 WIP: realtime signals 2024-09-24 19:18:20 +02:00
Andrey Turkin dbbbfcf48a Update RMM 2024-09-24 19:23:08 +03:00
Jeremy Soller edb3a87578 Merge branch 'riscv' into 'master'
Fixes and changes to make RISC-V paging work

See merge request redox-os/rmm!14
2024-09-24 12:51:39 +00:00
Andrey Turkin ed8bcfca1f Add write combining page flags where applicable 2024-09-24 08:26:02 +03:00
Andrey Turkin 192dd8283f RISC-V: implement TLB flush 2024-09-24 08:26:01 +03:00
Andrey Turkin f51cd00f00 Remove read/write flags from common PDE flags.
RISC-V convention marks PDE with no read/write/execute, so we can't have none of this flags set there. Remove their setting from PDE handling code and instead set them as appropriate in arch-specific defaults.

Also enable both readonly and readwrite flags to be non-zero (as long as their intersection completely masks both of them), as required for RISC-V PTE handling.
2024-09-24 08:24:18 +03:00
Andrey Turkin a96ea6f5f3 Allow physical address bits be anywhere in PTE entry
Before this commit, RMM assumed base physical address was presented in PTE as is, i.e. physical page address was shifted exactly to PAGE_SHIFT, so physical address can be extracted from PTE by simply masking off some bits and can be placed in PTE by simple addition/OR.

This is not the case for RISC-V which has 4Kb base page so 12 bits PAGE_SHIFT, yet physical page address is only shifted 10 bits in PTE.

This commit removes this assumption.

 NOTE: This commit changes meaning of constants:
 * ENTRY_ADDRESS_SIZE from "total physical size in bytes" to "total physical size in PAGES"
 * ENTRY_ADDRESS_MASK from "mask of physical bits in PTE" to "mask of physical bits starting at bit 0"
2024-09-23 08:47:27 +03:00
Andrey Turkin b7d3acf606 Separate leaf page and directory pages USER flag
This is required for RISC-V. Privileged spec says:

> For non-leaf PTEs, the D, A, and U bits are reserved for future standard use.
> Until their use is defined by a standard extension, they must be cleared by software
> for forward compatibility.

QEMU fails address translation if it sees any of these flags set on non-leaf page entry.
2024-09-23 08:47:23 +03:00
4lDO2 b485b1b3ea Update RMM. 2024-09-22 15:22:01 +02:00
Jeremy Soller bb27f57228 Merge branch 'fix_bump' into 'master'
Fix bump allocator initialization

See merge request redox-os/rmm!13
2024-09-22 13:20:33 +00:00
4lDO2 d95ea6598f Fix bump allocator. 2024-09-22 10:27:06 +02:00
4lDO2 960e79b107 Treat broken pipes as IO-capable in fevent. 2024-09-19 10:41:40 +02:00
4lDO2 ce9f699f8f Add unit tests to CI. 2024-09-17 23:10:36 +02:00
4lDO2 d498eefb2f Disable userspace feature in redox-syscall.
This prevents the kernel from being able to accidentally call itself
using the syscall instruction.
2024-09-17 19:24:26 +02:00
4lDO2 ef499f81fc Support compiling for host, allowing unit tests. 2024-09-17 19:24:23 +02:00
4lDO2 a0d0eac8aa Optimally divide responsibility for borrow free.
This appears to slightly improve performance.
2024-09-14 10:49:40 +02:00
4lDO2 031fdea089 Discard empty names in root scheme getdents. 2024-09-13 15:26:24 +02:00
4lDO2 97ea7ea6ec Disable syscall debug 2024-09-12 10:29:11 +02:00
4lDO2 e3e05ebca8 Fix root scheme order by using indexmap (tmp). 2024-09-11 22:09:29 +02:00
4lDO2 97f60de4ef WIP: Add getdents opaque_id 2024-09-11 22:09:29 +02:00
4lDO2 339271b4d7 Add getdents syscall, and switch schemes to it. 2024-09-11 22:09:26 +02:00
Kamil Koczurek 548fd63264 tsc: calculate elapsed ticks using saturating_sub
RDTSC readouts might not actually be monotonically increasing due to
desynchronization between CPU cores, so checked_sub was causing a kernel
panic.
2024-09-10 14:16:38 +02:00
4lDO2 652cdc7ef2 Replace repr(packed) with repr(C, packed). 2024-09-08 20:56:50 +02:00
4lDO2 5f9a587968 Convert repr(packed) to repr(C, packed). 2024-09-08 20:48:05 +02:00
4lDO2 815ac3da4a Revert "Fix possible UB in rmm::init."
This reverts commit 4626c74b78.
2024-09-08 20:22:46 +02:00
4lDO2 9673fa26b6 Expand Cargo features to separate lines.
This is much more diff- and by extension rebase-friendly.
2024-09-08 00:09:49 +02:00
4lDO2 4626c74b78 Fix possible UB in rmm::init.
I tested compiling the kernel with a more recent rustc, and this
triggered UB. Don't know for sure why there was an invalid entry passed
to the kernel, but it did.
2024-09-07 23:14:55 +02:00
Jeremy Soller 0c99e1bd0a Set xcr0 in all cases 2024-09-06 20:08:40 -06:00
Jeremy Soller 1c00450127 Use 64-bit versions of xsave and xrstor 2024-09-04 21:22:10 -06:00
4lDO2 09e7e66e00 Move scheme borrow unmap to cqe write. 2024-09-04 19:23:21 +02:00
4lDO2 181df19b24 Update rmm 2024-09-04 19:23:19 +02:00
Andrey Turkin a558860e88 Fix BSS sanity check
mark the canaries mutable so they go into data and bss and not in rodata
2024-09-04 10:55:20 +03:00
Andrey Turkin 7a9a5f024f Validate bootstrap memory allocation 2024-09-04 10:55:16 +03:00
Andrey Turkin ba154c0387 Fix a debug-build assertion
A range of usable memory could be small enough not to have any MAX_ORDER sized frames.
2024-09-04 10:55:11 +03:00
Andrey Turkin d2ebc7ff05 Wholesale fix of warnings
Pretty straightforward changes. This commit tries to avoid making any non-trivial fixes.
2024-09-04 10:55:01 +03:00
Jacob Lorentzon 643d7400db Implement paravirtualized KVM TSC support 2024-09-03 21:20:06 +00:00
bjorn3 d43eb74da3 Use softfloat abi in the target spec for aarch64
This allows removing the -Csoft-float argument when building.
2024-09-03 14:30:11 +00:00
Jeremy Soller ea4cfb2cbf Merge branch 'fix' into 'master'
Revived tests

See merge request redox-os/rmm!12
2024-09-02 21:16:38 +00:00
4lDO2 441385ddb2 Always map the kernel itself using global pages.
This avoids TLB stalls after context switching, that are very visible
from flamegraphs.
2024-08-31 10:44:54 +02:00
Ron Williams 19cd3ad287 Fix APIC reference in profiling.rs 2024-08-26 21:06:47 -07:00
Ron Williams 12eca4a0f5 Comment out error message for old scheme path 2024-08-26 11:51:01 -07:00
Ron Williams 47799a896d Don't warn about path for COSMIC apps 2024-08-24 11:49:49 -07:00
bjorn3 0876bed222 Remove a couple of exceptions from the deprecated scheme syntax warning 2024-08-19 19:13:42 +02:00
bjorn3 d4b979fb21 Log a deprecation message for usage of the legacy scheme syntax 2024-08-18 22:05:51 +02:00
Jeremy Soller 5cb6af6b8c Fix aarch64 build 2024-08-01 13:00:59 -06:00
bjorn3 f55da93b33 Fix building for AArch64
I broke this in !321
2024-08-01 20:45:59 +02:00
bjorn3 8f186a692f Allow writing messages to debug: without preserving them in sys:log
This would allow logd to write all received log messages to debug:
without causing an infinite loop when it at the same time reads all
messages in sys:log.
2024-07-25 12:49:43 +02:00
4lDO2 4158d899b5 Probably fix TLB shootdown "diagonal" livelock.
Diagonal as in

Thread A        Thread B
Send to B       Send to A
Wait for B      Wait for A.

I haven't reproduced this bug, but this should fix it, since the wait
steps now checks the local percpu block for pending TLB shootdowns onto
itself.
2024-07-24 22:48:56 +02:00
4lDO2 49b94047a8 Fix significant memory leak. 2024-07-24 22:48:56 +02:00
bjorn3 e7a46c3422 Let userspace control when graphical_debug gets disabled
Rather than disabling it right before entering userspace. This allows
showing debug messages while the graphics subsystem hasn't initialized
yet.
2024-07-24 20:59:40 +02:00
bjorn3 34cab9edba Fix typos and call graphical_debug::init_heap on arm64 2024-07-24 18:48:27 +02:00
bjorn3 98c28a3d60 Store a raw pointer in Display for the framebuffer 2024-07-24 17:45:31 +02:00
bjorn3 befd5175bb Limit visibilities 2024-07-24 17:10:35 +02:00
bjorn3 ebc4aeac85 Enable graphical_debug for aarch64
This doesn't give any issues both for UEFI boot (with framebuffer
present) and U-Boot boot (without framebuffer present).
2024-07-24 17:03:29 +02:00
bjorn3 e0855d0cb6 Fix typo 2024-07-22 16:47:35 +02:00
bjorn3 d3ccba0943 Avoid int2ptr cast in DebugDisplay 2024-07-22 14:26:44 +02:00
bjorn3 a89f93ff00 Move all drawing code from Display to DebugDisplay 2024-07-22 14:22:15 +02:00
bjorn3 dc36d18812 Remove unnecessary discard of return value in debug::Writer 2024-07-22 14:15:20 +02:00
4lDO2 51c4be10e0 Allow waitpid to be interrupted. 2024-07-20 23:17:31 +02:00
4lDO2 005635083d Fix thread cleanup during active file ops.
This fixes a bug where the window of `viewer` does not exit, due to a
leaked file descriptor.
2024-07-20 22:14:54 +02:00
4lDO2 29170ccbc7 Fix sigchld test. 2024-07-18 19:38:47 +02:00
4lDO2 05bde858f9 Fix SIGCONT deadlock. 2024-07-18 16:47:16 +02:00
4lDO2 daa11c911f Fix syscall debug, more success in sigchld test. 2024-07-18 16:14:07 +02:00
4lDO2 c54195f10d Ensure process signals can also interrupt. 2024-07-17 17:31:05 +02:00
4lDO2 2d50055dfb WIP: support thread/process-specific kill. 2024-07-17 15:29:05 +02:00
4lDO2 3c540efb00 Support sending signals to individual threads. 2024-07-16 22:06:21 +02:00
4lDO2 8de850e7e9 Ensure all threads stop in exit(). 2024-07-16 20:33:37 +02:00
4lDO2 79bbf79656 Fix some proc scheme FIXMEs. 2024-07-16 20:28:17 +02:00
4lDO2 cc465c008b Remove rustc hack. 2024-07-16 19:52:18 +02:00
4lDO2 bda12fe55e Print MXCSR in the SIMD exception handler. 2024-07-16 13:14:42 +02:00
4lDO2 cde108439c Fix kill deadlock. 2024-07-16 13:05:42 +02:00
4lDO2 6bd01513c5 Simplify and improve thread/process cleanup. 2024-07-15 18:08:43 +02:00
4lDO2 a3dedb0639 Do proper resource cleanup for thread exit too. 2024-07-15 18:08:43 +02:00
4lDO2 8259ed281c Boot to desktop with process/context changes. 2024-07-15 18:08:43 +02:00
4lDO2 40f5c01586 Flatten syscall match statement. 2024-07-15 18:08:43 +02:00
4lDO2 e67c040f69 WIP: Separate process status from context status. 2024-07-15 18:08:43 +02:00
4lDO2 7fbe5c72e9 Use strong references in context set. 2024-07-15 18:08:42 +02:00
4lDO2 80fe891c6e WIP: Replace ContextId with direct Arcs. 2024-07-15 18:08:42 +02:00
4lDO2 038ff03996 Fix waitpid and improve debug. 2024-07-15 18:08:42 +02:00
4lDO2 0de23a1141 Use correct context for proc scheme 'new-thread'. 2024-07-15 18:08:42 +02:00
4lDO2 4202bc3ba0 WIP: add new-thread 2024-07-15 18:08:42 +02:00
4lDO2 208d74899a Fix fork & process creation, now boots to desktop. 2024-07-15 18:08:42 +02:00
4lDO2 25974bec6e It compiles. 2024-07-15 18:08:42 +02:00
4lDO2 de1bd46c84 Make proc scheme almost compile. 2024-07-15 18:08:42 +02:00
4lDO2 89d532a267 Fix half of proc scheme errors. 2024-07-15 18:08:42 +02:00
4lDO2 89d1d49a4e Fix most code except proc scheme. 2024-07-15 18:08:41 +02:00
4lDO2 8f452b0b0f WIP: continue the process transition 2024-07-15 18:08:41 +02:00
4lDO2 0da2fce64a Separate context and process IDs. 2024-07-15 18:08:41 +02:00
4lDO2 74b824f40f Add rustfmt to CI. 2024-07-15 17:54:27 +02:00
4lDO2 d94baa2712 Run rustfmt. 2024-07-15 17:50:18 +02:00
4lDO2 f3532f4549 Fix static mut ref warnings. 2024-07-15 17:48:46 +02:00
4lDO2 5e7db80285 Fix a bunch of warnings. 2024-07-15 17:48:45 +02:00
4lDO2 c86f107344 Switch back to upstream syscall submodule. 2024-07-15 17:20:58 +02:00
4lDO2 9259a36f5e Run more of sigchld test correctly. 2024-07-15 17:20:58 +02:00
4lDO2 5abbcd8e34 Send SIGCHLD to parent after child stop/exit. 2024-07-15 17:20:57 +02:00
4lDO2 d70ad544e6 Fix SIGKILL and allow SYS_EXIT to pass 16 bits. 2024-07-15 17:20:57 +02:00
4lDO2 8f3e40a99e Fix aarch64 compilation. 2024-07-15 17:20:57 +02:00
4lDO2 465128da26 Don't block nanosleep/futex <= signals are pending. 2024-07-15 17:20:57 +02:00
4lDO2 9198ee7e52 Reimplement shutdown and restart. 2024-07-15 17:20:57 +02:00
4lDO2 4dba818c83 Check pending unblocked signals before blocking.
This is not a perfect solution, since the kernel technically already has
all the information it needs to synchronize this between the kill()
invocation and the time WaitCondition::wait is called, but it should not
have any noticeable performance impact.
2024-07-15 17:20:57 +02:00
4lDO2 e9de24c097 Only return EINTR in kill() if self was killed. 2024-07-15 17:20:57 +02:00
4lDO2 965f5879b7 Never clear sig pending bits in the kernel. 2024-07-15 17:20:57 +02:00
4lDO2 ae8e13525f Remove is_pending flag, read word directly instead. 2024-07-15 17:20:57 +02:00
4lDO2 f91b90445d Force userspace to do post-syscall EINTR check. 2024-07-15 17:20:56 +02:00
4lDO2 e8060b259d Only save ip and 'archdep' regs when signalling. 2024-07-15 17:20:56 +02:00
4lDO2 12cfcfc6f2 TMP: change syscall gitmodule to fork 2024-07-15 17:20:56 +02:00
4lDO2 93a3401df4 Fix bug causing raise() to not deliver any signals. 2024-07-15 17:20:56 +02:00
4lDO2 13720f59d5 Make signals masked when clear rather than set. 2024-07-15 17:20:56 +02:00
4lDO2 87046b77c7 Compile on aarch64. 2024-07-15 17:20:56 +02:00
4lDO2 c1ce1d76f9 Compile on i686. 2024-07-15 17:20:56 +02:00
4lDO2 5b25e2cda7 Fix excp_handler deadlock. 2024-07-15 17:20:56 +02:00
4lDO2 b94904a660 Use correct addrsp when setting sighandler. 2024-07-15 17:20:56 +02:00
4lDO2 cc406804c0 Don't double-clear is_pending flag. 2024-07-15 17:20:55 +02:00
4lDO2 35aa24800b Implement correct context sig unblocking behavior. 2024-07-15 17:20:55 +02:00
4lDO2 93f0573b5d Use improved signal control struct defs. 2024-07-15 17:20:55 +02:00
4lDO2 d6e0eef065 Implement signal delivery code (untested). 2024-07-15 17:20:55 +02:00
4lDO2 9b68d4de80 Fix add_ref(Shared) refcounting bug. 2024-07-15 17:20:55 +02:00
4lDO2 7d5b2e6c21 Prevent infinite userspace crash loops. 2024-07-15 17:20:55 +02:00
4lDO2 55fe58adf6 WIP: implement kill syscall prototype 2024-07-15 17:20:55 +02:00
4lDO2 639ba74a7e Fix kernel compilation. 2024-07-15 17:20:55 +02:00
4lDO2 295cc820e6 WIP: userspace signal handling 2024-07-15 17:20:55 +02:00
Andrey Turkin 198151a355 Make sure aarch64 kernel doesn't use any FP registers 2024-07-13 12:06:50 +00:00
Andrey Turkin 9c639af217 Fix debug assertion bug 2024-07-12 23:15:33 +03:00
Andrey Turkin 7c0995ee24 Revived tests
Also fixed debug build failure on i686, and reformatted the code
2024-07-12 21:10:37 +03:00
Andrey Turkin 2663873d45 Fix Dtb scheme reads 2024-07-09 09:52:16 +03:00
4lDO2 a80dc4dc9c Try fixing CI. 2024-06-25 12:58:53 +02:00
4lDO2 c73e2ffecf Add Makefile.
This will both improve CI, and decouple the kernel build script from
cookbook.
2024-06-25 12:46:02 +02:00
Jeremy Soller 15c7e10d52 Implement kreadoff for dtb scheme 2024-06-24 11:57:20 -06:00
4lDO2 d4997150d8 Temporarily suppress some cases of EINVAL for unknown SKMSGs. 2024-06-15 15:12:04 +02:00
4lDO2 6aa5ed020e Add missing fevent impl for RootScheme. 2024-06-15 12:29:05 +02:00
4lDO2 10714a4659 Make explicit flags optional for SYS_{READ,WRITE}2. 2024-06-14 13:58:10 +02:00
4lDO2 dd8661bcb3 Add debug print for SYS_READ2/SYS_WRITE2. 2024-06-14 13:57:56 +02:00
Jacob Lorentzon bf0fc66ac1 Improved scheme protocol. 2024-06-14 11:31:51 +00:00
4lDO2 e9ba024aaa Remove redundant .cargo/config
All options are already set by ../recipe.toml, and removing this file
will make Cargo stop complaining about missing -Zbuild-std when for
example compiling RMM for the host arch.
2024-06-10 11:52:59 +02:00
Jeremy Soller 81e6fc70d2 Enable use of MmapMode::Cow 2024-06-05 12:56:29 -06:00
Jeremy Soller 593959a7c3 Allow fp-armv8 in order to compile for aarch64 on new nightly 2024-05-11 14:45:44 -06:00
Jeremy Soller c9698b5d2d Update to new nightly 2024-05-11 14:13:41 -06:00
Jeremy Soller e7d00a8e05 Add driver for arm,gic-v3 2024-05-08 11:24:46 -06:00
Jeremy Soller 9e3688b507 Revert "Support arm,gic-v3"
This reverts commit e33015a5f8.
2024-05-07 15:24:50 -06:00
Jeremy Soller e33015a5f8 Support arm,gic-v3 2024-05-07 15:20:34 -06:00
4lDO2 7f409d46bf Fix futex wakeup when CoW has occurred. 2024-04-28 15:17:32 +02:00
Jeremy Soller 3ad6427e28 Disable AP if it has the same ID as BSP 2024-04-13 10:01:36 -06:00
Jeremy Soller 5b5b2dbc97 Debug messages during device init 2024-04-13 09:34:00 -06:00
4lDO2 0060dd326b Update rmm 2024-04-12 16:25:58 +02:00
4lDO2 99fcfc5fae Skip insufficiently large bump alloc regions. 2024-04-11 22:02:44 +02:00
4lDO2 161a92c9c2 Forbid strong fdtbl refs after setting context's.
This fixes a possible file table leak if a filetable contains an fd
referring (strongly) to the filetable itself. Now, it will automatically
be downgraded to a weak reference after it becomes a context's active
file table.

TODO: maybe support consuming a context's filetable to get a strong
reference back, provided it's exclusively owned.
2024-04-10 21:49:43 +02:00
Jeremy Soller e4246d6704 Re-enable sys:log 2024-04-10 10:38:46 -06:00
4lDO2 3fc9103826 Fix altreloc remap, always NOP-fill padding bytes.
This fixes a very rare (requires that an altreloc span two pages) kernel
crash where it writes past the region that was remapped as RWX, thus
triggering an in-kernel "wrote without write access" page fault.

Additionally, this fixes the logic for unavailable features. It fixes
the short-circuit that would forget to remap the memory back from RWX to
R-X. NOP bytes are also now replaced with multi-byte NOP regardless of
whether the CPU supports the given feature.
2024-04-10 16:16:37 +02:00
Jacob Lorentzon cd3f937861 Make futex timeout absolute, and properly return ETIMEDOUT 2024-04-05 20:31:03 +00:00
4lDO2 fbaa93e8fa Fix profiling stack trace bp bounds checking. 2024-04-04 15:45:47 +02:00
4lDO2 68e072aac9 Return correct fevent flags in PipeScheme.
This fixes a Cargo deadlock.
2024-04-02 15:04:39 +02:00
4lDO2 ed075474b0 Fix syscall_debug feature. 2024-03-31 14:40:57 +02:00
4lDO2 2f1551a6bb Mark allocated p2frame used *before* freelist unlock. 2024-03-26 17:07:37 +01:00
Jeremy Soller 168692f09d x86: use initial_top for tss stack 2024-03-25 14:15:43 -06:00
4lDO2 c17279f5bf Allocate kernel stacks using the frame allocator. 2024-03-25 16:31:16 +01:00
4lDO2 9253e16240 Fix kernel stack sizes, other arches. 2024-03-25 16:29:07 +01:00
4lDO2 b5523df187 Only support power-of-two frame allocations. 2024-03-24 14:40:15 +01:00
4lDO2 b2d52d6736 Implement allocator free/used bookkeeping. 2024-03-24 14:27:25 +01:00
4lDO2 12282439b6 Reduce dead code, fix aarch64. 2024-03-23 23:51:12 +01:00
4lDO2 e6dc0e96f0 Fix aarch64. 2024-03-23 19:16:53 +01:00
4lDO2 7261dccb72 Fix i686. 2024-03-23 16:54:47 +01:00
4lDO2 1b3e024f7d Fix profiling code. 2024-03-23 15:52:18 +01:00
4lDO2 299a829ff3 Remove debug code. 2024-03-22 17:21:17 +01:00
4lDO2 676368f5d2 Fix booting to desktop. 2024-03-22 16:35:29 +01:00
4lDO2 c0f3b6ccca Fix refcount assert 2024-03-22 13:32:14 +01:00
4lDO2 660acb4d94 Improve debugging 2024-03-22 13:32:14 +01:00
4lDO2 343f89f240 Fix unaligned section end append_pages. 2024-03-22 13:32:14 +01:00
4lDO2 baf46a3555 Far more progress 2024-03-22 13:32:13 +01:00
4lDO2 f4d270c7ce Ensure freelist does not contain used pages. 2024-03-22 13:31:24 +01:00
4lDO2 a847e4745c More progress 2024-03-22 13:31:24 +01:00
4lDO2 d2dc3302a7 Remove RefCount::Zero.
Only the allocator is allowed to switch between 0 and 1. Refcounts above
1 are however controlled by the virtual memory system.
2024-03-22 13:31:22 +01:00
4lDO2 3a8821e73b Hopefully fix most UB 2024-03-22 13:28:21 +01:00
4lDO2 08784e7166 More progress 2024-03-22 13:27:50 +01:00
4lDO2 c349e4cd83 Fix allocate_frames_complex 2024-03-22 13:26:03 +01:00
4lDO2 4fccc4b87b Some of userspace now boots! 2024-03-22 13:26:03 +01:00
4lDO2 bb01f0af66 More allocation progress 2024-03-22 13:26:03 +01:00
4lDO2 cfe153eb85 Fix section creation. 2024-03-22 13:25:57 +01:00
4lDO2 fe7244a8cd Ensure both set_next and set_prev are called. 2024-03-22 13:25:08 +01:00
4lDO2 2ba9ff720c Doubly-linked list. 2024-03-22 13:25:07 +01:00
4lDO2 0e8c187a50 WIP: Implement more of deallocate_p2frame. 2024-03-22 13:21:52 +01:00
4lDO2 fc19d63af9 Store aligned addrs rather than PFNs in Frame. 2024-03-22 13:19:19 +01:00
4lDO2 fd86bb4860 Try to naturally align sections. 2024-03-22 13:18:07 +01:00
4lDO2 d5b1ad2cd5 WIP: Improve allocation performance 2024-03-22 13:17:59 +01:00
Jeremy Soller 8f09b4aa06 Do not use HPET on i686 2024-03-19 20:44:47 -06:00
4lDO2 66eb3361d3 Use saved regs instead of costly context.syscall. 2024-03-19 11:33:55 +01:00
4lDO2 4862977fa5 Optimize syscall fast path without tracing. 2024-03-18 20:38:11 +01:00
4lDO2 33f0fa8709 Fix IOBITMAP_SIZE type. 2024-03-18 14:34:32 +01:00
4lDO2 ff0bd96abd Improve readability 2024-03-18 14:26:00 +01:00
4lDO2 f7900df0e2 Update syscall 2024-03-18 10:27:51 +01:00
4lDO2 d62aada7ad Replace iopl with either empty or full PIO bitmap. 2024-03-18 10:27:51 +01:00
bjorn3 de137fe58d Fix acpi::init call for i686 2024-03-17 19:34:14 +01:00
bjorn3 e1f4bf4356 Misc arm device tree fixes 2024-03-17 19:28:58 +01:00
4lDO2 c583745ede Update syscall 2024-03-16 17:49:32 +01:00
4lDO2 4a3dc2dadd Fix the SIGKILL fd leak bug. 2024-03-16 17:49:32 +01:00
4lDO2 8e19da338b Fix kstop and kreset. 2024-03-16 17:49:31 +01:00
4lDO2 b97e733d94 Boot to desktop on aarch64. 2024-03-16 17:49:31 +01:00
4lDO2 57c3119a83 Fix i686 triple fault by always initializing int stack. 2024-03-16 17:49:31 +01:00
4lDO2 7d8ee58df3 Fix aarch64 link step. 2024-03-16 17:49:31 +01:00
4lDO2 5ff26ca967 Remove paste dependency completely. 2024-03-16 17:49:31 +01:00
4lDO2 5ecba176f4 Compile on aarch64. 2024-03-16 17:49:31 +01:00
4lDO2 776a140212 Fix rax being overwritten, and compile on i686. 2024-03-16 17:49:31 +01:00
4lDO2 239bd317e9 Fix signal ordering wrt syscall return. 2024-03-16 17:49:31 +01:00
4lDO2 13bc46a30b WIP: Implement scheme call cancelation. 2024-03-16 17:49:31 +01:00
4lDO2 e57573c428 Ensure signals can't start new contexts too early. 2024-03-16 17:49:30 +01:00
4lDO2 e012d6cfca Fix altstack calculation typo. 2024-03-16 17:49:30 +01:00
4lDO2 c7da5a438c Replace incorrect interrupt IA32-isms.
The code incorrectly documents and states that SS and RSP are
conditionally pushed, based on whether the privilege level changed. This
is correct on IA-32, but wrong on x86-64.
2024-03-16 17:49:30 +01:00
4lDO2 6d1e436d29 Remove some dead code. 2024-03-16 17:49:30 +01:00
4lDO2 0cf2ce632a Only call sig handler in switch, not after EINTR. 2024-03-16 17:49:30 +01:00
4lDO2 6bf8238fb1 Unset procmask for kmain. 2024-03-16 17:49:30 +01:00
4lDO2 5ac0be7ec1 Start with full procmask, fix signal delivery. 2024-03-16 17:49:30 +01:00
4lDO2 5336cbd9e5 Improve signal interfaces and implementation. 2024-03-16 17:49:30 +01:00
4lDO2 10256b331c Ensure only the kernel can return EINTR. 2024-03-16 17:49:26 +01:00
bjorn3 04f689cee7 Accept a single RSDP from the bootloader 2024-03-15 11:43:27 +01:00
bjorn3 08bb2537b5 Remove the deprecated bootstrap_entry field from KernelArgs 2024-03-15 10:59:58 +01:00
bjorn3 502016815d Avoid unaligned access in the XsdtIter
The pointers in the XSDT table are only 4 byte aligned.
2024-03-15 10:53:45 +01:00
bjorn3 d5e1188b8e Remove doc feature 2024-03-15 09:55:27 +01:00
bjorn3 672e36f401 Force the zero page of the kernel to be part of a segment
This will be necessary for limine and likely multiboot support. See the
comment in the linker scripts.
2024-03-14 21:22:13 +01:00
bjorn3 b5f94a5a2e Fix bug in the unmapping code
Previously trying to funmap an address after the start of the grant
would result in an overflow only caught when compiling the kernel with
debug assertions enabled.
2024-03-14 12:15:43 +01:00
bjorn3 e81113349c Fix get_page_info for frames in the last memory section 2024-03-13 19:41:24 +01:00
bjorn3 ecbc2b7e8d Directly read the bootstrap entry point from the initfs header 2024-03-11 14:26:08 +01:00
bjorn3 fb66a8628f Use PAGE_SIZE instead of hard coded constant 2024-03-10 21:39:55 +01:00
bjorn3 616c7d4398 Load the bootstrap blob at 4096 instead of 0
This way the NULL page can stay unmapped and the bootstrap code can
avoid UB when reading the initfs header (which is at the start of the
bootstrap code.
2024-03-10 21:14:46 +01:00
4lDO2 ec58d6c541 Compile on aarch64 as well. 2024-03-05 10:40:54 +01:00
4lDO2 d38d8b66bd Fix i686 compilation. 2024-03-05 10:26:57 +01:00
4lDO2 b35c9d1e62 Properly free phys-contiguous grants, TLB-delayed. 2024-03-04 19:03:01 +01:00
4lDO2 4e392d05e4 Delay cow() dealloc until after TLB shootdown. 2024-03-04 19:03:01 +01:00
4lDO2 fa3e2a24d4 Optimize TLB flushing. 2024-03-04 19:03:01 +01:00
4lDO2 716f147cd4 Fix synchronization so acid tlb succeeds! 2024-03-04 19:03:01 +01:00
4lDO2 846d914a55 Improve synchronization. 2024-03-04 19:03:01 +01:00
4lDO2 1f8d7bc67c Always check shootdown reqs when locking addrsp. 2024-03-04 19:03:01 +01:00
4lDO2 3a592b9079 Use regular non-NMI IPIs for TLB shootdown. 2024-03-04 19:03:00 +01:00
4lDO2 3a915c7fd5 Fix lock/guard mismatch, move r#move to wrapper. 2024-03-04 19:03:00 +01:00
4lDO2 b5efaceb51 Fix more synchronization. 2024-03-04 19:03:00 +01:00
4lDO2 098cdd6067 Fix flusher, currently only with -smp 1 2024-03-04 19:03:00 +01:00
4lDO2 79381249a2 Implement a TLB shootdown draft. 2024-03-04 19:03:00 +01:00
4lDO2 6bf90f9eee Build the foundation for TLB shootdown. 2024-03-04 19:03:00 +01:00
4lDO2 156017a25d Refactor: wrap RwLock<AddrSpace>. 2024-03-04 19:03:00 +01:00
4lDO2 749df4c869 Fail successfully with todo! 2024-03-04 19:03:00 +01:00
4lDO2 bb30530ea0 Track which CPUs are using any given AddrSpace. 2024-03-04 19:03:00 +01:00
4lDO2 0c6c857012 Improve LogicalCpu{Id,Set}, make set atomic.
Technically there should be an atomic and nonatomic set type, but perf
should be the same, as the nonatomic one would only be used when setting
the sched_affinity.
2024-03-04 19:02:56 +01:00
Jeremy Soller 15cbb40802 Format 2024-02-28 12:10:17 -07:00
Jeremy Soller 8390277eb2 Fix affinity alignment 2024-02-28 12:10:06 -07:00
bjorn3 e08eadf64a Don't pass CallerCtx in file_op_generic
It isn't used by any of the callers.
2024-02-25 21:05:21 +01:00
bjorn3 24187b5f80 Move set_tss_stack call to switch_to 2024-02-25 20:10:49 +01:00
bjorn3 96f1a14115 Remove some dead code 2024-02-25 20:06:22 +01:00
bjorn3 52f4aaf741 Avoid unaligned access for serial over x86 io port 2024-02-25 18:36:41 +01:00
bjorn3 782ec87f27 Fix UB in the locking code of context switching
The spin crate considers it UB to call force_write_unlock while there is
a threads trying to obtain a read lock on the same rwlock.

This also switches to the spinning_lot crate for the context rwlock as
it has support for a write guard keeping a reference to the rwlock using
an Arc instead of a reference.
2024-02-25 17:07:41 +01:00
bjorn3 449abb8925 Share bootstrap_mem between all archs 2024-02-25 15:53:04 +01:00
bjorn3 e23f0ed66b Share idt.rs between x86 and x86_64 2024-02-25 15:49:29 +01:00
bjorn3 f92b4c9608 Unify cpuid between x86 and x86_64 and don't return an Option
Systems without cpuid support aren't supported anyway.
2024-02-25 15:07:31 +01:00
bjorn3 eecfbb19d2 Share the functions in interrupt/mod.rs between x86 and x86_64 2024-02-25 14:48:28 +01:00
bjorn3 fbe2980b3d Share interrupt/ipi.rs between x86 and x86_64 2024-02-25 14:48:15 +01:00
bjorn3 62614db9ac Share interrupt/trace.rs between x86 and x86_64 2024-02-25 14:48:12 +01:00
bjorn3 c1d0c11a1b Fix typo in irq.rs 2024-02-25 14:31:52 +01:00
bjorn3 3610dd7e03 Remove unused interrupt handler 2024-02-25 14:31:28 +01:00
bjorn3 e9e3b4487d Reduce the difference of idt.rs between x86 and x86_64 2024-02-25 14:31:28 +01:00
Jeremy Soller 39c20720ee Fix compilation on x86_64 2024-02-16 22:05:57 -07:00
Jeremy Soller e4eb4031bd Fix APIC offsets for x86 32-bit 2024-02-16 22:02:47 -07:00
Jeremy Soller 6c6fc18f8e Format 2024-02-16 21:40:42 -07:00
Jeremy Soller 86589aa7fa Only switch to idle process when no other processes can run 2024-02-13 14:46:21 -07:00
Jeremy Soller 98f12fd750 Hack to workaround hangs by pinning to one cpu 2024-02-10 09:18:57 -07:00
Ron Williams 9331452bdb Use RedoxPath::as_parts. redox-path from crates.io 2024-02-09 15:05:45 +00:00
Ron Williams eeee40ae0c update unlink for new path format 2024-02-01 00:50:33 -08:00
Ivan Tan e7d47d10c6 aarch64: fix compile error 2024-01-27 23:29:37 +08:00
bjorn3 58314e6a47 Share a whole lot more code between x86 and x86_64 2024-01-25 13:34:04 +00:00
bjorn3 785975089b Dedup the last remaining piece of code in the driver module between x86 and x86_64 2024-01-25 13:34:04 +00:00
bjorn3 0d86348e41 Dedup the apic code between x86 and x86_64 2024-01-25 13:34:04 +00:00
bjorn3 86fb4208f2 Dedup some more code between x86 and x86_64 2024-01-25 13:34:04 +00:00
bjorn3 0d092d7921 Dedup code for most x86 and x86_64 device drivers 2024-01-25 13:34:04 +00:00
bjorn3 9404e9f892 Mark the sections used by alternative!() as allocated
This prevents the linker from discarding any function which uses the
alternative!() macro which would result in runtime relocation crashing.
2024-01-25 11:51:34 +01:00
bjorn3 5e71f6f9df Correctly mark unaligned write as such to avoid UB 2024-01-24 19:43:34 +01:00
bjorn3 fa58f5887e The kernel now works fine without optimizations
It is relatively slow without optimizations, but it is still usable.
2024-01-24 14:15:09 +01:00
bjorn3 3085b31336 Ensure __altrelocs_start is correctly aligned 2024-01-24 14:13:27 +01:00
bjorn3 732fad0593 Fix disabling the self_modifying feature 2024-01-24 14:13:18 +01:00
bjorn3 e5c93ae334 Fix some UB and debug assertions
The UB has been found by rustc's new UB checks with debug assertions
enabled.
2024-01-24 13:51:20 +01:00
Jeremy Soller 87ee68998c Handle new path format 2024-01-18 12:35:32 -07:00
Jeremy Soller 0e58953259 Update redox-path 2024-01-18 11:22:23 -07:00
Jeremy Soller 0fde840f83 Add redox-path submodule 2024-01-18 11:15:04 -07:00
Jeremy Soller 45f1c4e29e Add rustfmt from relibc and apply it with cargo fmt 2024-01-17 13:52:01 -07:00
Jeremy Soller 73897bd83d scheme/pipe: allow removing fevent 2024-01-08 16:59:48 -07:00
Jeremy Soller d18c316012 Add session ID 2024-01-08 14:43:11 -07:00
4lDO2 5e75df56c5 More BumpAllocator APIs. 2023-12-18 11:16:15 +01:00
4lDO2 ed455915ca Allow arbitrary bump allocation size. 2023-12-18 11:16:11 +01:00
4lDO2 529c491fa0 Allow disabling profiling at compile time. 2023-12-17 00:49:28 +01:00
4lDO2 fac0e783ef Refactor profiling code. 2023-12-17 00:49:28 +01:00
4lDO2 99ad6a0a2c Support toggling profiling. 2023-12-17 00:49:28 +01:00
4lDO2 0f27d55c0a Advance profiling buffer correctly. 2023-12-17 00:49:28 +01:00
4lDO2 14abf0cbc6 Exclude kmain from profile. 2023-12-17 00:49:27 +01:00
4lDO2 f973bc4128 Profiling 2023-12-17 00:49:24 +01:00
Jeremy Soller a285863335 Update syscall 2023-12-16 11:12:21 -07:00
Jeremy Soller 364896c6e7 Update syscall 2023-12-16 11:10:28 -07:00
4lDO2 dae3726057 Update syscall 2023-12-15 15:14:40 +01:00
4lDO2 ee3aafa1d9 Remove PhysBorrowed hacks. 2023-12-15 15:14:40 +01:00
4lDO2 52df9dd1bc Remove the AddrSpace ref when exiting, not reaping. 2023-12-15 15:14:40 +01:00
4lDO2 d4a120188f Ensure PhysBorrowed iff !alloc-owned, vice versa.
This is allowed now that the old physalloc/physfree syscalls have been
removed.
2023-12-15 15:14:40 +01:00
4lDO2 eda462fd11 Remove SYS_PHYSMAP. 2023-12-15 15:14:40 +01:00
4lDO2 875a130843 Remove SYS_PHYSALLOC* and SYS_PHYSFREE. 2023-12-15 15:14:40 +01:00
4lDO2 a42e406569 Fix contiguous mmap. 2023-12-15 15:14:40 +01:00
4lDO2 cd19831ffb Improved options for memory: files. 2023-12-15 15:14:40 +01:00
4lDO2 77400f63ee Add a memory: file for phys-contiguous mmaps. 2023-12-15 15:14:36 +01:00
Ivan Tan ebf96fa843 aarch64: fix dtb scheme 2023-12-14 03:34:37 +00:00
Jeremy Soller 1cc5804333 Allow CPUs to take any context 2023-12-13 17:20:43 -07:00
Jeremy Soller 4386e0716d Missed change for last commit 2023-12-13 17:20:21 -07:00
Jeremy Soller fbaa4306e3 Add unblock_no_ipi function and use in context switch 2023-12-13 17:19:43 -07:00
bjorn3 2d065083df Use HashMap instead of BTreeMap where possible
This shrinks the kernel from 905840 bytes to 862408 bytes.
2023-12-13 19:55:20 +01:00
4lDO2 78beae5c92 Fix aarch64 2023-12-13 11:08:12 +01:00
4lDO2 d531c6f1bf Context switch correctly in UserInner::call. 2023-12-13 11:08:12 +01:00
4lDO2 6b642d62a6 Disable trigger_debugger again. 2023-12-13 11:08:12 +01:00
4lDO2 88508a2cb7 Remove as_user_inner. 2023-12-13 11:08:12 +01:00
4lDO2 3a35338aa7 Remove as_{filetable,sigaction,addrspace}. 2023-12-13 11:08:12 +01:00
4lDO2 f3ce5b167d Make proc: and thisproc: global. 2023-12-13 11:08:11 +01:00
4lDO2 3be015ce4d Make sys: global. 2023-12-13 11:08:11 +01:00
4lDO2 fe0e3103f4 Make itimer: global. 2023-12-13 11:08:11 +01:00
4lDO2 87b0c568a0 Make time: global. 2023-12-13 11:08:11 +01:00
4lDO2 f6002e839d Centralize global scheme constructors. 2023-12-13 11:08:11 +01:00
4lDO2 ce313ba28d Add global scheme IDs to map, for now. 2023-12-13 11:08:11 +01:00
4lDO2 d9c2443ae3 Make irq: a GlobalScheme. 2023-12-13 11:08:11 +01:00
4lDO2 10e86ea89d Hardcode global scheme IDs. 2023-12-13 11:08:11 +01:00
4lDO2 679c26c03b s/Arc<dyn KernelScheme>/enum, but deref as dyn. 2023-12-13 11:08:07 +01:00
Jeremy Soller d7d824552b Merge branch 'derive_hash_virtual_address' into 'master'
Derive Hash for VirtualAddress

See merge request redox-os/rmm!11
2023-12-13 00:10:02 +00:00
bjorn3 aad492f805 Derive Hash for VirtualAddress 2023-12-12 22:21:22 +01:00
bjorn3 a7165f822f Switch from the memoffset crate to the offset_of feature
The memoffset crate requires const_refs_to_cell to work in const
contexts. This feature has some known issues around it's semantics. The
offset_of feature however is currently on track for stabilization.
2023-12-12 20:21:31 +00:00
bjorn3 2aea52a94b Remove the sole usage of the const_option feature 2023-12-12 20:21:31 +00:00
bjorn3 82a87be7d5 Avoid usage of the unstable Allocator trait
And also optimize init_sections to use the fact that allocate_frames
returns zeroed frames.
2023-12-12 20:21:31 +00:00
bjorn3 5bce3a5bb5 Move -z max-page-size from the target spec to the cookbook 2023-12-12 18:15:05 +01:00
bjorn3 3188a44b23 Don't use target_family="redox" for the kernel
This cfg is meant for redox userspace programs.
2023-12-12 18:14:18 +01:00
bjorn3 2e689eb5d4 Remove unnecessary no_mangle and extern "C" from the panic handler
#[panic_handler] handles all linkage related details.
2023-12-12 15:01:29 +00:00
bjorn3 c99e582c86 Use the default panicking alloc error handler 2023-12-12 15:01:29 +00:00
bjorn3 6b1c154847 Use kernel_executable_offsets on AArch64 and x86 2023-12-12 15:01:29 +00:00
bjorn3 017702d3d2 Remove a lot of dead code 2023-12-12 15:01:29 +00:00
bjorn3 00d0b8fb6b Remove all pub from main.rs
This will cause rustc to emit warnings for all unused items.
2023-12-12 15:01:29 +00:00
bjorn3 5ce7d1df8a Remove unnecessary extern crate item
This was only necessary in the 2015 edition
2023-12-12 15:01:29 +00:00
bjorn3 6045b0cc59 Remove unused feature gates 2023-12-12 15:01:29 +00:00
Jeremy Soller 4e3103a48a x86: fix enter/exit gs and usercopy asm 2023-12-11 15:25:54 -07:00
Ivan Tan 1f1a57e1f7 support userspace program ioremapping device memory 2023-12-11 16:07:53 +00:00
Ivan Tan 9b6197d686 aarch64: code clean up 2023-12-11 16:07:53 +00:00
Ivan Tan a8329956ca support raspi3b+ serial && uart interrupt 2023-12-11 16:07:53 +00:00
Ivan Tan 44b14f994a fix qemu-arm64 run error 2023-12-11 16:07:53 +00:00
Ivan Tan 1c1c541f0e bringup raspi3b+, add device memory, disable uart init 2023-12-11 16:07:53 +00:00
Ivan Tan bfbf435546 draft: aarch64: add irq_bcm2835. Need refactoring 2023-12-11 16:07:53 +00:00
Ivan Tan 9a5b9798ca remove qemu-aarch64-virt hard code 2023-12-11 16:07:53 +00:00
Ivan Tan ed68c98b42 aarch64: add irq-bcm2836 for raspi3b+ && refactor irq module 2023-12-11 16:07:53 +00:00
Ivan Tan b65a7e9103 move gic into irqchip module 2023-12-11 16:07:53 +00:00
Ivan Tan 01d0e9a4b5 aarch64: add irqchip module to initialize all irq chip. 2023-12-11 16:07:53 +00:00
Ivan Tan 78a8568932 update dtb syscall scheme to kernelscheme 2023-12-11 16:07:53 +00:00
Ribbon 4f98319a92 Improve the README and fix the docs badge link 2023-12-07 15:32:45 +00:00
Ron Williams 02087065c1 don't panic when adding an existing name to a namespace 2023-11-15 22:18:50 +00:00
4lDO2 036a4bdee4 Replace syscall::Scheme with KernelScheme. 2023-11-15 20:00:47 +01:00
4lDO2 192d663d84 Forbid / in scheme names. 2023-11-09 14:40:20 +01:00
Ron Williams 29803e7865 setrens: always ignore -1 2023-11-08 23:29:08 -08:00
4lDO2 431dba9563 Update syscall 2023-10-19 17:07:17 +02:00
4lDO2 2d04b76a2c Close sendfd file descriptor unless consumed. 2023-10-14 15:38:21 +02:00
4lDO2 2f2e76c0ca Inform SYS_SENDFD scheme if the fd was exclusive. 2023-10-14 14:56:40 +02:00
4lDO2 1546a4a08f Implement SYS_SENDFD and SKMSG_FOBTAINFD. 2023-10-14 12:44:38 +02:00
4lDO2 da491fd5fc Disable sys:trigger_debugger by default. 2023-10-08 11:21:59 +02:00
4lDO2 6f6f69c728 Fix test instruction reg length in paranoid swapgs. 2023-10-08 11:21:23 +02:00
bjorn3 d819277d56 Make rustc directly invoke the linker 2023-10-03 09:53:37 +02:00
bjorn3 b9299224ea Move debuginfo option to Cargo.toml 2023-10-03 09:39:14 +02:00
Enver Balalic 750e566a27 Get aarch64 to compile
Fixes enough errors to get the kernel to compile
2023-10-01 23:55:24 +02:00
4lDO2 c481f6b5d4 Track state for all UserScheme calls. 2023-09-30 12:53:37 +02:00
Jeremy Soller e794f2fe9b Fix panic when there is no xsave support 2023-09-18 15:01:39 -06:00
Ivan Tan eb0d48ac81 aarch64: add dtb scheme 2023-09-18 20:45:23 +00:00
Ivan Tan a76cbc9f31 aarch64: trap msr, mrs or system instruction 2023-09-18 20:45:23 +00:00
4lDO2 5eace9997a Compile successfully on i686 as well. 2023-09-16 10:48:25 +02:00
4lDO2 0b9c5bbf49 Pass both original and padded length in altrelocs. 2023-09-16 10:33:09 +02:00
4lDO2 ed3d2d7832 Allow disabling overwrite-based optimizations. 2023-09-14 16:44:12 +02:00
4lDO2 ce0d474cb9 Fail if a feature is force-enabled but unsupported. 2023-09-14 16:28:14 +02:00
4lDO2 dfc372d241 Replace with rdgsbase dynamically in paranoid ISRs. 2023-09-14 14:43:46 +02:00
4lDO2 d90aeef62e Fix nop-filling code. 2023-09-14 14:34:04 +02:00
4lDO2 dde8f78903 Support XSAVE, XSAVEOPT, and AVX2. 2023-09-14 10:54:30 +02:00
4lDO2 38e669c807 Dynamic fsgsbase support, enable by default. 2023-09-14 09:25:30 +02:00
4lDO2 f581c71c7c Allow code-overwriting optimizations, use for smap. 2023-09-14 08:38:49 +02:00
4lDO2 dd30ae109a Ensure altcode/data/features sections are kept. 2023-09-14 08:38:08 +02:00
4lDO2 e005619b78 Add alternative! macro. 2023-09-12 21:43:37 +02:00
4lDO2 f028b77412 Use config.toml instead of x86_* Cargo feature. 2023-09-12 21:19:06 +02:00
4lDO2 c210e59a75 Add a config.toml to the kernel. 2023-09-12 21:13:58 +02:00
4lDO2 9fd2488d64 Use a compact push+jump table for IRQs. 2023-09-10 21:42:02 +02:00
Jeremy Soller 5c4961d139 Update Cargo.lock 2023-09-09 12:31:14 -06:00
Jeremy Soller 4cd76ea9e3 arch/x86: sync LogicalCpuId changes 2023-09-09 12:31:04 -06:00
Jeremy Soller a4d0960b3f Update redox syscall 2023-09-08 11:16:53 -06:00
4lDO2 6d65a93606 Remove live scheme. 2023-09-08 01:57:34 +00:00
Jeremy Soller 40a3601ca5 Update syscall 2023-09-07 16:17:57 -06:00
4lDO2 eeb0d8c1e6 Unify Interrupt{,Error}Stack. 2023-09-06 22:45:29 +02:00
4lDO2 c4a5abb34a Remove AtomicSchemeId. 2023-09-06 09:22:59 +02:00
4lDO2 126c7b7d8a Pass scheme ID to UserInner cleaner. 2023-09-06 09:21:53 +02:00
4lDO2 0d4f3125cd Use Once<SchemeId> for debug:, simplify other Once. 2023-09-06 08:58:59 +02:00
4lDO2 27d350955a Replace atomic with Once<SchemeId> for irq: 2023-09-06 08:49:37 +02:00
4lDO2 2862f7abb5 Once<SchemeId> for serio, simplify queue globals. 2023-09-06 08:48:22 +02:00
4lDO2 16cb32b178 Make WaitQueue::new() const fn. 2023-09-06 08:47:52 +02:00
4lDO2 68b03d69c0 Downgrade int_like const fn default to trait. 2023-09-06 08:46:58 +02:00
4lDO2 f025ece614 Replace from/into with get/new when necessary. 2023-09-06 08:38:10 +02:00
4lDO2 9d742387ac Replace int_like from/into with get/new, impl From. 2023-09-06 08:37:13 +02:00
4lDO2 45d1c256ea Add LogicalCpuSet as a sched affinity mask. 2023-09-04 21:57:54 +02:00
4lDO2 3b725b2c27 Add logical CPU ID newtype, switch to u32. 2023-09-04 21:27:48 +02:00
4lDO2 45e1eb7ba4 Set IA32_TSC_AUX if present. 2023-09-04 21:07:30 +02:00
4lDO2 303c96494c Improve sysretq checks. 2023-09-03 15:50:28 +02:00
4lDO2 ad02f5cbba Remove SYS_PIPE2. 2023-09-01 17:17:15 +02:00
Jeremy Soller da6e9fd8d1 Merge branch 'ivan/raspi3b' into 'master'
aarch64: init serial port by parsing dtb file

See merge request redox-os/kernel!241
2023-08-12 13:40:24 +00:00
Ivan Tan ca6699a11e aarch64: init serial port by parsing dtb file 2023-08-12 12:45:50 +08:00
Jeremy Soller 4d7d86d47c Merge branch 'mvk2' into 'master'
Set relocation-model=static

Closes #107

See merge request redox-os/kernel!240
2023-08-12 00:57:46 +00:00
4lDO2 cbd02a8489 Set relocation-model=static 2023-08-12 00:57:45 +00:00
Jeremy Soller 652aa4f1ac Merge branch 'no_more_tls' into 'master'
Replace #[thread_local]

See merge request redox-os/kernel!239
2023-08-09 14:18:16 +00:00
4lDO2 de23cd447e Fix aarch64 build. 2023-08-08 12:01:43 +02:00
4lDO2 28d4e60beb Set relocation-model=static for i686. 2023-08-08 12:01:43 +02:00
4lDO2 0dd464d428 Unset TLS model on i686. 2023-08-08 12:01:42 +02:00
4lDO2 ca92eda5e6 Remove TLS on aarch64 too. 2023-08-08 12:01:42 +02:00
4lDO2 ed2febb289 Disable thread-local storage entirely. 2023-08-08 12:01:42 +02:00
4lDO2 a78d6e42f8 Stop using #[thread_local] on x86_*. 2023-08-08 12:01:42 +02:00
4lDO2 bdd5c954dc Move PIT_TICKS to context::switch. 2023-08-08 12:01:42 +02:00
4lDO2 0c90802ae0 Fix RaiiFrame deallocation. 2023-08-08 11:57:57 +02:00
Jeremy Soller 5cabe38a78 Merge branch 'mmu' into 'master'
Demand paging

See merge request redox-os/kernel!238
2023-08-07 15:36:58 +00:00
4lDO2 4688090dea Fix RaiiFrame typo. 2023-08-03 16:46:42 +02:00
4lDO2 8f98d5b987 Extend mremap, eager mappings for real hardware. 2023-08-03 12:37:58 +02:00
4lDO2 8af63e3aae Update syscall 2023-08-03 11:50:02 +02:00
4lDO2 c7714992f3 Fix clone_grant_using_fmap test. 2023-08-02 14:17:26 +02:00
4lDO2 2070fa44b7 Fix warnings. 2023-08-02 13:07:49 +02:00
4lDO2 05a9530ac7 Temporarily disable CoW fmaps. 2023-08-01 17:29:36 +02:00
4lDO2 ef879b35ba Update RMM. 2023-08-01 15:52:34 +02:00
Jeremy Soller a992ae89ed Merge branch 'mmu' into 'master'
Demand paging related improvements

See merge request redox-os/rmm!10
2023-08-01 13:51:37 +00:00
4lDO2 34708bd1be Temporarily disable MAP_LAZY. 2023-08-01 15:44:41 +02:00
4lDO2 fe88b23d09 Use a single cow zeroed page for RO maps + eager mapping. 2023-08-01 13:11:00 +02:00
4lDO2 1e670645e4 Bypass kernel heap for storing PageInfo.
Since these are stored in arrays that are typically 512 KiB each
(i.e. which in turn typically store metadata for 128 MiB), they will
certainly be a page-size multiple, and large contiguous allocations are
allowed at least at boot time. Not only is the linked-list allocator
less efficient for that, but this change will also help reduce TLB
overhead.
2023-08-01 11:22:42 +02:00
4lDO2 8a8c04685e Merge adjacent frame sections. 2023-08-01 10:55:01 +02:00
4lDO2 0cdfb886c0 Fix debugger for x86_64, disable sc debug. 2023-07-28 13:40:00 +02:00
4lDO2 86aba2dbe5 Better VirtualAddress Debug impl. 2023-07-28 13:39:32 +02:00
4lDO2 b5937b7b91 Set aarch64 "not global" flag by default. 2023-07-28 13:38:39 +02:00
4lDO2 e28fef09e3 Improve aarch64 debugger. 2023-07-28 13:23:44 +02:00
4lDO2 d16569110e Don't mess up x18 in aarch64 exc handler. 2023-07-28 12:56:55 +02:00
4lDO2 ce35deed4b Support aarch64 page consistency checking. 2023-07-28 12:38:25 +02:00
4lDO2 f454df38eb Fix get_page_info. 2023-07-28 10:47:18 +02:00
4lDO2 ec9c24f841 WIP: aarch64 2023-07-27 19:05:33 +02:00
4lDO2 8b7fc8a468 Compile and mostly run properly on i686. 2023-07-27 16:45:36 +02:00
4lDO2 f4bdb5388e Remove AtomicU64 requirement for starting APs. 2023-07-27 16:44:52 +02:00
4lDO2 885f88b777 Fix futex for non-AtomicU64-capable targets. 2023-07-27 16:44:26 +02:00
4lDO2 25d26b3b93 Arch-independent x86-modeled page fault handler. 2023-07-27 15:56:45 +02:00
4lDO2 7a3b453fbb Declare __usercopy_{start,end} as functions. 2023-07-27 15:34:33 +02:00
4lDO2 4d2cd6ce0f Remove redundant log msg. 2023-07-27 15:25:51 +02:00
4lDO2 a4a84775d6 Fix MMAP_PREP order. 2023-07-26 22:31:56 +02:00
4lDO2 d6e1732d44 Stop using feature(arbitrary_self_types). 2023-07-25 11:22:36 +02:00
4lDO2 3cfec39b47 Pass MunmapFlags to scheme. 2023-07-25 10:52:24 +02:00
4lDO2 c9aa5ca851 WIP: Add SYS_MREMAP. 2023-07-25 10:52:24 +02:00
4lDO2 2660c3e07a WIP: Pin fmap grants that are borrowed too.
This might not be the most ideal solution, since a GiB grant can be
EBUSY blocked if a single page is used by an indefinitely-blocking
UserScheme. But, the alternatives would impose lots of additional
complexity, such as increasing the PageInfo size, adding more
refcounting arrays to grants, etc.
2023-07-25 10:52:24 +02:00
4lDO2 e054a5b211 Add debugger checks for correct CoW page flags. 2023-07-25 10:52:24 +02:00
4lDO2 37579601b2 Remove one level of indirection in get_page_info. 2023-07-25 10:52:24 +02:00
4lDO2 e2b736140f Make PageInfo atomic once again. 2023-07-25 10:52:24 +02:00
4lDO2 d58ddc35fe Complete PageInfo cleanup.
This enables proper CoW ^ shared enforcement, so that e.g. acquiring a
new CoW page from already shared memory, or vice versa, will enforce
that they aren't both simultaneously.
2023-07-25 10:52:23 +02:00
4lDO2 0f1b5b9b6f WIP: Make cow/shared refcounts mutually exclusive. 2023-07-25 10:52:23 +02:00
4lDO2 113cb5ed4e Ensure pages cannot be both CoW and shared. 2023-07-25 10:52:23 +02:00
4lDO2 d3ecedefd9 Notify schemes when mmaps are unmapped. 2023-07-25 10:52:23 +02:00
4lDO2 02f04752e8 Use proper locks for PageInfo. 2023-07-25 10:52:23 +02:00
4lDO2 7bdf5e9af3 Pass unaligned length to scheme for fmap. 2023-07-25 10:52:23 +02:00
4lDO2 afa3d7dc7b Support anonymous MAP_SHARED mmaps. 2023-07-25 10:52:23 +02:00
4lDO2 70b4d99c96 Implement MAP_FIXED without MAP_FIXED_NOREPLACE. 2023-07-25 10:52:23 +02:00
4lDO2 f0341280f7 Fix frame deallocation. 2023-07-25 10:52:23 +02:00
4lDO2 3a80528d13 Fix MAP_LAZY mappings. 2023-07-25 10:52:23 +02:00
4lDO2 cbec83215a Lazy-evaluate pages returned by fmap. 2023-07-25 10:52:22 +02:00
4lDO2 9182722f84 WIP: Allow listing address space grants again. 2023-07-25 10:52:22 +02:00
4lDO2 0466e87e59 Error if scheme fmap returns unaligned address. 2023-07-25 10:52:22 +02:00
4lDO2 ba62c0606e Pin PhysBorrowed head/tail UserScheme grants too. 2023-07-25 10:52:22 +02:00
4lDO2 329d60848c WIP: Support CoW fmap. 2023-07-25 10:52:22 +02:00
4lDO2 b24cf821c2 Support transferring grants again. 2023-07-25 10:52:22 +02:00
4lDO2 55f1829e77 Call funmap if applicable. 2023-07-25 10:52:22 +02:00
4lDO2 4ec8712fb0 Adjust fmap offsets in Grant::extract. 2023-07-25 10:52:22 +02:00
4lDO2 c5eb44d968 Increase refcount for borrowed fmap too. 2023-07-25 10:52:22 +02:00
4lDO2 b3a6a6744a Pin grants that are used in UserScheme. 2023-07-25 10:52:22 +02:00
4lDO2 954a8d00fe Make page fault handler recursive.
This is probably a bad idea, but it works for now, and can only cause
problems, if grants that borrow grants that borrow grants etc., are
used.
2023-07-25 10:52:21 +02:00
4lDO2 da6f6a316c Return only one grant, External, for Grant::borrow. 2023-07-25 10:52:21 +02:00
4lDO2 b5430359d8 Forbid scheme calls with non-RAM physmapped memory. 2023-07-25 10:52:21 +02:00
4lDO2 43c433a3f0 Remove FmapCtxt. 2023-07-25 10:52:21 +02:00
4lDO2 bf6ad5c41a Disable debugging again. 2023-07-25 10:52:21 +02:00
4lDO2 8553bc7a59 WIP: Support userspace-backed borrowing mmaps. 2023-07-25 10:52:21 +02:00
4lDO2 024f3e3828 Fix deadlock, booting to shell works now. 2023-07-25 10:52:21 +02:00
4lDO2 ad78dcc5a1 WIP: Rudimentary MAP_SHARED fmap implementation. 2023-07-25 10:52:21 +02:00
4lDO2 afa61601c4 Add ContextStatus::HardBlocked. 2023-07-25 10:52:21 +02:00
4lDO2 23fede5db0 Remove scheme funmap methods. 2023-07-25 10:52:20 +02:00
4lDO2 0c365f54e6 WIP: FmapBorrowed. 2023-07-25 10:52:20 +02:00
4lDO2 20c3adf38d WIP: Start rewriting fmap impl. 2023-07-25 10:52:20 +02:00
4lDO2 99975c0e42 WIP: Ensure that Grant::borrow does not borrow nonpresent grants. 2023-07-25 10:52:20 +02:00
4lDO2 dffc8ec9fc Do not expect PageInfo for PhysMap grants. 2023-07-25 10:52:20 +02:00
4lDO2 20a84decdf Fix MemoryScheme fmap. 2023-07-25 10:52:20 +02:00
4lDO2 15ce84164b Reminder that borrow does handle "lack of grant". 2023-07-25 10:52:20 +02:00
4lDO2 50e2f51ab3 Remove outdated #[must_use]. 2023-07-25 10:52:20 +02:00
4lDO2 f7bffacef0 Implement Drop for AddrSpace. 2023-07-25 10:52:20 +02:00
4lDO2 829d2276fb Remove Context::vfork.
Since clone is no longer exists as a syscall, it makes little sense to
manage vfork in the kernel. Implementing vfork in userspace would still
be possible.
2023-07-25 10:52:20 +02:00
4lDO2 e34a3cee42 Fix mmap/munmap, invert borrowed/owned refcount. 2023-07-25 10:52:19 +02:00
4lDO2 45ec3ecc70 Track Allocated and CoW External the same way. 2023-07-25 10:52:19 +02:00
4lDO2 7aca53753e Call init_mm from correct function. 2023-07-25 10:52:19 +02:00
4lDO2 a599d9b389 WIP: Store PageInfo in separate data structure. 2023-07-25 10:52:19 +02:00
4lDO2 760fc2ba5a WIP: Global page info structs. 2023-07-25 10:52:19 +02:00
4lDO2 593e21d95e Support schemes. 2023-07-25 10:52:19 +02:00
4lDO2 f53a1ffd53 Remove proc:pid/memory. 2023-07-25 10:52:19 +02:00
4lDO2 0a5b6ce656 Reach proc:memory access in userspace. 2023-07-25 10:52:19 +02:00
4lDO2 11fdb3bb46 Copy on writes to CoW pages. 2023-07-25 10:52:19 +02:00
4lDO2 565db7694f Add cow_refcount. 2023-07-25 10:52:19 +02:00
4lDO2 276f051d19 Further userspace progress, fix RMM bug. 2023-07-25 10:52:18 +02:00
4lDO2 8cfbc39b9f Get further in userspace. 2023-07-25 10:52:18 +02:00
4lDO2 490e1b2777 WIP: Track grant ownership. 2023-07-25 10:52:18 +02:00
4lDO2 e7d94ddff5 WIP: Lazy zeroed mapping and page fault handler. 2023-07-25 10:52:18 +02:00
4lDO2 8dfa73db35 Post-refactor fixes. 2023-07-25 10:52:18 +02:00
4lDO2 34b4512dbd Refactor Grants.
Page alignment is now verified at compile time, for example.
2023-07-25 10:52:13 +02:00
4lDO2 d4b5899c53 Remove allocator_owned hack. 2023-07-25 10:49:55 +02:00
Jeremy Soller 5cc05a281e Merge branch 'less_unstable_use' into 'master'
Reduce usage of unstable features

See merge request redox-os/kernel!230
2023-07-24 19:18:53 +00:00
Jeremy Soller c61fd1837a Merge branch 'fix_mmap' into 'master'
Fix fmap typo and remove warning.

See merge request redox-os/kernel!237
2023-07-18 18:04:42 +00:00
4lDO2 c130b18ee7 Fix fmap typo and remove warning. 2023-07-18 16:54:44 +02:00
Jeremy Soller 16912bca82 Merge branch 'replace_physmap' into 'master'
Alternative physmap via memory:physical@<mem type>.

See merge request redox-os/kernel!236
2023-07-17 16:48:32 +00:00
4lDO2 8e22e69c94 Add remap_with{,_full}. 2023-07-17 13:31:51 +02:00
4lDO2 0aa7fea250 Fix remap bug: require present before remapping. 2023-07-17 13:31:46 +02:00
Jeremy Soller eaab222011 Merge branch 'fix_is_global' into 'master'
Fix is_global.

See merge request redox-os/rmm!9
2023-07-16 16:36:55 +00:00
4lDO2 339984e49b Fix is_global. 2023-07-16 18:32:34 +02:00
4lDO2 37eb577ada Support physmap via memory:physical@<mem type>. 2023-07-15 00:28:56 +02:00
Jeremy Soller 5a9a38a948 Merge branch 'fix' into 'master'
Set space in copy_and_capture_tail.

See merge request redox-os/kernel!235
2023-07-14 13:30:42 +00:00
4lDO2 797c81eb3b Set space in copy_and_capture_tail. 2023-07-14 12:51:26 +02:00
bjorn3 e73e42be66 Replace intrinsics::abort() call in switch_finish_hook with safer abort mechanism
abort will still run the illegal instruction interrupt handler which may
not be safe.
2023-07-10 17:03:36 +02:00
bjorn3 7500ffaa5a Remove uses of the arbitrary_self_types feature 2023-07-10 17:03:36 +02:00
bjorn3 174e38a851 Remove all uses of concat_idents!() 2023-07-10 17:03:34 +02:00
bjorn3 437b70838f Replace uses of atomic_* intrinsics with Atomic* types 2023-07-10 17:02:01 +02:00
bjorn3 0d01f7be57 Use core::ptr wrappers instead of the unstable volatile_* intrinsics 2023-07-10 17:02:01 +02:00
bjorn3 6803c2c33c Remove a couple of unused feature gates 2023-07-10 17:02:01 +02:00
Jeremy Soller c1b28af544 Merge branch 'fix_debug_scheme' into 'master'
Fix debug: scheme.

See merge request redox-os/kernel!233
2023-07-10 14:29:52 +00:00
4lDO2 f700958642 Fix debug: scheme. 2023-07-10 16:26:52 +02:00
Jeremy Soller 4d6b4c24a9 Merge branch 'better_percpu' into 'master'
Simplify x86_64 percpu and GSBASE calculation

See merge request redox-os/kernel!222
2023-07-10 14:13:12 +00:00
4lDO2 3ded84c945 Simplify x86_64 percpu and GSBASE calculation 2023-07-10 14:13:12 +00:00
Jeremy Soller 5c99d73bbe Merge branch 'no_static_mut_thread_local' into 'master'
Avoid static mut thread locals

See merge request redox-os/kernel!228
2023-07-10 14:03:41 +00:00
Jeremy Soller 6440f2dcbc Merge branch 'fix_live' into 'master'
Fix live scheme

See merge request redox-os/kernel!232
2023-07-07 13:34:10 +00:00
4lDO2 9e6dfc82d0 Fix live scheme. 2023-07-07 15:00:46 +02:00
Jeremy Soller 6fca481a0a Merge branch 'mm' into 'master'
Usercopy migration

Closes #82 and #115

See merge request redox-os/kernel!219
2023-07-06 13:03:21 +00:00
4lDO2 56f88e80c2 Usercopy migration 2023-07-06 13:03:21 +00:00
Jeremy Soller b1d0851a7b Merge branch 'sys_scheme_remove_indirection' into 'master'
Replace Box<dyn Fn> with fn in sys: scheme.

See merge request redox-os/kernel!231
2023-07-06 12:56:13 +00:00
4lDO2 fa7d1c821f Replace Box<dyn Fn> with fn in sys: scheme. 2023-07-05 17:08:00 +02:00
bjorn3 56b16ce897 Avoid static mut thread locals
Instead use UnsafeCell inside the thread locals.
2023-07-05 14:50:17 +02:00
Jeremy Soller 846aa32f21 Merge branch 'panic_abort' into 'master'
Build the kernel with panic=abort

See merge request redox-os/kernel!229
2023-07-04 18:00:53 +00:00
Jeremy Soller 74e74ce633 Merge branch 'no_idtr_thread_local' into 'master'
Move IDTR thread local to a stack variable

See merge request redox-os/kernel!227
2023-07-04 17:30:43 +00:00
bjorn3 8c0be73224 Build the kernel with panic=abort
This reduces the kernel size and avoids the need to define the
eh_personality lang item.
2023-07-04 19:14:36 +02:00
bjorn3 13733fb943 Move IDTR thread local to a stack variable 2023-07-04 12:17:52 +02:00
Jeremy Soller acefb8888e Merge branch 'pipe_scheme' into 'master'
Improved pipe scheme.

Closes #84

See merge request redox-os/kernel!226
2023-06-27 13:35:14 +00:00
4lDO2 5abf16a51e Improved pipe scheme. 2023-06-26 13:54:13 +02:00
Jeremy Soller 7269f9c6f1 Merge branch 'fix_df' into 'master'
Always clear DF when entering the kernel

See merge request redox-os/kernel!223
2023-06-18 12:54:19 +00:00
4lDO2 416269eeaf Always clear DF when entering the kernel. 2023-06-18 14:47:00 +02:00
Jeremy Soller 78a8173f62 Merge branch 'aarch64-stuff' into 'master'
More aarch64 stuff

See merge request redox-os/kernel!221
2023-06-13 13:49:25 +00:00
uuuvn a5d4ccba57 More aarch64 stuff 2023-06-13 10:15:47 +00:00
Jeremy Soller 2849510892 Copy HPET divide by zero workaround to x86 arch 2023-06-12 09:19:34 -06:00
Jeremy Soller 503a21d461 Merge branch 'aarch64-stuff' into 'master'
Improve aarch64 code + memory management and crush some bugs

See merge request redox-os/kernel!220
2023-06-12 15:17:51 +00:00
uuuvn 63290429b2 Improve aarch64 code + memory management and crush some bugs 2023-06-12 14:46:02 +00:00
Jeremy Soller e24e8485ba Merge branch 'aarch64-stuff' into 'master'
Add GLOBAL flag and prettify some stuff

See merge request redox-os/rmm!8
2023-06-12 12:12:09 +00:00
uuuvn d89e6008e8 Add GLOBAL flag and prettify some stuff 2023-06-12 10:23:40 +00:00
Jeremy Soller 0ae3958a8c Merge branch 'fix-lsp-helix' into 'master'
Fix LSP in helix

See merge request redox-os/kernel!218
2023-06-10 12:18:52 +00:00
uuuvn ffe9bb8593 Fix LSP in helix 2023-06-10 08:50:25 +00:00
Jeremy Soller 0deb0d79e1 Merge branch 'file_forwarding_v2' into 'master'
Allow schemes to return external file descriptors

See merge request redox-os/kernel!215
2023-06-08 12:02:35 +00:00
4lDO2 aa1420d599 Update syscall. 2023-06-08 11:11:20 +02:00
Jeremy Soller 37746c0743 Merge branch 'fix-aarch64' into 'master'
Fix aarch64

See merge request redox-os/kernel!217
2023-06-07 13:42:02 +00:00
uuuvn d502418e49 Fix aarch64 2023-06-06 15:36:30 +00:00
Jeremy Soller a9bdb51deb Merge branch 'master' into 'master'
Update README.md: add command to build docs

See merge request redox-os/kernel!216
2023-06-05 23:03:28 +00:00
Florian Meißner 33bdf8e5b6 Update README.md: add command to build docs 2023-06-05 19:14:42 +00:00
4lDO2 ce77703146 Move forwarded files rather than copying them. 2023-06-02 14:50:44 +02:00
4lDO2 b1d4f55e0a Use kopen and kdup in syscall handlers. 2023-06-02 14:50:44 +02:00
4lDO2 c7ba937bbf Support forwarding in UserScheme. 2023-06-02 14:50:40 +02:00
Jeremy Soller da5063375e Merge branch 'context_name' into 'master'
Remove one level of indirection for Context::name.

See merge request redox-os/kernel!214
2023-05-30 13:36:48 +00:00
4lDO2 58c0c5d040 Remove one level of indirection for Context::name. 2023-05-27 14:27:34 +02:00
Jeremy Soller 34894e3d73 Merge branch 'fix_aarch64' into 'master'
Fix unaligned_references error on aarch64

See merge request redox-os/kernel!213
2023-05-06 16:37:06 +00:00
4lDO2 a451c0aa1b Fix aarch64 build. 2023-05-06 17:49:39 +02:00
Jeremy Soller 89d560e6e5 Merge branch 'fix-sigreturn-dos' into 'master'
Fix kernel DoS via sigreturn from non-signal context

See merge request redox-os/kernel!211
2023-05-04 12:32:24 +00:00
uuuvn 4621cd674d Fix kernel DoS via sigreturn from non-signal context 2023-05-04 15:58:05 +04:00
Jeremy Soller 3a6732eaad Merge branch 'updated_rustc_and_futex_fixes' into 'master'
Fixes for futex and newer rustc

See merge request redox-os/kernel!209
2023-05-02 22:11:53 +00:00
Jeremy Soller 37ba7c63b4 Merge branch 'qemu_hpet_bug' into 'master'
Qemu hpet bug

See merge request redox-os/kernel!210
2023-05-02 16:19:01 +00:00
Andrew Mackenzie d3a2fe7083 Qemu hpet bug 2023-05-02 16:19:01 +00:00
4lDO2 50b877d1aa Remove ignored unaligned_references exception. 2023-04-30 18:13:55 +02:00
4lDO2 c604d6b051 Make IDT #[repr(C)]. 2023-04-30 18:13:27 +02:00
4lDO2 99ffc370e8 Work around repr(packed) but not fixing UB. 2023-04-30 18:11:34 +02:00
4lDO2 a5168b4442 Fix warnings. 2023-04-30 18:11:20 +02:00
4lDO2 45f031b50d Improve clone_entry lock granularity. 2023-04-30 17:54:05 +02:00
4lDO2 6c3f577f05 Also translate the 12-bit page offset in SYS_FUTEX. 2023-04-30 17:53:17 +02:00
4lDO2 62eab8a2fe Retry rather than panic if clone_entry is unset. 2023-04-09 12:04:08 +02:00
Jeremy Soller 4bf307d88e Merge branch 'fix_mem_fns' into 'master'
Fix memcpy, memmove, memset, and memcmp.

Closes #99

See merge request redox-os/kernel!208
2023-04-01 21:17:54 +00:00
4lDO2 78557eff18 Fix memcpy, memmove, memset, and memcmp. 2023-04-01 21:30:10 +02:00
Jeremy Soller 42de1f3e9c Merge branch 'master' into 'master'
Add QEMU tip.

See merge request redox-os/kernel!206
2023-03-14 15:25:59 +00:00
Jeremy Soller 295bcbdac8 Update redox_syscall 2023-03-14 09:25:17 -06:00
Ribbon 32300c2d9e Add QEMU tip. 2023-03-12 15:16:05 +00:00
Jeremy Soller 6fb14edcb0 Merge branch 'context-switch-optimization' into 'master'
Context switch optimization

See merge request redox-os/kernel!205
2023-03-09 21:33:27 +00:00
Jeremy Soller 12688a929e Context switch optimization
- Contexts for other CPUs will never be evaluated for switch
- Running contexts will never be evaluated for switch
- Arc::clone is only called for previous and next context when there is a context to switch to
- Lots of cleanup to the switch function
2023-03-09 14:30:12 -07:00
Jeremy Soller 3bf381caf8 Do not panic if ACPI is not available 2023-03-03 18:56:23 -07:00
Jeremy Soller 11e6dd7b24 Merge branch 'master' into 'master'
Improve text organization.

See merge request redox-os/kernel!202
2023-02-28 14:11:38 +00:00
Ribbon f1b45f658f Improve text organization. 2023-02-28 12:46:34 +00:00
Jeremy Soller 4b3337e479 Merge branch 'master' into 'master'
Kernel notes (moved from CONTRIBUTING).

See merge request redox-os/kernel!201
2023-02-28 12:27:09 +00:00
Ribbon 2c593fb0b9 Move from CONTRIBUTING to kernel README. 2023-02-28 08:10:33 +00:00
Jeremy Soller 12d5830097 Merge branch 'pin_kmain_contexts' into 'master'
Pin kmain contexts

Closes #111

See merge request redox-os/kernel!200
2023-02-27 16:22:46 +00:00
4lDO2 b73922bc95 Also fix outdated-#![feature(...)] warnings. 2023-02-24 23:16:57 +01:00
4lDO2 ac913e49f9 Pin kmain contexts to corresponding CPUs. 2023-02-24 23:05:11 +01:00
Jeremy Soller 87e1689b56 Merge branch 'sched_affinity' into 'master'
Support scheduler CPU affinity.

See merge request redox-os/kernel!199
2023-02-15 15:44:39 +00:00
4lDO2 8d14d54fa9 Support scheduler CPU affinity. 2023-02-15 14:50:01 +01:00
Jeremy Soller cb58500b68 Update for new Rust 2023-02-11 14:50:55 -07:00
Jeremy Soller 7aeb9f0ac8 Remove rust-toolchain 2023-02-11 14:50:26 -07:00
Jeremy Soller 55fd7dfff7 Add centiseconds to context time 2023-01-30 10:51:32 -07:00
Jeremy Soller e5c3be86cd Ensure unmounting is read from atomic in all cases 2023-01-12 07:33:54 -07:00
Jeremy Soller 85e0a7c368 Record mappings in funmap with page aligned size, always 2022-12-21 18:29:15 -07:00
Jeremy Soller 523d00eeac Make it possible to track syscall time when debugging 2022-12-19 10:11:59 -07:00
Jeremy Soller d298459686 Add sys:irq 2022-11-18 14:18:06 -07:00
Jeremy Soller 1e81c9d78b Fix compilation without ACPI feature 2022-11-16 13:53:04 -07:00
Jeremy Soller 111606ccdc Increase PIT divisor again to reduce wasted interrupt handling time 2022-11-15 11:50:23 -07:00
Jeremy Soller 33aa263deb Fixes for hpet counter read, choose better PIT divisor 2022-11-14 13:58:55 -07:00
Jeremy Soller 2052cc8cdc Allow arch to provide higher precision time 2022-11-14 11:12:44 -07:00
Jeremy Soller 31868077f0 Use u128 for time, store CPU time of processes 2022-11-14 10:10:17 -07:00
Jeremy Soller ee6c9f4020 Fix compilation on i686 2022-11-11 13:23:07 -07:00
Jeremy Soller 8e0f54cb31 Clippy fixes 2022-11-11 13:19:14 -07:00
Jeremy Soller 515a03b870 Fix warnings 2022-11-11 12:51:07 -07:00
Jeremy Soller 6bef3afee6 Support bootloader stride 2022-09-16 12:29:38 -06:00
Jeremy Soller 3bef7d7bad Simplify ps2 interrupts to reduce latency to reading bytes 2022-09-08 10:33:31 -06:00
Jeremy Soller f5bdae2d0c Reduce schreduler time slices to reduce latency 2022-09-07 18:21:30 -06:00
Jeremy Soller 07ed93225e 0.3.4: Update syscall to matching version 2022-08-31 16:15:25 -06:00
Jeremy Soller 6753251af3 Do not allow mmap with page_count 0 2022-08-31 16:14:27 -06:00
Jeremy Soller 21108d57fe Update syscall 2022-08-30 10:33:22 -06:00
Jeremy Soller 7fbe5112ca Allow physmap with unaligned size 2022-08-29 09:41:35 -06:00
Jeremy Soller 1b3c6a957d Add aarch64 debugger 2022-08-28 09:27:38 -06:00
Jeremy Soller 8d8437a5d3 Update rmm 2022-08-28 09:19:17 -06:00
Jeremy Soller 81b03cc693 Improve aarch64 tlb flushing 2022-08-28 09:19:07 -06:00
Jeremy Soller 91b5d64c22 Use current address space for proc kfmap workaround 2022-08-27 18:05:20 -06:00
Jeremy Soller 2278fd7fe1 Workaround to ensure proc kfmap does not try to map kernel memory 2022-08-27 10:55:52 -06:00
Jeremy Soller 1fadde3ee8 Eliminate deadlock in capture_inner 2022-08-27 07:48:47 -06:00
Jeremy Soller 6f6648c4d2 Disable HPET use on x86 2022-08-26 11:13:53 -06:00
Jeremy Soller 6dbb85d4c9 Static mapping of some CPU devices outside of physmap 2022-08-26 11:08:13 -06:00
Jeremy Soller 27bb8e44dd Do not allow phys_to_virt overflow 2022-08-26 11:07:21 -06:00
Jeremy Soller 002425d625 Fix trampoline on x86 2022-08-26 08:24:04 -06:00
Jeremy Soller 33b8fcecfb Sync x86_64 trampoline with bootloader 2022-08-26 08:08:24 -06:00
Jeremy Soller fb1bdf7c3e Ignore null bytes from pl011 uart 2022-08-25 20:10:35 -06:00
Jeremy Soller 6a3fc5a68a Send SIGSEGV on aarch64 exception 2022-08-25 20:00:53 -06:00
Jeremy Soller 80b8382cd7 Fix aarch64 kfx size 2022-08-25 18:40:19 -06:00
Jeremy Soller 82ac7a66f7 Only save preserved regs in aarch64 context switch 2022-08-25 18:23:51 -06:00
Jeremy Soller 52434b359c Disable building aarch64 asm 2022-08-25 18:12:43 -06:00
Jeremy Soller ff738074d2 Cleanup aarch64 code 2022-08-25 15:46:27 -06:00
Jeremy Soller afd82ba4bb Save/restore aarch64 FPU regs 2022-08-25 09:30:53 -06:00
Jeremy Soller 31680bf5b9 Do not set tpidr_el0 from kernel 2022-08-25 08:46:26 -06:00
Jeremy Soller b3b5bb8a91 Simplify handling of aarch64 env regs 2022-08-25 08:12:07 -06:00
Jeremy Soller f7e8026494 Set aarch64 thread pointers 2022-08-24 19:21:36 -06:00
Jeremy Soller 545a561a26 Set ptrace regs for aarch64 2022-08-24 19:03:30 -06:00
Jeremy Soller 84704353af Support address space change on aarch64 2022-08-24 18:54:42 -06:00
Jeremy Soller 6d3fa8b374 Enable clone_handler on aarch64 2022-08-24 15:50:10 -06:00
Jeremy Soller b20a71113c Implement aarch64 switch_to_inner using naked function 2022-08-24 13:24:37 -06:00
Jeremy Soller fb34e4eddf Partially implement stack trace on aarch64 2022-08-24 12:34:31 -06:00
Jeremy Soller 0ed9f03317 Use push/pop scratch for aarch64 signal handler 2022-08-24 12:29:48 -06:00
Jeremy Soller 613968dc30 Use push/pop scratch for x86 signal handler 2022-08-24 11:39:31 -06:00
Jeremy Soller 113a7164bb Use push/pup scratch for x86_64 signal handler 2022-08-24 11:11:50 -06:00
Jeremy Soller 310a0dda08 Some aarch64 register struct updates 2022-08-24 08:56:57 -06:00
Jeremy Soller bb12da2b68 Update syscall 2022-08-24 08:53:37 -06:00
Jeremy Soller 54d9d011aa Use framebuffer virtual address 2022-08-23 20:07:30 -06:00
Jeremy Soller 2b8af1cf07 Ignore areas outside 1GiB and combine memory areas on x86 2022-08-23 15:41:29 -06:00
Jeremy Soller aa51e9812d Use PAT flags on x86 2022-08-22 19:54:14 -06:00
Jeremy Soller f3e23af9ec Update rmm 2022-08-22 18:49:42 -06:00
Jeremy Soller 61ba2e6c8e Fix unmap_parents 2022-08-22 18:49:32 -06:00
Jeremy Soller 06d952979f Implement debugger for x86 2022-08-22 08:41:35 -06:00
Jeremy Soller 58104649db Set limits for x86 GDT entries 2022-08-21 14:56:59 -06:00
Jeremy Soller 538ad9e57f Remove debug message when writing x86 EnvRegisters 2022-08-21 13:22:58 -06:00
Jeremy Soller d3fbbd5918 Pre-allocate x86 kernel PD entries 2022-08-21 13:21:59 -06:00
Jeremy Soller 0d4ff5d4f3 Add functions for accessing mapper allocator 2022-08-21 13:20:44 -06:00
Jeremy Soller bdba700c21 Disable syscall debugging 2022-08-20 21:52:09 -06:00
Jeremy Soller 76a46c54b8 Fix stack selector on x86 2022-08-20 21:51:21 -06:00
Jeremy Soller c750ee26a8 Implement setting FS/GS offset on x86 2022-08-20 21:21:32 -06:00
Jeremy Soller 01e4bc899e Fix compilation on x86 2022-08-20 18:11:57 -06:00
Jeremy Soller d3f42989c9 Fix compilation on x86_64 2022-08-20 14:51:05 -06:00
Jeremy Soller 9dd069c8ca Support proc partially with aarch64 2022-08-20 14:45:45 -06:00
Jeremy Soller 9b8abfc5d7 Copy exception handlers from early_init 2022-08-20 13:48:13 -06:00
Jeremy Soller 44d5e6573a Updated utable switching code for aarch64 2022-08-20 13:31:20 -06:00
Jeremy Soller fe7def2797 Update to use TableKind on x86_64 2022-08-20 13:16:23 -06:00
Jeremy Soller 01df1c20da Use TableKind everywhere 2022-08-20 13:06:52 -06:00
Jeremy Soller 3911fc616a Update rmm 2022-08-20 13:01:01 -06:00
Jeremy Soller df733ed571 Use TableKind for most table operations 2022-08-20 13:00:48 -06:00
Jeremy Soller 849b854bd0 Implement usermode for aarch64 2022-08-20 09:34:12 -06:00
Jeremy Soller c7e5466bd7 Fix aarch64 switch_to_inner functino definition 2022-08-20 09:15:26 -06:00
Jeremy Soller 157dbc7b4d Convert aarch64 context switching to asm macro 2022-08-20 09:08:14 -06:00
Jeremy Soller 9ca2484079 Get aarch64 kernel to boot to the point of needing context switch 2022-08-19 21:40:04 -06:00
Jeremy Soller 82ad6e2fa7 Remove devmap region from aarch64, use physmap instead 2022-08-19 21:01:10 -06:00
Jeremy Soller ba64d82818 Make kstart the aarch64 entry point 2022-08-19 21:00:47 -06:00
Jeremy Soller 97b4d31355 Match aarch64 PHYS_OFFSET with x86_64 2022-08-19 20:54:02 -06:00
Jeremy Soller c5eb435d79 Match PHYS_OFFSET accross archs 2022-08-19 20:53:15 -06:00
Jeremy Soller a1411353a9 Update rmm 2022-08-19 19:52:39 -06:00
Jeremy Soller e05868e1dc Improve aarch64 paging instructions 2022-08-19 19:52:00 -06:00
Jeremy Soller 49fcafac45 Fix building on aarch64 2022-08-19 16:12:42 -06:00
Jeremy Soller 38361661e6 Add proc scheme stubs for aarch64 2022-08-19 16:00:35 -06:00
Jeremy Soller 80fc1d7fd4 Remove phys_offset stack hack 2022-08-18 15:03:35 -06:00
Jeremy Soller 6b2439f1b9 Improved 32-bit x86 support 2022-08-18 14:57:15 -06:00
Jeremy Soller c09be1770b Use registers for switch_to_inner instead of stack 2022-08-18 09:09:11 -06:00
Jeremy Soller 472081f8ba Save/restore GS segment on interrupt 2022-08-17 21:13:35 -06:00
Jeremy Soller bd9ee98ba9 Use same code for clone_handler on 32-bit and 64-bit x86 2022-08-17 14:40:30 -06:00
Jeremy Soller d47ba636a0 Support x86 in proc scheme 2022-08-17 14:32:12 -06:00
Jeremy Soller 679662c99e Name bootstrap process 2022-08-17 13:25:13 -06:00
Jeremy Soller 4bd137f36e Fixes for x86 32-bit 2022-08-17 10:48:23 -06:00
Jeremy Soller 1eda828877 Merge branch 'userspace_cwd' into 'master'
Remove SYS_CHMOD and cwd related syscalls/files.

See merge request redox-os/kernel!198
2022-08-16 09:17:37 +00:00
4lDO2 67c0b911b4 Update syscall 2022-08-16 10:45:04 +02:00
4lDO2 c3c135cb1d Remove chmod from UserScheme 2022-08-13 19:44:44 +02:00
4lDO2 431407aff0 Remove SYS_CHMOD and cwd related syscalls/files. 2022-08-13 19:44:44 +02:00
Jeremy Soller ac70c76922 Fix TSS and IDT structures on 32-bit x86 2022-08-12 09:03:56 -06:00
Jeremy Soller 9c78219a6a Use 32-bit TSS for x86 32-bit 2022-08-12 08:44:05 -06:00
Jeremy Soller d33ff704ba Implement usermode for x86 32-bit 2022-08-12 08:21:49 -06:00
Jeremy Soller 4602b81a2f Fix debugger when dumping kernel threads 2022-08-03 11:08:49 -06:00
Jeremy Soller 3ba1b018b7 Warn but otherwise allow unaligned sizes in funmap 2022-08-03 11:08:18 -06:00
Jeremy Soller 7a390c2a1d Sync some paging code for aarch64 with x86_64 2022-08-01 08:25:33 -06:00
Jeremy Soller 2191308d15 setup_new_utable for aarch64 2022-07-29 18:58:19 -06:00
Jeremy Soller 358abbd40f Fix copy paste error and update rmm 2022-07-29 18:53:27 -06:00
Jeremy Soller e9950ee6da Fix more warnings 2022-07-29 18:53:12 -06:00
Jeremy Soller 07015d17ba Sync x86 and x86_64 2022-07-29 18:49:55 -06:00
Jeremy Soller 166e1e304b Update syscall 2022-07-29 18:39:34 -06:00
Jeremy Soller 62c62c4e7c Update rmm 2022-07-29 18:38:12 -06:00
Jeremy Soller 23d4995e50 Fix warnings 2022-07-29 18:37:37 -06:00
Jeremy Soller 5d55d4eb87 Fix warnings 2022-07-29 18:33:54 -06:00
Jeremy Soller cc6c974c91 Bump kernel to 0.3.0 to match syscall 2022-07-29 18:18:27 -06:00
Jeremy Soller be12d0f1bd Add initial i686 arch module 2022-07-29 18:12:49 -06:00
Jeremy Soller 9b74fb3ff1 Update syscall 2022-07-29 18:07:44 -06:00
Jeremy Soller e99cbcf5d2 Fixes for compiling aarch64 2022-07-29 18:06:53 -06:00
Jeremy Soller 897cd4c9f4 Add graphical_debug module 2022-07-29 15:57:02 -06:00
Jeremy Soller 0c80643077 Make graphical_debug arch independent and fix lots of warnings 2022-07-29 15:56:44 -06:00
Jeremy Soller 87acffe859 Fix kernel TLS permissions in INIT_GDT 2022-07-29 09:28:13 -06:00
Jeremy Soller 4d1c41232b Support inner_physmap on 32-bit systems 2022-07-29 09:27:54 -06:00
Jeremy Soller 059f2a0d07 Support ContextList::spawn on i686 2022-07-29 09:27:35 -06:00
Jeremy Soller a1d9edee52 Use Mutex<u64> instead of AtomicU64 for user scheme packet ID 2022-07-29 09:25:40 -06:00
Jeremy Soller bf9e630f65 Fix building proc scheme on non-x86_64 2022-07-29 09:25:17 -06:00
Jeremy Soller f0d3e3281c Use acpi on i686 2022-07-28 08:22:55 -06:00
Jeremy Soller 8db4596f73 Use x86 crate on i686 as well 2022-07-28 08:22:26 -06:00
Jeremy Soller fdb4ad8e88 Only build debugger on x86_64 for now 2022-07-28 08:21:31 -06:00
Jeremy Soller 8d5ca62499 Add linker and target for i686 2022-07-28 08:20:49 -06:00
Jeremy Soller a45a7c696e Merge branch 'fix-bootstrap' into 'master'
Fix bootstrap

See merge request redox-os/kernel!196
2022-07-28 13:38:27 +00:00
4lDO2 f3faf33e3f Add a workaround to treat bootstrap mem as owned. 2022-07-28 14:17:02 +02:00
4lDO2 ca4525462d Return right number of bytes written for addrspace. 2022-07-28 14:16:07 +02:00
4lDO2 2d935ca6d3 Update cargo.lock 2022-07-27 18:01:58 +02:00
Jeremy Soller 7fcdd8f6e2 Merge branch 'userspace_fexec' into 'master'
Userspace fexec

See merge request redox-os/kernel!195
2022-07-27 15:40:58 +00:00
4lDO2 e58bf714d8 Update rmm and syscall 2022-07-27 17:39:16 +02:00
4lDO2 5700899e9a Merge branch 'migrate_kernel_to_rmm' into 'master'
Add necessary functionality for migrating kernel paging code to RMM

See merge request redox-os/rmm!6
2022-07-27 15:10:52 +00:00
4lDO2 99362f98d2 Add a better interface for modifying addrspaces. 2022-07-27 10:52:52 +02:00
4lDO2 939feacdc5 Add fn for validating user memory range bounds. 2022-07-27 10:52:46 +02:00
4lDO2 5bbfdcda6b Add mmap-min-addr and support unmapping parent PTs. 2022-07-27 10:52:45 +02:00
4lDO2 0720db2265 Remove SYS_EXEC debug code. 2022-07-27 10:52:29 +02:00
4lDO2 308c2cc711 Support modifying processes' sigactions.
This is, other than vfork, the last piece of functionality that the
previous clone() offered (CLONE_SIGHAND) which previously was not
implemented.
2022-07-27 10:52:29 +02:00
4lDO2 b766501896 Fix deadlock while starting APs. 2022-07-27 10:52:29 +02:00
4lDO2 bf82387f3b Fix KernelMapper unlocking code. 2022-07-27 10:52:29 +02:00
4lDO2 e60321d4a0 Partial: migrate remaining parts to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 dc8ce1c22b Partial: migrate context handling code to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 c912d9e0db Partial: migrate syscall handling code to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 6589083238 Partial: Migrate schemes to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 486d296d6d Remove old x86_64 paging code, migrate to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 302e55098c Migrate misc x86_64 parts to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 2bb019bc44 Partial: migrate debugger, add consistency check. 2022-07-27 10:52:23 +02:00
4lDO2 648b0edb41 Partial: migrate allocator to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 0aec4d3341 Partial: migrate ACPI to RMM. 2022-07-27 10:52:23 +02:00
4lDO2 8970ce1fe7 Benefit from addrspace abstraction in switch. 2022-07-27 10:52:22 +02:00
4lDO2 1cdd462244 Move the initfs scheme to userspace. 2022-07-27 10:52:22 +02:00
4lDO2 351d77ad9b Improve floating point handling. 2022-07-27 10:52:22 +02:00
4lDO2 94578efd1e Use alloc_zeroed when allocating FX. 2022-07-27 10:52:22 +02:00
4lDO2 db3b834f19 Also inherit pgid, umask, sigmask. 2022-07-27 10:52:22 +02:00
4lDO2 4aea0cfd0c Fix AddrSpace memory leak. 2022-07-27 10:52:22 +02:00
4lDO2 b141cdaad2 Fail if funmap's length isn't page size divisible. 2022-07-27 10:52:22 +02:00
4lDO2 60e3e0af34 Flush less frequently in funmap. 2022-07-27 10:52:22 +02:00
4lDO2 549c023398 Return correct bytes written in proc:X/addrspace. 2022-07-27 10:52:22 +02:00
4lDO2 59d74689dc Copy filetable more efficiently. 2022-07-27 10:52:22 +02:00
4lDO2 0b67997c7b Fix "id == current" check in set_addr_space. 2022-07-27 10:52:21 +02:00
4lDO2 240d91f951 Set address space/files when closing, not writing.
This fixes file descriptor leaks. Suppose relibc is just about to set
the address space. For this, it needs to write the address space fd to
the selection fd. To avoid having to close them in the kernel, it rather
memorizes what the file descriptors refer to internally, and then do the
actual operation when they are gone, i.e. when closing.
2022-07-27 10:52:19 +02:00
4lDO2 fa48c7aa97 Deduplicate code for transferring/creating grants. 2022-07-27 10:52:11 +02:00
4lDO2 cb40eb3792 Support reading all grants and transferring grants. 2022-07-27 10:52:10 +02:00
4lDO2 b50495bfa5 WIP: Support clone in userspace
Everything seems to work for the most part, but now there are tons of
daemons which rely on syscall::clone, which is now implemented in relibc
:(
2022-07-27 10:52:04 +02:00
4lDO2 283ada82a0 WIP: Remove SYS_CLONE (to be done in userspace). 2022-07-27 10:52:03 +02:00
4lDO2 563121596d Fix running on multi_core.
Turns out the problem all along was that the ActivePageTable was never
dropped in usermode_bootstrap. So as soon as any other hardware thread
tried to do page table business, it deadlocked!
2022-07-27 10:51:45 +02:00
4lDO2 6e5015dcab WIP: Add necessary interfaces for setuid/setgid. 2022-07-27 10:51:45 +02:00
4lDO2 37f9b292f1 Add kfmap to fix properly reobtaining grants. 2022-07-27 10:51:45 +02:00
4lDO2 de28cc4918 Add a Scheme supertrait for kernel-only methods. 2022-07-27 10:51:45 +02:00
4lDO2 31c4bc8a1c Remove kernel support for fmap_old and funmap_old. 2022-07-27 10:51:45 +02:00
4lDO2 23f49414bd Fix phys offset, lock grants correctly. 2022-07-27 10:51:45 +02:00
4lDO2 15b029de36 Fix everything all the way to booting to desktop. 2022-07-27 10:51:45 +02:00
4lDO2 e6e1348072 Implement exec, and change UserGrant allocator. 2022-07-27 10:51:44 +02:00
4lDO2 f7f722f81c Don't use identity mapping for ACPI.
This is so that any process can use pointers to ACPI tables, since they
now point to the universally-accessible KERNEL_OFFSET+physaddr virtual
addresses.
2022-07-27 10:51:44 +02:00
4lDO2 846318e716 WIP: Attempt implementing fexec in userspace. 2022-07-27 10:51:43 +02:00
4lDO2 67edfbfc42 Remove the unused USER_HEAP_PML4. 2022-07-27 10:50:53 +02:00
4lDO2 9462df03e7 Add support for unmapping parents.
Currently, this uses a relatively naive method of simply scanning the
512 entries for the PRESENT flag. But, unless the optimizer cannot, it
can be reduced to calculating the bitwise OR of every entry and then
checking that.

If this turns out to be too slow, which it might be when unmapping lots
of pages, then we can (1) either fall back to using a counter like the
old paging code did, or even better (2) use the now-1:1 grants tree to
check if it became empty. Putting the grants code in RMM might be
suboptimal, so instead we can add "unmap_range" and have the kernel
paging code take the offset of the next grant, if any, and then possibly
unmap entire P1s/P2s/P3s -- whatever is in the page tables within that
range.

Note that I am fairly certain that method (1) was the cause of the
visually notorious orbital memory corruption bug.
2022-07-27 10:49:49 +02:00
4lDO2 229ae5da40 Add remaining interfaces to user RMM for user mem. 2022-07-27 10:49:49 +02:00
4lDO2 efc67a2012 Use wrapped flags for PageEntry. 2022-07-27 10:49:49 +02:00
4lDO2 fad6afa7d8 Flush on Drop, unless explicitly ignored. 2022-07-27 10:49:49 +02:00
4lDO2 7a209c83c9 Implement Debug for X8664Arch. 2022-07-27 10:49:49 +02:00
4lDO2 c847b1e2a8 Implement FrameAllocator for mutable refs of impls. 2022-07-27 10:49:49 +02:00
4lDO2 2f16dddf25 Add a page flusher trait. 2022-07-27 10:49:49 +02:00
Jeremy Soller 76d29bac78 Update rmm 2022-07-26 20:16:47 -06:00
Jeremy Soller 0944b17983 Add initial x86 32-bit support 2022-07-26 20:13:55 -06:00
Jeremy Soller ec284ca8e3 Update rust-toolchain 2022-07-26 19:01:42 -06:00
Jeremy Soller ac38e62398 Update syscall 2022-07-26 15:30:51 -06:00
Jeremy Soller b5a9301706 Map live disk only if not already mapped 2022-04-26 12:01:55 -06:00
Jeremy Soller 65bbd50416 Update kernel version to match syscall version 2022-04-26 08:28:05 -06:00
Jeremy Soller e88e7d6df1 Fix HPET on real hardware with better debugging 2022-04-25 15:08:09 -06:00
Jeremy Soller 6f83a0800a Set graphical_debug by default 2022-04-25 08:47:10 -06:00
Jeremy Soller 6e98736c94 Do not map live disk twice 2022-04-25 08:43:51 -06:00
Jeremy Soller 7205dd7463 Unmap xAPIC page if already mapped 2022-04-12 20:17:27 -06:00
Jeremy Soller 8f06672153 Merge branch 'external-initfs' into 'master'
External initfs

See merge request redox-os/kernel!192
2022-04-11 21:09:08 +00:00
4lDO2 df37b1f634 External initfs 2022-04-11 21:09:08 +00:00
Jeremy Soller dc9e6eaf0c Merge branch 'clone_grant_using_fmap_v2' into 'master'
Fix "clone grant using fmap"

See merge request redox-os/kernel!193
2022-04-11 20:19:41 +00:00
4lDO2 4d7da495f5 Fix "clone grant using fmap"
This does the same as the previous MR, but fixes the issue where the
parent process got the mapping (and at the wrong address) and not the
child process.
2022-04-11 21:31:36 +02:00
4lDO2 e72fd5a0e4 Fix a kernel deadlock in empty().
For more information, see https://gitlab.redox-os.org/4lDO2/kernel/-/commit/b3b5d1b864eec030d53ccd2ab907c68958f140aa
2022-04-09 13:38:59 +02:00
Jeremy Soller 87b3bef06c Revert "Merge branch 'clone_grant_using_fmap' into 'master'"
This reverts merge request !190
2022-03-30 14:54:49 +00:00
Jeremy Soller 37ebef2d35 Merge branch 'pipe_list_const_fn' into 'master'
Move more of `pipe:`'s initialization to compile time.

See merge request redox-os/kernel!182
2022-03-30 13:54:27 +00:00
Jeremy Soller cbc2902852 Merge branch 'context_list_const_fn' into 'master'
Pre-initialize the context list at compile time.

See merge request redox-os/kernel!181
2022-03-30 13:53:57 +00:00
Jeremy Soller c5c5b33b6a Merge branch 'clone_grant_using_fmap' into 'master'
Clone grant using fmap

See merge request redox-os/kernel!190
2022-03-30 13:53:08 +00:00
4lDO2 b9c34b3c05 Merge branch 'update-toolchain-2022' into 'master'
Update to latest toolchain.

See merge request redox-os/kernel!191
2022-03-27 09:17:09 +00:00
4lDO2 51e339c973 Update rmm and syscall. 2022-03-24 15:55:16 +01:00
Jeremy Soller 507f7ccd4a Merge branch 'update-toolchain-2022' into 'master'
Update to latest toolchain.

See merge request redox-os/rmm!5
2022-03-23 18:06:11 +00:00
4lDO2 a5f4e9a52a Update syscall. 2022-03-19 22:09:17 +01:00
4lDO2 8644f82b48 Remove unused Xargo.toml. 2022-03-19 22:09:03 +01:00
4lDO2 6255bea143 Update to latest toolchain.
Multi-core is slightly broken when using the latest version of spin
(0.9.2). I believe this is because Once used to do SeqCst loads/stores
everywhere, which might have made any possible data race much harder to
come by.
2022-03-12 17:10:36 +01:00
Jeremy Soller 80376a95dc Improve graphical debug performance 2022-03-08 07:36:01 -07:00
Jeremy Soller 150717f18e Enable local apic error interrupt on all processors 2022-03-07 13:56:46 -07:00
Jeremy Soller b62496f50e Debug HPET init 2022-03-07 13:56:17 -07:00
4lDO2 e2648005ba Update to latest toolchain. 2022-03-06 11:34:22 +01:00
Jeremy Soller 7e2e7b8c21 Log reasons why HPET not used 2022-03-02 08:43:11 -07:00
Jeremy Soller ae3bdea4bc Update raw-cpuid 2022-03-01 18:12:06 -07:00
Jeremy Soller d234df37c9 Improve RMM logging 2022-03-01 17:57:03 -07:00
Jeremy Soller fe468aa1ab Improvements for graphical debug and system76 EC debug 2022-03-01 16:25:15 -07:00
Jeremy Soller 2b5aa1f375 Cleanup of graphical debug to allow it to run much earlier 2022-03-01 15:50:26 -07:00
Jeremy Soller ae0d48d9ab Identity map ACPI 2022-03-01 12:52:06 -07:00
Jeremy Soller 47c3bbe13a Update syscall 2022-03-01 09:28:17 -07:00
Jeremy Soller 81e700708d Get memory areas as argument instead of from hardcoded pointer 2022-02-14 11:52:02 -07:00
Jeremy Soller 933b3b8fc0 Respect min flag to allocate_frames_complex 2022-02-14 10:29:12 -07:00
Jeremy Soller c1aa76bf3c Fill in st_dev in fstat 2022-02-14 09:57:24 -07:00
Jeremy Soller 52ad689d37 Notify debug: readers of new input after all input is processed 2022-02-14 08:49:34 -07:00
Jeremy Soller 1aae949fc4 Support for getting live disk from bootloader 2022-02-10 15:49:34 -07:00
Jeremy Soller 9e6664fb82 Fix additional page mapping in graphical debug 2022-02-10 14:48:52 -07:00
Jeremy Soller 7d9a33c63a Add debugger (dumps all kernel state) 2022-02-10 14:10:04 -07:00
Jeremy Soller f92fe90069 Use requested page table in trampoline 2022-02-07 17:49:23 -07:00
Jeremy Soller 1b2a28a4f0 Use FRAMEBUFFER variables for graphical debug 2022-02-07 17:38:52 -07:00
Jeremy Soller 413238a0a6 Prevent re-use of real mode areas, adjust areas instead of panic 2022-02-07 16:36:05 -07:00
Jeremy Soller b109263e77 Ensure ACPI RSDPs are not re-used 2022-02-05 19:59:02 -07:00
Jeremy Soller 308c5ad3d9 Make sure kernel, stack, and env are identity mapped 2022-02-04 11:16:54 -07:00
Jeremy Soller 941f59283b Map kernel to KERNEL_OFFSET, remove bump_offset 2022-02-03 20:21:00 -07:00
Jeremy Soller 5104437423 WIP: changes for rust bios bootloader 2022-02-03 17:15:28 -07:00
Jeremy Soller bbc4a4aefe workaround for crash on graphical debug finish 2022-01-28 09:47:47 -07:00
Jeremy Soller 3f2a9f7f0a Fix graphical debug feature 2022-01-28 09:15:03 -07:00
4lDO2 a3356c3fdd Clone grant using fmap 2021-12-30 11:27:44 +01:00
Jeremy Soller 0ab4529eaa Make register dumps lowercase 2021-12-01 09:53:33 -07:00
Jeremy Soller cd3dcf153e Do not print interpreter 2021-12-01 08:40:11 -07:00
Jeremy Soller 63fcc204cb x86 paging refactor for debugger 2021-11-30 20:56:55 -07:00
Jeremy Soller 77b8215a66 Getter for Grant region, remove set_mapped, and make region_mut private 2021-11-30 20:06:45 -07:00
Jeremy Soller 4f259e3589 Workaround for thread race conditions 2021-11-30 18:03:34 -07:00
Jeremy Soller 515cab03eb Fix a number of warnings 2021-11-29 20:01:27 -07:00
Jeremy Soller 61279db991 Remove no_threaded_syscalls feature 2021-10-27 20:48:16 -06:00
Jeremy Soller 61d8b0ff32 Fix allocator race condition 2021-10-27 20:29:00 -06:00
Jeremy Soller 063881d2ca Show context name and syscall when panicking 2021-10-27 20:28:40 -06:00
Jeremy Soller 9ea278997c Disable threaded syscalls until threaded allocation issues are solved 2021-10-20 20:05:47 -06:00
Jeremy Soller 64f1533d6f Implement anonymous fmap 2021-09-22 21:04:04 -06:00
Jeremy Soller 17309754d6 Merge branch 'no-more-recursive-mapping' into 'master'
No more recursive mapping

See merge request redox-os/kernel!187
2021-08-13 02:13:07 +00:00
4lDO2 307fcf3ad7 Remove now unused TLS struct. 2021-08-11 17:46:40 +02:00
4lDO2 d6e1797620 Make Mapper::map fallible. 2021-08-11 17:46:40 +02:00
4lDO2 df145ea0a9 Utilize linear_phys_to_virt where applicable. 2021-08-11 17:46:40 +02:00
4lDO2 16a31b0cd1 Add linear_phys_to_virt and vice versa.
However, since not all platforms will allow the entire physical address
space to be simultaneously mapped to part of the virtual address space,
we may still require some dynamic mapping.
2021-08-11 17:46:40 +02:00
4lDO2 5f4978a6dc Return ENOMEM rather than panicking for PML4 alloc. 2021-08-11 17:46:40 +02:00
4lDO2 67cc6799bd Fix possible UB by checking for null allocating FX.
Namely, the global allocator API in Rust, actually only returns a null
pointer on failure, rather than wrapping it in a Result, which AllocRef
does. Since Box::from_raw(null) is direct UB, this can in theory lead to
very strange behavior.
2021-08-11 17:46:40 +02:00
4lDO2 465c461b60 WIP: Stop using recursive mapping.
Note that this is very preliminary, and I merely got my already freezing
kernel branch not to triple fault, but I would probably apply this patch
to upstream.

What is changed here, is that rather than relying on recursive mapping
for accessing page table frames, it now uses linear translation
(virt=phys+KERNEL_OFFSET). The only problem is that the paging code now
makes assumptions that the entire physical address space remains mapped,
which is not necessarily the case on x86_64 architecturally, even though
systems with RAM more than a PML4 are very rare. We'd probably lazily
(but linearly) map physical address space using huge pages.
2021-08-11 17:46:33 +02:00
Jeremy Soller 0c3542ff51 Store funmap data with the context's grants 2021-08-10 20:46:30 -06:00
Jeremy Soller f94dc3beb8 Allow current process to access its own proc data 2021-08-10 16:33:49 -06:00
Jeremy Soller 0b1445f8bd Merge branch 'fix_interrupt_handlers' into 'master'
Fix TLS in paranoid interrupt handlers

See merge request redox-os/kernel!186
2021-08-09 21:19:39 +00:00
4lDO2 1a80351a2c Fix TLS in paranoid entries. 2021-08-09 14:25:15 +02:00
4lDO2 41d5a2a786 Use naked functions in syscall inst handler too. 2021-08-06 18:08:04 +02:00
4lDO2 d7a1c6255b Fix possible race condition in paranoid ISRs.
Additionally, because it turned out to be infeasible to rely on
link-time constants in global_asm! code, I have also converted the
interrupt handlers to naked fns. This removes the proc-macro-reliant
"paste" dependency, but inserts a tiny ud2 at the end of every ISR.
2021-08-06 17:34:56 +02:00
4lDO2 1047728f35 Only set process regs for faults from ring 3.
This fixes a deadlock that might occur if a page fault is triggered
while a lock to the current context is held.
2021-08-06 15:41:38 +02:00
4lDO2 862265f150 Merge branch 'fsgsbase' into 'master'
FSGSBASE and user-controlled TLS

See merge request redox-os/kernel!185
2021-08-06 13:22:45 +00:00
4lDO2 25a82eeb1b Update syscall again. 2021-08-06 15:09:32 +02:00
4lDO2 57a1e37535 Update syscall. 2021-08-06 14:46:47 +02:00
4lDO2 87241a9d3c Pass AT_PHDR via a grant rather than the stack. 2021-08-01 14:57:41 +02:00
4lDO2 3eedbeb14d WIP: Let userspace manage fsbase/gsbase and TLS. 2021-08-01 12:09:22 +02:00
4lDO2 0968e4f87e Support fsgsbase at compile time. 2021-07-31 10:12:59 +02:00
Jeremy Soller 9c3cf84453 Merge branch 'futex_wait64' into 'master'
Add support for full 64-bit futex words

See merge request redox-os/kernel!183
2021-07-11 22:14:10 +00:00
4lDO2 6993c98e0f Update rmm and syscall. 2021-07-12 00:10:48 +02:00
Jeremy Soller 37e88ff4d3 Merge branch 'virt_is_canonical' into 'master'
Add Arch::virt_is_valid

See merge request redox-os/rmm!4
2021-07-11 21:33:34 +00:00
4lDO2 bbe6b4650a Futex: check for lower-half addrs manually. 2021-07-08 16:08:02 +02:00
4lDO2 6bc59e7013 Remove virt_kind, impl virt_is_valid() for riscv.
All there is left now is AArch64.
2021-07-08 16:06:51 +02:00
4lDO2 bcfd7b175e Update rmm. 2021-07-08 13:47:16 +02:00
4lDO2 b75c329a27 Add virt_kind and virt_is_valid for emulation. 2021-07-08 13:35:51 +02:00
4lDO2 9e9d025bb5 Add support for FUTEX_WAIT64. 2021-07-08 13:28:46 +02:00
4lDO2 32caee3095 Add arch functions for checking canonical addrs. 2021-07-08 13:27:08 +02:00
4lDO2 e92ff831b7 Move more of pipe:s init to compile time. 2021-07-05 11:54:11 +02:00
4lDO2 f2926f5f25 Pre-initialize the context list at compile time. 2021-07-05 11:30:08 +02:00
Jeremy Soller b973c5db95 Merge branch 'dont-hardcode-reg-offsets' into 'master'
Use offset_of! in context::arch::switch_to.

See merge request redox-os/kernel!180
2021-06-21 19:06:56 +00:00
4lDO2 3e5cf387d5 Use offset_of! in context::arch::switch_to.
This is definitely better than hardcoding the offsets!
2021-06-21 10:16:41 +02:00
4lDO2 6039026349 Merge branch 'update_toolchain' into 'master'
Update toolchain

See merge request redox-os/kernel!179
2021-06-18 15:15:15 +00:00
4lDO2 ecfcedb9bf Remove explicit .intel_syntax directive.
It is now default, and the new compiler generated a lot of warnings now
that Intel syntax has (luckily) become the default.
2021-06-18 09:20:13 +02:00
4lDO2 1cf5f5ea22 Update dependencies to work with latest nightly. 2021-06-17 22:42:54 +02:00
4lDO2 2dc899dc3b Update paste and align interrupt handlers. 2021-06-17 22:42:50 +02:00
4lDO2 7594dd60d2 Remove compare_and_swap from int_like!. 2021-06-17 22:42:44 +02:00
4lDO2 7d4defa5e5 Use weak CAS and use abort() in context::switch.
Previously context::switch used compare_and_swap for acquiring the
global context switch lock, but given its deprecation in more recent
Rust versions, it has been replaced with compare_exchange_weak (which
can be further optimized on some architectures).

It also replaces panic!() with abort() in switch_finish_hook, because
unwinding from assembly is not that fun.
2021-06-17 22:42:38 +02:00
4lDO2 cc6f792a03 Use options(noreturn) in all naked functions. 2021-06-17 22:42:31 +02:00
4lDO2 dc5f1fe055 Update toolchain. 2021-06-17 22:42:23 +02:00
4lDO2 c66956ca2a Remove unused #![feature(const_fn)]. 2021-06-17 18:42:03 +02:00
Jeremy Soller d3cf4db47b Prerequisites for risv64 support 2021-05-12 20:23:53 -06:00
Jeremy Soller 0a79c17307 Show meaning of CODE on page fault 2021-05-10 11:34:14 -06:00
Jeremy Soller 8130e4752b Map TSS using RMM 2021-05-07 09:13:25 -06:00
Jeremy Soller 77f6887fbc Debug use of memory map and env data 2021-05-07 08:54:36 -06:00
Jeremy Soller 38f7884e21 Improvements for aarch64 serial driver on real hardware 2021-05-06 21:25:15 -06:00
Jeremy Soller 2c474f98f9 Merge branch 'higher_half_percpu' into 'master'
Put the KPCRs in high memory, in their own PML4.

See merge request redox-os/kernel!173
2021-05-06 19:25:16 +00:00
4lDO2 36b3a4a49e Add KERNEL_PERCPU_PML4 on AArch64. 2021-05-06 21:22:48 +02:00
4lDO2 558109a9cb Put the KPCRs in high memory, in their own PML4.
This also removes the need to do another semi-expensive remap when
cloning processes, since the KPCRs (for kernel TLS) are no longer stored
in the user PML4.
2021-05-06 21:21:37 +02:00
Jeremy Soller 2e38fab913 Do not hardcode aarch64 uart 2021-05-06 13:16:50 -06:00
Jeremy Soller c4617c0bce Merge branch 'outsource-most-acpi' into 'master'
Move most of ACPI to userspace

See merge request redox-os/kernel!175
2021-05-06 18:36:06 +00:00
4lDO2 3eacbdda2a Remove unnecessary exit() diff. 2021-05-06 19:49:58 +02:00
4lDO2 fd97fa80bb Move pid back to inner scope in exit() handler. 2021-05-06 19:49:58 +02:00
4lDO2 a771ca699a Move all DMAR parsing to userspace.
We may also want to do this with the MADT and the HPET tables, and let
user drivers specify what the tables mean independent of ACPI. That is,
adding an interface for registering new CPUs, and specifying the main
timer IRQ.
2021-05-06 19:49:58 +02:00
4lDO2 e816d4801f Remove the empty fadt module. 2021-05-06 19:49:58 +02:00
4lDO2 9b4ce0d0cc WIP: Fix userspace ACPI shutdown. 2021-05-06 19:49:58 +02:00
4lDO2 b2e131b57b Fix ACPI scheme fevent warning. 2021-05-06 19:49:58 +02:00
4lDO2 7ac5bdbae0 WIP: Implement userspace-driven shutdown. 2021-05-06 19:49:58 +02:00
4lDO2 64b2dd238a Rename the kernel ACPI scheme to kernel/acpi:. 2021-05-06 19:49:57 +02:00
4lDO2 bea6747643 Move all AML code to userspace.
Currently, there are some things that need to be set up by userspace
that the kernel previously did. These include telling firmware when the
I/O APIC is used, and most importantly, shutting down the system.

The former is not particularly important, but for the latter I think
that we could implement this using a "shutdown pipe". Essentially it
will be a file that triggers an event shutting down, which would be used
to notify to acpid that the kernel is requesting a shutdown.
2021-05-06 19:49:57 +02:00
Jeremy Soller 28d1d7e847 Update version to 0.2.8 2021-05-05 21:21:57 -06:00
Jeremy Soller 46a364471c Re-init aarch64 serial port for interrupts 2021-05-05 20:46:51 -06:00
Jeremy Soller 11a3315255 Re-enable acpi feature and gate it for x86_64 only 2021-05-04 08:33:00 -06:00
Jeremy Soller ac8c7834ef Update linked branch of rmm and syscall 2021-05-04 08:14:43 -06:00
Jeremy Soller bdccce4a1b Update rmm and syscall 2021-05-04 08:12:18 -06:00
Jeremy Soller c81c4de223 Add method to get TableKind from VirtualAddress 2021-05-04 08:10:44 -06:00
Jeremy Soller 5e47692b8d Support more operations on PageFlags 2021-05-04 08:10:44 -06:00
Jeremy Soller 2f74326384 Add riscv64 sv39 and sv48 2021-05-04 08:10:34 -06:00
Jeremy Soller 3dc08c878f Fix aarch64 switch_to function 2021-05-04 08:07:44 -06:00
Jeremy Soller b9a89f2160 More fixes for building aarch64 2021-05-03 22:07:40 -06:00
Jeremy Soller 8f50785781 Fixes for building aarch64 2021-05-03 21:57:45 -06:00
Jeremy Soller c646cb76e5 Update rmm 2021-05-03 21:29:44 -06:00
Jeremy Soller 8d61c79b23 Use RMM TableKind and fix x86_64 compilation 2021-05-03 21:15:46 -06:00
Jeremy Soller 2aa4d8caf5 Merge remote-tracking branch 'origin/aarch64-rebase' into riscv64 2021-05-03 20:52:59 -06:00
Jeremy Soller 17c261553b Fixes for building x86_64 2021-05-03 20:43:18 -06:00
Jeremy Soller dfdb562e6b Use RMM PhysicalAddress 2021-05-03 20:33:31 -06:00
Jeremy Soller 9f0532b1d5 Remove unused flags from old EntryFlags 2021-05-03 17:29:55 -06:00
Jeremy Soller b9448274fc Switch to using RMM PageFlags 2021-05-03 17:28:08 -06:00
Jeremy Soller 826180659c Update rmm and syscall 2021-05-03 17:16:59 -06:00
Jeremy Soller ff8cb8abe8 Enforce must_use 2021-05-03 15:02:32 -06:00
Jeremy Soller dd0616cc8f Use RMM for TLB flushing 2021-05-03 12:42:16 -06:00
Jeremy Soller 29460e0bff Use RMM for some arch-specific paging functions 2021-05-03 12:14:49 -06:00
Jeremy Soller c46d148e26 Fix tests for aarch64 2021-05-02 21:25:27 -06:00
Jeremy Soller ad39568fe9 Fix unwrapping stack when there are kernel addresses (and there always are) 2021-05-02 19:53:31 -06:00
4lDO2 af17eeec3a Give schemes a dangling address for empty slices.
This allows schemes to avoid checking the length against zero before
constructing a slice from pointer+len that the kernel gave.
Additionally, the address is now non-canonical on x86, meaning that
userspace will fail instead of continuing with UB, if they would ever
forget to check the length.
2021-04-29 07:40:50 -06:00
Jeremy Soller 73c77d756d Print context name in exception 2021-04-28 21:15:21 -06:00
Jeremy Soller 37e6951501 Print CPU and PID when exception occurs 2021-04-28 20:59:52 -06:00
Jeremy Soller d331f72f2a Use UTF-8 for all paths 2021-04-28 20:06:07 -06:00
Jeremy Soller 8fcd375bd9 Switch Context::grants to RwLock 2021-04-28 20:04:27 -06:00
Jeremy Soller 41bea0086f Switch Context::actions to RwLock 2021-04-28 20:03:29 -06:00
Jeremy Soller 83dea72a50 Switch Context::files to RwLock 2021-04-28 20:03:25 -06:00
Jeremy Soller c7aba8fdfd Switch Context::cwd to using RwLock 2021-04-28 20:03:18 -06:00
Jeremy Soller a9bee0bbdc Require UTF-8 for context name 2021-04-28 20:03:12 -06:00
Jeremy Soller b26c3e0ae9 Make context name a RwLock 2021-04-28 20:03:05 -06:00
Jeremy Soller f90033e0e1 Use PHYS_OFFSET instead of KERNEL_OFFSET to refer to the physmap 2021-04-13 20:38:54 -06:00
Jeremy Soller afca4da382 Update syscall 2021-04-13 19:34:38 -06:00
Jeremy Soller 959a917ba2 Update RMM 2021-04-13 19:34:27 -06:00
Jeremy Soller 7fd1218465 Merge remote-tracking branch 'origin/aarch64-rebase' 2021-04-13 19:12:48 -06:00
Jeremy Soller 5fe8dcf6af Merge branch 'chown-perms' into 'master'
UserScheme: permission check EUID and EGID before proceeding with chown

See merge request redox-os/kernel!176
2021-03-21 13:02:41 +00:00
Joshua Abraham ee6493d02e UserScheme: permission check EUID and EGID before proceeding with chown
Fixes redox#1327.
2021-03-20 20:42:02 -05:00
Jeremy Soller 47048102ef Fix typo in ContextList 2021-03-02 19:57:44 -07:00
Jeremy Soller b8e47f6b8f Merge branch 'fix-invalid-grant-state' into 'master'
Fix "Grant should not exist" errors.

See merge request redox-os/kernel!174
2021-03-02 13:30:03 +00:00
4lDO2 031496ff0d Fix "Grant should not exist" errors.
This is done by making sure that when empty() is called on a context,
the grants Arc will be replaced with a new unused Arc, hence
decrementing the refcount. Previously this was only done when the
context was actually reaped, but since there is no guarantee as far as I
am aware about when this must happen, the grants could be completely
leaked, leading to the error.
2021-02-27 15:36:12 +01:00
Jeremy Soller f873fc7e1a Merge branch '4lDO2/kernel-use_gs_for_tls' 2021-02-23 09:21:00 -07:00
Jeremy Soller ba330ffc9a Merge branch 'fix-utf8-userspace-ub' into 'master'
Give schemes a dangling address for empty slices, fixing UB in userspace

See merge request redox-os/kernel!172
2021-02-23 16:17:30 +00:00
4lDO2 ad58ca1de6 Give schemes a dangling address for empty slices.
This allows schemes to avoid checking the length against zero before
constructing a slice from pointer+len that the kernel gave.
Additionally, the address is now non-canonical on x86, meaning that
userspace will fail instead of continuing with UB, if they would ever
forget to check the length.
2021-02-20 17:20:30 +01:00
4lDO2 bdc925d275 Use GS for TLS!
Previously, the kernel used the regular FS segment for Thread-Local
Storage. The problem however, is that userspace code also uses FS for
TLS, meaning that the kernel would have to switch the FS segment between
user and kernel, _upon every syscall_. This is obviously suboptimal for
performance (especially with fast syscalls such as futex, nanosleep, or
yield).

I had to search LLVM for hours, just to find out that the insertion of
the memory load with FS was actually done in the linker, so I added a
flag for that.

I haven't done any proper benchmarking, but the boot process seems to
have gotten much faster!
2021-02-17 14:44:45 +01:00
Jeremy Soller a283160c14 Merge branch 'sysretq-fix2' into 'master'
FIX: Forbid lower-half noncanonical addresses too.

See merge request redox-os/kernel!170
2021-02-17 13:32:26 +00:00
4lDO2 1988583e23 Forbid lower-half noncanonical addresses too. 2021-02-17 13:00:07 +01:00
Jeremy Soller 98af1405e6 Merge branch 'sysretq-fix' into 'master'
Fix mistyped instructions in sysretq

See merge request redox-os/kernel!169
2021-02-15 19:12:05 +00:00
4lDO2 a4b3af34a5 Use correct jump instruction. 2021-02-15 20:05:00 +01:00
4lDO2 c19581282d Use the correct add instruction when popping CS. 2021-02-15 20:02:35 +01:00
Jeremy Soller 2a9b7a0fc8 Merge branch 'sysretq' into 'master'
Use faster sysretq when returning from system calls

See merge request redox-os/kernel!168
2021-02-15 18:59:19 +00:00
4lDO2 8eb58891aa Simplify sysretq code. 2021-02-15 19:53:49 +01:00
4lDO2 5b2df9f504 Document why usermode() can omit rcx check. 2021-02-15 19:53:49 +01:00
4lDO2 ff33090fd0 Check whether RCX is canonical in sysretq. 2021-02-15 19:53:41 +01:00
4lDO2 a183953ee8 Motivate usage of the IST without SWAPGS involved. 2021-02-15 19:53:37 +01:00
4lDO2 a3583a10ce Only swapgs when leaving/entering userspace code. 2021-02-15 19:53:37 +01:00
4lDO2 05db0f5977 Temporarily fix sysretq by swapping gs 4 times.
In order words, it swaps gs both directly at the start of the syscall
handler, then swaps it back, and the at the end of the syscall handler.
I cannot tell for sure why this is necessary, but probably since some
interrupt handler will execute swapgs in the wrong order or something.
2021-02-15 19:53:37 +01:00
4lDO2 1a8016b985 Give NMI, #DF, and #MC handlers a special stack.
This is done by allocating an extra 64 KiB per CPU, and putting it in
the Interrupt Stack Table.
2021-02-15 19:53:37 +01:00
4lDO2 5a638691e0 Treat GS as always pointing to TSS in kernel space. 2021-02-15 19:53:37 +01:00
4lDO2 c913c3be80 Use sysretq in usermode(). 2021-02-15 19:53:24 +01:00
4lDO2 a8dc3fcaf1 Begin using sysretq in the system call handler. 2021-02-15 19:53:01 +01:00
Jeremy Soller 6db78cce24 Use UTF-8 for all paths 2021-02-14 13:45:03 -07:00
Jeremy Soller 11b5e2fe59 Merge branch 'switch_to_safer' into 'master'
Prevent possible UB, and use naked functions correctly.

See merge request redox-os/kernel!167
2021-02-13 22:42:18 +00:00
4lDO2 a706a0dae4 Rewrite signal_handler_wrapper as single asm block.
The reason for these types of rewrites, is that more recent Rust
compilers have started to deprecate naked functions that consist of more
than only a single asm block, as they can trigger all sorts of UB.
2021-02-13 21:55:40 +01:00
4lDO2 47c3b2269f Fix context switching.
Previously there was a triple fault, due to a combination of reasons
(e.g. rsp and rbp being ordered in the struct and in the assembly).

Now, the locks will be held __all the way until the new context__ has
been switched to, which completely eliminates any possibility that the
"pcid fault" originates here.

While I am unsure whether this will work, this could also be an
opportunity to be able to remove CONTEXT_SWITCH_LOCK fully.
2021-02-13 21:55:40 +01:00
4lDO2 ef4270e473 WIP: Attempt to rewrite switch_to in assembly.
This is due to a warning in more recent compilers, which forbid anything
but a single inline assembly block, in naked functions. It does
unfortunately triple fault right now, but I hope I may be able to fix it
soon.
2021-02-13 21:55:36 +01:00
Jeremy Soller c19bd573b5 Switch Context::grants to RwLock 2021-02-13 13:06:13 -07:00
Jeremy Soller 2611985a38 Switch Context::actions to RwLock 2021-02-13 13:01:20 -07:00
Jeremy Soller bfaf8438a1 Switch Context::files to RwLock 2021-02-13 12:57:53 -07:00
Jeremy Soller 55d2467420 Switch Context::cwd to using RwLock 2021-02-13 12:24:19 -07:00
Jeremy Soller cd6ede84fe Fix warnings from futex changes 2021-02-13 12:16:55 -07:00
Jeremy Soller 238702f7d1 Require UTF-8 for context name 2021-02-13 12:16:47 -07:00
Jeremy Soller b9f4a915ea Make context name a RwLock 2021-02-13 11:10:21 -07:00
Jeremy Soller 76d8c1074c Merge branch 'futex-fix' into 'master'
Use physical addresses internally in futex, and fix a context switching data race

See merge request redox-os/kernel!166
2021-02-13 17:52:09 +00:00
4lDO2 6f3fc3a4f4 Make cpu_id_opt non-mutable. 2021-02-03 18:10:39 +01:00
4lDO2 44527a8340 Fix a very annoying multi_core data race*.
So, when I first introduced io_uring, it was not compiled with the
`multi_core` kernel feature, mainly to make development easier (I
thought). However, since io_uring allows multiple simultaneous system
calls, we cannot longer make the in-kernel contexts block, for example
when receiving a message from a pipe, if there can be multiple such
requests simultaneously.

This has required me to change WaitCondition into allowing multiple
simultaneous tasks; although, it introduces a potential race condition:
since a future can only return Pending and not block directly before
releasing the lock (condvar logic), we need some way to make sure that
nothing happens after the context finds out that it has to wait, and the
actual waiting. If a message is pushed in between, and the waker is
called (Context::unblock), just before it was going to block itself,
then we miss the message, and potentially cause a deadlock.

Fortunately, in order to block and unblock contexts, we need to
exclusively lock the context. So, what we can do to ensure that waking
while running is no longer a no-op, is to introduce a "wake flag", which
is set only if the context is currently running, and Runnable.

But, this still caused all weird kinds of hard-to-debug problems, with
arbitrary CPU exceptions and possibly memory corruption. The reason for
this, is that the context switching logic uses really unsafe operations,
which is why context switching (at the moment) requires an exclusive
lock. Before this commit, it would modify the `running` field after the
lock had been released, which obviously can cause a data race, when the
regular context waker code that is run within a system call, locks the
context but not the global switching lock.

The solution was to make sure that the locks were held, all the way
until the actual switching, which was done in assembly. There can still
be a race condition here, since it modifies memory containing registers
after the lock has been released, even if it may be behind &mut on
another context, which can be UB, but it has not contributed to any
actual bugs... yet.

* I have not yet done that rigorous testing, but it appears to work well
enough, and I have not encountered the bug after like 10 tries.
2021-02-03 18:06:42 +01:00
4lDO2 fec8f4aa0c Use physical addresses internally for futexes.
This solves a bug, that allows processes in different address spaces to
be the target of a futex wakeup call, even though that process is in
another address space!
2021-02-03 18:06:42 +01:00
Jeremy Soller 31887bf532 Merge branch 'floating-point-fixups' into 'aarch64-rebase'
Floating point fixups

See merge request redox-os/kernel!165
2021-01-28 17:02:32 +00:00
Robin Randhawa 1e10cac3e1 aarch64: Increase storage for FP context to consider AArch64's needs
Brute-forcing this at present. Would be better to wrap this
conditionally for the architecture.
2021-01-28 16:51:50 +00:00
Robin Randhawa afca6ab31c aarch64: Fix incorrect FP save/restore 2021-01-28 16:50:07 +00:00
Jeremy Soller a06636b77f Update syscall 2021-01-27 10:44:52 -07:00
Jeremy Soller f8f1596f67 Merge branch 'add-floating-point-support' into 'aarch64-rebase'
Add floating point support

See merge request redox-os/kernel!164
2021-01-27 17:43:57 +00:00
Robin Randhawa 4dbfaf3ec1 Nit: Add missing close brace in code comment 2021-01-27 17:19:37 +00:00
Robin Randhawa 1462fe8638 aarch64: context: Align with x86_64 code 2021-01-27 17:17:59 +00:00
Robin Randhawa 3afa0f0895 aarch64: Basic Floating-point/SIMD support 2021-01-27 17:17:11 +00:00
Robin Randhawa 00723c4ac2 aarch64: Make IRQs use the exception macros 2021-01-26 19:37:23 +00:00
Jeremy Soller 9621c64991 Update syscall 2021-01-26 11:46:09 -07:00
Jeremy Soller 81c33a3f6a Merge branch 'aarch64-base' into 'aarch64-rebase'
Misc exception handling fixups

See merge request redox-os/kernel!163
2021-01-26 18:41:53 +00:00
Robin Randhawa 28dfc0f46b aarch64: Basic exception handlers 2021-01-26 18:18:19 +00:00
Robin Randhawa 4a215c7c2c aarch64: exception management and clone fixups 2021-01-26 18:17:09 +00:00
Jeremy Soller fa62b48285 Merge branch 'fixes-for-grant-maps-and-others' into 'aarch64-rebase'
Fixes for grant maps and others

See merge request redox-os/kernel!162
2021-01-22 15:15:08 +00:00
Robin Randhawa 78d1cd1798 syscall: process: empty: Use user-space specific page table 2021-01-21 11:53:35 +00:00
Robin Randhawa 6cacbb47f6 scheme: user: Use user-space specific pagt table 2021-01-21 11:53:07 +00:00
Robin Randhawa 591775874b ptrace: with_context_memory: use user-space specific page table 2021-01-21 11:50:56 +00:00
Robin Randhawa 65448c2d48 aarch64: context: memory: Grant::map_inactive: Bugfix
When mapping one (from) virtual address range to another (to) virtual
address range, be mindful of which mapper type to use for each range.

Before this, the same mapper type was used for both ranges. This meant
that if from and to were different (as in not both kernel virtual
addresses or user virtual addresses) then it would appear that either
from or to was not mapped previously and the kernel would panic.
2021-01-21 11:41:26 +00:00
Robin Randhawa 75870a655f aarch64: context: Add separate kspace and uspace page table getters 2021-01-21 11:40:02 +00:00
Robin Randhawa 3da345867a aarch64: paging: Derive Debug, PartialEq for VirtualAddressType
This makes asserts on VirtualAddressType equality possible.
2021-01-21 11:38:46 +00:00
Robin Randhawa 452196b81f aarch64: consts: Use the same USER_TLS_SIZE as x86_64 2021-01-21 11:37:32 +00:00
Jeremy Soller d76298b3f8 Merge branch 'wip-clone-and-misc-fixes' into 'aarch64-rebase'
Wip clone and misc fixes

See merge request redox-os/kernel!161
2021-01-18 23:00:00 +00:00
Robin Randhawa f1db56f026 aarch64: clone: Further uspace and kspace mods 2021-01-18 21:55:42 +00:00
Robin Randhawa 9429032cec aarch64: clone: Further clone_ret + tpidr_el0 fixes 2021-01-18 21:53:04 +00:00
Robin Randhawa fd0336692d aarch64: clone: Introduce kernel and user space specific mods
At present these are done 'wholesale' without any regard for x86_64.
That needs to change eventually.
2021-01-18 21:50:19 +00:00
Robin Randhawa c188a60871 aarch64: Fix clone_ret
FIXME: Explain the magic numbers here later.
2021-01-18 21:47:28 +00:00
Robin Randhawa 95bd8f2013 clone: Make stack manipulation arch specific 2021-01-17 10:26:49 +00:00
Robin Randhawa ae0aebd036 aarch64: clone: Return from clone syscall
No CLONE_STACK functionality yet.
2021-01-17 10:12:42 +00:00
Robin Randhawa 67ec6c23e7 aarch64: Move tpidr_el0 setup from spawn to switch 2021-01-17 10:09:03 +00:00
Robin Randhawa 67d72532a9 aarch64: usermode: Remove tpidr_el0 manipulation
Was using the incorrect USER_TLS_OFFSET instead of USER_TCB_OFFSET. In
any case, this is better done in process::clone.
2021-01-17 10:06:04 +00:00
Robin Randhawa 3585f620b0 aarch64: clone: Fix incorrect stack offset in clone_ret 2021-01-17 10:03:50 +00:00
Robin Randhawa 208fb681f4 aarch64: vectors: Manage unhandled exceptions
So we can more clearly see when things go wrong.
2021-01-17 10:01:34 +00:00
Jeremy Soller 17fd135017 Merge branch 'pagetabletype-and-misc-fixes' into 'aarch64-rebase'
Pagetabletype and misc fixes

See merge request redox-os/kernel!158
2021-01-15 19:50:13 +00:00
Jeremy Soller e124fa171b Merge branch 'misc-fixes' into 'aarch64-rebase'
Misc fixes

See merge request redox-os/kernel!160
2021-01-15 19:43:23 +00:00
Robin Randhawa 5bc9dea242 aarch64: context::switch: update the CONTEXT_SWITCH_LOCK 2021-01-15 19:03:42 +00:00
Robin Randhawa 6677cfbf1e aarch64: Make interrupt::pause use nop so we can move ahead before interrupts are enabled 2021-01-15 19:02:43 +00:00
Robin Randhawa 825bc4a02d aarch64: spawn: split out arch specific mods 2021-01-15 09:12:30 -07:00
Robin Randhawa 14d79927af aarch64: Add a set_tcb method to setup tpidr_el0 2021-01-15 09:12:30 -07:00
Robin Randhawa ae3a55f5d1 Introduce a PageTableType enum to help distinguish User and Kernel Tables 2021-01-15 09:12:30 -07:00
Robin Randhawa 76129ddf75 aarch64: Mirror PRESENT and VALID bits in Page and Table descriptors 2021-01-15 15:54:25 +00:00
Robin Randhawa c5e077546a aarch64: spawn: split out arch specific mods 2021-01-15 15:51:47 +00:00
Robin Randhawa e0a7471cf8 aarch64: Add a set_tcb method to setup tpidr_el0 2021-01-15 15:50:00 +00:00
Robin Randhawa 9c3f6e3660 Introduce a PageTableType enum to help distinguish User and Kernel Tables 2021-01-15 15:49:04 +00:00
Jeremy Soller bdea7f553a Remove PRESENT flag from aarch64 descriptors 2021-01-15 06:57:02 -07:00
Jeremy Soller 5f8b004476 Fix typo in InterruptStack parameter 2021-01-15 06:56:36 -07:00
Robin Randhawa 252ec24905 aarch64: Use target-feature for NEON insn suppression and tpidr_el1 use 2021-01-15 06:09:42 -07:00
Robin Randhawa aa3839605f aarch64: Remove code-model from the JSON spec
We use a target-feature for this now.
2021-01-15 06:09:42 -07:00
Robin Randhawa ea21fba3aa build.rs: aarch64: Specify target for cc::Build
Oddly, not specifying this or using aarch64-unknown-none (which would be
the default that cc gets from the TARGET environment variable) both
fail to invoke the appropriate compiler to build the asm code.

Using aarch64-unknown-redox works but shouldn't really be needed. This
is perhaps because of some odd arrangement of KTARGET, TARGET, the
installed prefix toolchain and the kernel target JSON spec.

The early_init asm code shall be replaced by a pure Rust bootloader
eventually so let's move with this for the moment.
2021-01-15 06:09:42 -07:00
Robin Randhawa 02c37d3fae WIP: aarch64 rebase 2021-01-15 05:54:42 -07:00
Jeremy Soller 132d91d3aa Fixed page flags for aarch64 2021-01-14 15:54:51 -07:00
Jeremy Soller cb6b44d69e Use devmap offset for physmap on aarch64 2021-01-14 12:35:27 -07:00
Jeremy Soller 1214f3dcdc Add PageFlags to abstract differences between architectures 2021-01-14 10:01:36 -07:00
Jeremy Soller c5774c5529 Add TableKind for future use 2021-01-14 09:16:46 -07:00
Jeremy Soller dafd9cb3c4 Add ENTRY_FLAG_DEFAULT_PAGE and ENTRY_FLAG_DEFAULT_TABLE 2021-01-14 09:16:37 -07:00
Jeremy Soller fad48af985 WIP: aarch64 support 2021-01-13 10:47:35 -07:00
Jeremy Soller 5e10feeaeb Fix whitespace in linker file 2021-01-12 19:59:05 -07:00
Jeremy Soller 6c4c19a95c Move consts to arch 2021-01-12 19:57:42 -07:00
Jeremy Soller ed55b49093 Update aarch64 target to new Rust 2021-01-12 19:57:07 -07:00
Jeremy Soller ea6b1e7f8b Update redox_syscall to 0.2.4 2021-01-11 07:01:05 -07:00
Jeremy Soller 334584b3d5 Use rmm::PhysicalAddress and rmm::VirtualAddress directly 2021-01-09 21:16:11 -07:00
Jeremy Soller ccddabadf7 Make x86 specific dependencies, x86 specific 2021-01-09 20:12:59 -07:00
Jeremy Soller e771e6a4d9 Reduce duplication in context::switch 2020-12-27 20:03:13 -07:00
Jeremy Soller 9033902830 Better messaging about which timer is used 2020-12-23 10:33:09 -07:00
Jeremy Soller 04cc8a2d9c Simplify reserved memory hack 2020-12-23 09:55:03 -07:00
Jeremy Soller 7355ae1671 Hack to ensure kernel is mapped even if it uses reserved memory 2020-12-23 09:46:34 -07:00
Jeremy Soller b1c7b9638d Merge branch 'fix-repr-packed' into 'master'
Fix possible UB by implementing Copy and Clone manually for BuddyEntry.

See merge request redox-os/rmm!1
2020-12-20 16:08:31 +00:00
4lDO2 9a716604fc Implement Copy and Clone manually for BuddyEntry.
This fixes a warning that may in the future become an error, about the
possibility for unaligned references, since the derive macros apparently
rely on creating references to fields. Unaligned references are direct
UB.
2020-12-20 16:36:52 +01:00
Jeremy Soller cff858b455 Merge branch 'rmm' into 'master'
Support for RMM

See merge request redox-os/kernel!155
2020-11-27 16:49:39 +00:00
Jeremy Soller f5ac405db6 Support for RMM 2020-11-27 16:49:39 +00:00
Jeremy Soller cdbeecfffe Remove some warnings 2020-09-14 09:47:29 -06:00
Jeremy Soller 936352a049 FrameCount::new function 2020-09-14 09:47:23 -06:00
Jeremy Soller 8e0df608e2 Add allocator usage information 2020-09-14 09:41:56 -06:00
Jeremy Soller e94d7e7772 Rewrite buddy allocator 2020-09-14 09:41:42 -06:00
Jeremy Soller a775c9e987 Require Arch to implement Clone and Copy 2020-09-14 09:08:28 -06:00
Jeremy Soller a12be1b172 Keep track of last free page 2020-09-09 20:19:28 -06:00
Jeremy Soller f17a1b52bd Test multi-page allocation 2020-09-09 16:02:59 -06:00
Jeremy Soller 0c44dde349 Implement multi-page allocations in buddy allocator (poorly) 2020-09-09 16:02:44 -06:00
Jeremy Soller 711414223b Fix buddy map footer read address 2020-09-09 11:11:39 -06:00
Jeremy Soller fed3110ae8 Better unimplemented messages 2020-09-09 10:55:29 -06:00
Jeremy Soller 811dd09de4 Remove unused function for empty buddy allocator 2020-09-08 20:20:56 -06:00
Jeremy Soller fb88d1669f Add unmap function 2020-09-08 19:59:13 -06:00
Jeremy Soller e6d93d5743 Allow const creation of buddy allocator 2020-09-08 15:51:13 -06:00
Jeremy Soller 5990a04e13 Rename Mapper::active to Mapper:make_current 2020-09-08 15:13:01 -06:00
Jeremy Soller f97a80fecb Flush user table changes 2020-09-08 15:11:26 -06:00
Jeremy Soller e8ea483832 Add page flushing, add support for mapping anonymous pages 2020-09-08 14:56:57 -06:00
Jeremy Soller 6375c175f7 Do not zero tables when not necessary in buddy allocator 2020-09-08 13:52:45 -06:00
Jeremy Soller db7869d995 Add table function for mapper, to get inner page table 2020-09-08 13:52:22 -06:00
Jeremy Soller b4c8ab797d Zero all allocations 2020-09-08 12:41:46 -06:00
Jeremy Soller 8484d4447c Fix compilation using no_std 2020-09-08 11:16:59 -06:00
Jeremy Soller 1b58d2a956 Add FrameCount struct, improve zeroing page performance 2020-09-08 11:13:49 -06:00
Jeremy Soller a64e790471 Fix warnings 2020-09-08 10:54:59 -06:00
Jeremy Soller fcb64422c4 Add FrameAllocator trait, move frame allocator and mapper to library 2020-09-08 10:52:52 -06:00
Jeremy Soller 29945b84b1 no_std building support 2020-09-08 10:24:53 -06:00
Jeremy Soller d153af8b83 Fix calculation of free areas 2020-09-08 10:24:43 -06:00
Jeremy Soller 62da3afef5 Add clearing of freed pages in BuddyAllocator 2020-09-08 09:35:34 -06:00
Jeremy Soller 52a08e70fd Add buddy allocation 2020-09-08 09:27:40 -06:00
Jeremy Soller 57d66236b7 WIP buddy allocator free pages using bitmap 2020-09-07 22:02:52 -06:00
Jeremy Soller 4eb4f579df Set entry when performing allocation 2020-09-07 22:02:24 -06:00
Jeremy Soller 21d7f28fdc Allocate and clear buddy maps 2020-09-07 21:44:23 -06:00
Jeremy Soller d752c5c91e WIP: buddy allocator 2020-09-07 21:05:04 -06:00
Jeremy Soller 011212905d Add WIP slab allocator 2020-09-07 20:01:40 -06:00
Jeremy Soller d450cafad6 Add mapping functionality 2020-09-06 21:07:14 -06:00
Jeremy Soller 03d3264085 Add index_of function to PageTable 2020-09-06 21:06:58 -06:00
Jeremy Soller d9500dc24e Fix excess size of emulated memory, do not print emulated mapping 2020-09-06 21:06:41 -06:00
Jeremy Soller 2dc0853903 Add constants for sizes 2020-09-06 21:06:12 -06:00
Jeremy Soller 4bf43652c3 Only use offset mapping 2020-09-06 14:38:31 -06:00
Jeremy Soller d5111d429e Implement PHYS_OFFSET mapping 2020-09-06 14:30:50 -06:00
Jeremy Soller a40b26293b Do not use explicit register fo x86_64 table operations 2020-09-06 14:20:29 -06:00
Jeremy Soller 379294b59f Implement x86_64 arch functions 2020-09-06 14:18:01 -06:00
Jeremy Soller f801a40908 Add function for addresses 2020-09-06 14:17:49 -06:00
Jeremy Soller 5fc0a080ad Update nightly 2020-09-06 14:17:26 -06:00
Jeremy Soller a482e506c5 Use physical and virtual address abstraction for arch functions 2020-09-06 13:58:40 -06:00
Jeremy Soller ab07997bbe Add derives for physical and virtual addresses 2020-09-06 13:55:38 -06:00
Jeremy Soller 8efc425b07 Add phys_to_virt function 2020-09-06 13:54:58 -06:00
Jeremy Soller 023bb5811a Add definition of physical address size 2020-09-06 13:25:21 -06:00
Jeremy Soller 2df212f48d Add tests to ensure correct constant calculation 2020-09-06 13:00:01 -06:00
Jeremy Soller f5e8c031ca Move constants into Arch trait 2020-09-06 08:30:56 -06:00
Jeremy Soller 8c8e09d23e Refactor, use trait for arch differences 2020-09-05 21:02:27 -06:00
Jeremy Soller 58323aadd0 Implement recursive mapping 2020-09-05 19:00:32 -06:00
Jeremy Soller 556b777386 Define for page levels, enable recursive mapping by default 2020-09-04 21:19:57 -06:00
Jeremy Soller adad6bbe65 Add recursive mapping 2020-09-04 21:07:31 -06:00
Jeremy Soller a55e19868e Add abstraction for page table 2020-09-04 20:56:48 -06:00
Jeremy Soller a70bc00264 Improve machine read/write functions 2020-09-04 15:42:42 -06:00
Jeremy Soller 048298d65b Add README.md 2020-09-04 21:24:43 +00:00
Jeremy Soller 21dc9624d7 Add LICENSE 2020-09-04 21:23:23 +00:00
Jeremy Soller e7ae8e6812 init 2020-09-04 15:22:35 -06:00
Jeremy Soller 8b27de416b Update Cargo.lock 2020-08-27 10:26:56 -06:00
Jeremy Soller afa175f778 Merge branch 'jD91mZM2/kernel-remove-brk' into HEAD 2020-08-27 10:26:29 -06:00
Jeremy Soller 1baeb5a891 Format memory entries using hex 2020-08-27 09:43:39 -06:00
Jeremy Soller 8211e92c02 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/kernel 2020-08-27 09:43:23 -06:00
Jeremy Soller 858dd6ef51 Update syscall 2020-08-27 09:43:15 -06:00
Jeremy Soller 45b48f8078 Merge branch 'fix-deprecate' into 'master'
Fix printing of deprecation warning

See merge request redox-os/kernel!151
2020-08-27 15:33:12 +00:00
Jeremy Soller 853b77e3a4 Unmap owned grants, use owned grants to calculate memory usage 2020-08-25 10:35:55 -06:00
Jeremy Soller 4e3df8b953 Merge branch 'aj-chdir-initfs-message' into 'master'
Add more descriptive error message for when initfs chdir fails

See merge request redox-os/kernel!150
2020-08-17 16:25:46 +00:00
Jeremy Soller 6ba3850042 Merge branch 'aj-logging' into 'master'
Use logging instead of println in src/lib.rs

See merge request redox-os/kernel!149
2020-08-17 16:18:08 +00:00
jD91mZM2 5fc6acacc4 Fix printing of deprecation warning 2020-08-17 15:25:14 +02:00
Aaron Janse dc6132dc06 elaborate error message for initfs chdir failure 2020-08-17 03:24:56 -07:00
Aaron Janse dfcf5be778 use logging instead of println 2020-08-17 02:55:40 -07:00
jD91mZM2 922b3d0437 Remove brk 2020-08-15 17:36:50 +02:00
Jeremy Soller 0590a71b87 Merge branch 'mynameissherlockholmes' into 'master'
Investigate why user heap isn't mapped

See merge request redox-os/kernel!147
2020-08-15 15:27:33 +00:00
jD91mZM2 da7b813fa9 Investigate why user heap isn't mapped
Took me way too long to spot this :D
2020-08-15 17:22:34 +02:00
Jeremy Soller e3814c1ca2 Merge branch 'deprecate-stuff' into 'master'
Deprecate the original fmap/funmap

See merge request redox-os/kernel!146
2020-08-14 15:20:36 +00:00
jD91mZM2 78e5c71103 Deprecate the original fmap/funmap
The cool thing here is that we're temporarily binary compatible with the
old stuff, so if anyone would use an old version of redox_syscall we can
easily find them with these prints.
2020-08-14 15:18:47 +02:00
Jeremy Soller 2057b889ae Merge branch 'log_experiment' into 'master'
Log experiment

See merge request redox-os/kernel!144
2020-08-09 13:01:39 +00:00
Wren Turkal 4c009530a8 Make x86_64 log writer not use println!.
This opens the door to completely elimnating println! usage from the
kernel.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-09 00:00:26 -07:00
Wren Turkal 5301057324 Convert some println -> log::info!.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 21:18:18 -07:00
Wren Turkal dafd2e9f98 Add a way to customize how logging is done.
Each architecture may have a different method to enable logging. Now
that can be customized with a function passed to the init_logger
function.

Also, provide a minimal x86_64 implementation.

This is the first commit where you can see logging coming from the log
crate.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 21:18:15 -07:00
Wren Turkal 29a9592e7b Re-export log::set_max_level.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:50:55 -07:00
Wren Turkal 50675842af Add logger init and initialize on x86_64.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:50:53 -07:00
Wren Turkal 03e60f7da6 Add log crate and add a generic logger.
This is the first step of integrating the log crate as the main way to
log messages from the kernel.

Also, reexport all log macros. This module should eventually be the
only logging API used in the kernel.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:48:41 -07:00
Jeremy Soller d8a0a8182d Merge branch 'add_debug_to_structs' into 'master'
Implement Debug for a couple structs.

See merge request redox-os/kernel!142
2020-08-08 12:55:53 +00:00
Jeremy Soller ad6035c7de Merge branch 'idiomatic-rust' into 'master'
Replace llvm_asm with asm

See merge request redox-os/kernel!141
2020-08-03 15:09:08 +00:00
jD91mZM2 bdc504f862 Update redox_syscall again 2020-08-03 16:08:15 +02:00
Wren Turkal efb5b47463 Implement Debug for a couple structs.
I am finding it useful to be able to pretty print Mappers and
ActivePageTable structs.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-02 22:13:24 -07:00
Jeremy Soller 1a8f47330e Add a message when user heap is not mapped, do not panic 2020-08-02 17:07:57 -06:00
Jeremy Soller ec1809e7c0 Add memory: to null namespace, temporarily 2020-08-02 17:05:17 -06:00
Jeremy Soller 6f3094cb2b Work around unmapping user heap 2020-08-02 16:33:56 -06:00
Jeremy Soller 220e53c24d Show CPU and PID in kernel panic 2020-08-02 12:12:59 -06:00
jD91mZM2 9ab778d649 Update redox_syscall 2020-08-01 16:53:39 +02:00
jD91mZM2 f07603902d Replace all llvm_asm! uses with asm! 2020-08-01 14:56:46 +02:00
Jeremy Soller c8263cc4bd Merge branch 'latest-rust' into 'master'
Support latest rust

See merge request redox-os/kernel!140
2020-08-01 12:22:17 +00:00
jD91mZM2 895c0c11da Use cargo for lto over manually entering rustflags 2020-08-01 13:19:12 +02:00
jD91mZM2 fbeb297949 Fix compilation since last rust
Thanks to @4lDO2 for all this. I just moved his changes to io_uring onto
the master branch of the kernel. I take no credit.
2020-08-01 13:00:52 +02:00
jD91mZM2 93856b43b9 s/\basm!/llvm_asm!/g 2020-08-01 12:31:56 +02:00
Jeremy Soller c8fb3792a9 Merge branch 'memory' into 'master'
Implement funmap2

See merge request redox-os/kernel!139
2020-07-30 13:36:59 +00:00
jD91mZM2 877259257c Update syscall submodule 2020-07-30 15:05:46 +02:00
jD91mZM2 55c3377c5c Use VirtualAddress wrapper in user.rs 2020-07-30 14:21:57 +02:00
jD91mZM2 3fca287bcc Remove debug prints 2020-07-30 13:21:17 +02:00
jD91mZM2 34194e2b79 Implement partial funmap-ing for user schemes 2020-07-30 13:08:03 +02:00
jD91mZM2 0ffa9b0be6 Track region instead of address in user.rs 2020-07-30 11:42:49 +02:00
jD91mZM2 9eb2aebd43 Implement unmapping multiple whole maps 2020-07-28 11:34:50 +02:00
jD91mZM2 639e603c4f WIP: Add funmap2 2020-07-25 22:29:21 +02:00
jD91mZM2 a811774c58 Add necessary functions for funmap2 2020-07-23 16:45:35 +02:00
jD91mZM2 ccc577b3a1 Abstract over finding nice addresses 2020-07-23 11:22:54 +02:00
jD91mZM2 57c167d2fa Make grants be a BTreeSet 2020-07-22 15:09:28 +02:00
Jeremy Soller 2f94031221 Merge branch 'auxv' into 'master'
Implement auxiliary vector

See merge request redox-os/kernel!136
2020-07-21 14:16:05 +00:00
jD91mZM2 9c41424d3a Apply suggestion to src/syscall/process.rs 2020-07-21 14:10:58 +00:00
jD91mZM2 2782a5a7a9 Apply suggestion to src/syscall/process.rs 2020-07-21 14:10:43 +00:00
jD91mZM2 5dc65a920f Add restrictions on fmap 2020-07-21 16:08:28 +02:00
jD91mZM2 cf709783d6 Reverse mod/syscall.rs 2020-07-20 11:17:36 +02:00
jD91mZM2 07baf70c7a Don't push interpreter as argv[0] 2020-07-20 11:09:56 +02:00
Jeremy Soller 854149ee97 Support for debugging to system76 EC 2020-07-19 10:24:15 -06:00
jD91mZM2 ff5354b5b5 Fix mmap when using out-of-place address 2020-07-18 15:03:23 +02:00
jD91mZM2 2d63009ba4 Add debug entry for fmap2 2020-07-18 13:40:12 +02:00
jD91mZM2 310a425c65 Merge branch 'master' into auxv 2020-07-18 12:19:11 +02:00
jD91mZM2 615e516585 Add extra assembler metadata 2020-07-16 17:13:30 +02:00
jD91mZM2 11f26140f5 Fix most MR concerns 2020-07-16 16:59:58 +02:00
jD91mZM2 895a4a5656 Deprecate int 0x80
Mainly because I think the code could be cleaner if we can remove
support entirely :)
2020-07-16 16:33:25 +02:00
jD91mZM2 4fbe86a9ce Fix random userspace page faults
I was an idiot and forgot rbx wasn't always backed up. As a result, we
should never ever write to it
2020-07-16 16:32:48 +02:00
jD91mZM2 acebd1a8d1 Merge remote-tracking branch 'origin/master' into global-asm 2020-07-16 15:35:42 +02:00
jD91mZM2 b00456dbb9 WIP: Continue trying to fix clone_ret 2020-07-16 13:46:53 +02:00
Jeremy Soller c78b69969f Include trampoline in kernel to fix multi_core on EFI 2020-07-15 21:46:15 -06:00
Jeremy Soller 1e44f157d0 Fix graphical_debug feature 2020-07-15 16:10:51 -06:00
jD91mZM2 145c1898be Merge branch 'master' into global-asm 2020-07-15 12:05:34 +02:00
jD91mZM2 3bb234009a WIP: Ensure clone_ret correctness 2020-07-15 11:43:17 +02:00
Jeremy Soller 93303af931 Merge branch 'catch-kernel-signal' into 'master'
Catch kernel signal

See merge request redox-os/kernel!135
2020-07-14 12:53:46 +00:00
Jeremy Soller 6b2302f92e Merge branch 'paging-packed-use-unsafe' into 'master'
Wrap borrows of page table entries in unsafe

See merge request redox-os/kernel!126
2020-07-14 12:53:21 +00:00
jD91mZM2 ca3ddcdeca Add TODOs for mapping PTI properly
I think we need to reimplement these functions in assembly :(
2020-07-14 09:14:16 +02:00
jD91mZM2 701c31cee0 Fix PTI compilation
It's broken on master anyway
2020-07-13 15:49:37 +02:00
jD91mZM2 5927743ff8 fixup! WIP: Rewrite interrupts as global assembly 2020-07-13 15:25:15 +02:00
jD91mZM2 aa3279455d Merge branch 'master' into auxv 2020-07-13 12:48:48 +02:00
jD91mZM2 ec2c42dc66 WIP: Work around fmap quirks 2020-07-13 12:48:29 +02:00
jD91mZM2 fbdfcd2ba0 WIP: Rewrite interrupts as global assembly
Because the way we were using inline assembly was technically incorrect
and breaking the laws of rust

This *finally* compiles. That doesn't mean it works!
2020-07-11 16:15:25 +02:00
jD91mZM2 4b8d2e45c6 Add AT_PHDR 2020-07-10 12:56:08 +02:00
jD91mZM2 3430eadc9a Add auxiliery vector 2020-07-10 12:34:32 +02:00
Jeremy Soller dbfc8ab188 Merge branch 'no_mprotect_crashes' into 'master'
Don't panic on mprotect for unmapped pages

See merge request redox-os/kernel!134
2020-07-09 12:01:33 +00:00
bjorn3 7b76ab3356 Don't panic on mprotect for unmapped pages 2020-07-09 11:03:02 +02:00
4lDO2 01041a5d8a Implement (mostly) fmap2 for memory: 2020-07-08 20:49:16 +02:00
jD91mZM2 56f55a3b97 Always save proccess registers
Not sure if this is going to be required, and I'm not sure if this will
hurt performance, y'know, *always* doing this.
2020-07-08 11:47:12 +02:00
jD91mZM2 103ed1b17f Make interrupt stack readable on kernel signals 2020-07-08 11:44:04 +02:00
Jeremy Soller 92cad589d9 Merge branch 'moar-gdb' into 'master'
Simplify EXEC catching + add signal handling

See merge request redox-os/kernel!132
2020-07-07 12:49:16 +00:00
jD91mZM2 184824234e Update submodule 2020-07-07 14:47:21 +02:00
jD91mZM2 039f7f5c83 Simplify EXEC catching
Instead of having a separate flag, let's reuse STOP_SINGLESTEP :)

I wasn't thinking enough when making this flag!
2020-07-07 14:16:42 +02:00
jD91mZM2 cdcb34486b Keep singlestep across signals 2020-07-07 13:32:10 +02:00
Jeremy Soller 77f3a17c14 Fix warnings in live: 2020-06-30 09:36:19 -06:00
Jeremy Soller d82eb57e9c Update live: to new seek function 2020-06-30 09:08:55 -06:00
Jeremy Soller 7989aa0327 Merge branch 'signed-seek' into 'master'
change seek sig to match posix - signed pos and result

See merge request redox-os/kernel!123
2020-06-27 13:26:53 +00:00
Graham MacDonald af63c9773c Merge remote-tracking branch 'origin/master' into signed-seek 2020-06-27 14:20:51 +01:00
Graham MacDonald 2d8b2d94b9 hopefully update syscall submodule 2020-06-27 14:10:15 +01:00
Jeremy Soller 35ca4c221e Merge branch 'proc-fexec' into 'master'
Changes required for GDB

See merge request redox-os/kernel!131
2020-06-25 13:06:45 +00:00
jD91mZM2 fed36d49e3 Bump submodule 2020-06-25 15:04:49 +02:00
jD91mZM2 4701838118 Fix RIP register on int3 2020-06-23 19:47:44 +02:00
jD91mZM2 7fc49eed74 ptrace: Allow stopping on fexec 2020-06-22 13:11:32 +02:00
Graham MacDonald aa1b11cc8a move calc_seek_offset* to syscall 2020-06-19 23:53:30 +01:00
Graham MacDonald 01f95b644d change seek sig to match posix - signed pos and result 2020-06-19 23:31:55 +01:00
jD91mZM2 e18a877995 Implement proc:<pid>/exe for getting exe name 2020-06-17 19:06:48 +02:00
Jeremy Soller fcea6e06dd Merge branch 'complex-physalloc' into 'master'
More complex physalloc

See merge request redox-os/kernel!127
2020-06-16 21:20:00 +00:00
4lDO2 003bd6a0d2 More complex physalloc 2020-06-16 21:20:00 +00:00
Jeremy Soller 654c0a7bbc Merge branch 'ptrace-sane-block' into 'master'
Ptrace sane block

See merge request redox-os/kernel!129
2020-06-16 12:10:47 +00:00
Jeremy Soller 484f4c13fe Merge branch 'moar-ptrace' into 'master'
Misc ptrace cleanup

See merge request redox-os/kernel!128
2020-06-16 12:09:26 +00:00
jD91mZM2 edcc39929d Fix unused import
I added that assert, because I managed to get an error I couldn't reproduce
2020-06-16 13:58:36 +02:00
jD91mZM2 9c891384ea Fix ptrace returning ENODEV when process exists 2020-06-16 13:42:04 +02:00
jD91mZM2 cbb17327aa ptrace: Block on read, not on write 2020-06-16 13:00:27 +02:00
jD91mZM2 12f632837a Misc proc code cleanup 2020-06-16 10:08:49 +02:00
jD91mZM2 4effb97c04 fixup! Fix acid test-bench issues 2020-06-16 09:28:42 +02:00
jD91mZM2 727217ad42 Fix acid test-bench issues 2020-06-15 17:14:52 +02:00
jD91mZM2 3420339c04 proc scheme: Rewrite try_stop_context 2020-06-15 15:08:59 +02:00
jD91mZM2 75872cc5f8 ptrace: Fix WaitCondition mutex 2020-06-13 16:05:57 +02:00
4lDO2 1c0e6c253f Fix test. 2020-06-11 16:11:46 +02:00
4lDO2 8117119d8e Wrap borrows of page table entries in unsafe.
This is safe because `Entry` is `#[repr(8)]` which is the minimum
alignment for qwords. Since the size of a qword is equal to that
alignment (8), they can also be borrowed from the array.
2020-06-11 16:05:00 +02:00
Jeremy Soller 5d53c65f0b Merge branch 'resolve-kernel-warnings' into 'master'
Fix various kernel warnings.

See merge request redox-os/kernel!125
2020-06-11 13:18:58 +00:00
Jeremy Soller b90233bc30 Merge branch 'paging-repr-packed' into 'master'
Use #[repr(packed)] with correct alignment for paging.

See merge request redox-os/kernel!124
2020-06-11 13:17:51 +00:00
4lDO2 e7d00d4735 Fix various kernel warnings. 2020-06-11 12:58:03 +02:00
4lDO2 c7b207f4dc Use #[repr(packed)] with correct align for paging. 2020-06-11 11:58:58 +02:00
Jeremy Soller 93e0db1aa3 Merge branch 'noacpi-fix' into 'master'
Fix conditional compilation without the acpi feature.

See merge request redox-os/kernel!122
2020-05-22 11:38:16 +00:00
4lDO2 3289b95a7a Fix conditional compilation without acpi feature. 2020-05-22 10:21:22 +02:00
Jeremy Soller 30b109d288 Update dependencies 2020-05-06 09:05:58 -06:00
Jeremy Soller 4245dff4d8 Merge branch 'separate-idt' of gitlab.redox-os.org:4lDO2/kernel 2020-05-06 08:58:10 -06:00
4lDO2 0585c2b4d9 Make the IDTs of APs visible to irq:. 2020-05-03 16:57:32 +02:00
4lDO2 9232736bf1 Rename some things, and fix a map insertion. 2020-05-03 16:57:32 +02:00
4lDO2 f4246deabf WIP: Use a different IDT for each processor. 2020-05-03 16:57:32 +02:00
4lDO2 0d1ca687fb Use the correct interrupt method for spurious IRQs. 2020-05-03 16:57:03 +02:00
4lDO2 1165445602 Add spurious IRQ handling, using a visible counter. 2020-05-03 16:56:50 +02:00
Jeremy Soller dd4e82f4ce Merge branch 'cpuid' into 'master'
bump raw-cpuid dep to avoid pulling in serde

See merge request redox-os/kernel!121
2020-05-02 17:41:05 +00:00
Graham MacDonald 0614d3298d bump raw-cpuid dep to avoid pulling in serde 2020-05-02 14:11:23 +01:00
Jeremy Soller 582e3fd8eb Unlock CONTEXT_SWITCH_LOCK after loading registers but before switch 2020-04-21 21:03:17 -06:00
Jeremy Soller c79f308f07 Unlock CONTEXT_SWITCH_LOCK after switch happens 2020-04-21 20:45:15 -06:00
Jeremy Soller 0bfd830f3c Work around spurious nanosleep wakes 2020-04-20 21:08:56 -06:00
Jeremy Soller dd0633a3d2 Kernel reading of ps2 bytes 2020-04-20 13:10:06 -06:00
Jeremy Soller 2fa85ed303 Remove unused import 2020-04-19 21:47:58 -06:00
Jeremy Soller fa58651b70 Add serio scheme, based on debug scheme, for supporting ps2 devices 2020-04-19 21:40:12 -06:00
Jeremy Soller 5fd8f0430b Cleanup debug scheme 2020-04-19 21:39:53 -06:00
Jeremy Soller 02abd58c10 Merge branch 'multi_core' into 'master'
Multi core

See merge request redox-os/kernel!118
2020-04-19 20:28:15 +00:00
Jeremy Soller e528aa8fdc Fix order of masking IRQ and eoi 2020-04-19 10:50:03 -06:00
Jeremy Soller abf971eaee Only require alignment of 4 bytes for rsdp 2020-04-19 08:49:42 -06:00
Jeremy Soller 315343be41 Add a way to snapshot context state 2020-04-19 08:46:50 -06:00
Jeremy Soller 123918ed43 Track the namespace that a description was opened from 2020-04-19 08:46:50 -06:00
Jeremy Soller 051a275c94 Remove unused import 2020-04-19 08:46:50 -06:00
Jeremy Soller 3c86af57b7 Allow contexts sharing process space to run on different CPUs 2020-04-19 08:46:50 -06:00
Jeremy Soller fdf46d8043 Fix multi_core livelocks and add livelock debugging 2020-04-19 08:46:50 -06:00
Jeremy Soller 9d67e3dc28 Merge branch 'ioapic' into 'master'
Support the I/O APIC alongside the 8259 PIC

See merge request redox-os/kernel!117
2020-04-19 13:02:42 +00:00
4lDO2 9413475119 Don't use the I/O APIC by default,
since this would require pcid to know the _PRT (PCI routing table) to
use and map the interrupt pins to the correct IRQs. xhcid is unaffected
by this though, since it uses MSI-X.

All ACPI handling will be done in userspace before the infrastructure
necessary would make sense (I don't think adding serde to the kernel
would be optimal, and how else would all of the ACPI namespace be
parsed?).
2020-04-19 13:25:43 +02:00
4lDO2 00312bdf32 Revert to old default-features. 2020-04-19 13:21:59 +02:00
4lDO2 3bc4b9a691 Allow the MADT to be read from userspace,
and fix a typo that prevented multiple tables from being listed
correctly.
2020-04-19 09:41:42 +02:00
4lDO2 02ca8edfc5 Execute AML code after IOAPIC init,
which tells the firmware that the I/O APIC is used rather than the 8259
PIC.
2020-04-19 09:41:40 +02:00
4lDO2 8c351e0768 Use the I/O APIC when applicable. 2020-04-19 09:41:09 +02:00
4lDO2 45fe040625 rustfmt. 2020-04-19 09:39:57 +02:00
4lDO2 d1ece2c811 Add a basic acpi: scheme, currently only for MCFG. 2020-04-19 09:39:57 +02:00
4lDO2 dc3452650c Execute AML code after IOAPIC init,
which tells the firmware that the I/O APIC is used rather than the 8259
PIC.
2020-04-18 23:17:37 +02:00
4lDO2 290098b5a4 impl Debug for AmlValue. 2020-04-18 18:21:04 +02:00
4lDO2 5490de9fd2 Fix a page fault. 2020-04-18 17:33:03 +02:00
4lDO2 de4b66150d Remove unnecessary kernel args. 2020-04-18 17:06:45 +02:00
4lDO2 f0b5d51793 Use the I/O APIC when applicable. 2020-04-18 16:36:18 +02:00
4lDO2 da6de394e4 Add a new backwards-compatible v2 boot protocol. 2020-04-18 11:28:11 +02:00
Jeremy Soller 5d4aa75133 Merge branch 'schemes-no-arc-box' into 'master'
Replace Arc<Box<dyn Scheme>> with Arc<dyn Scheme>.

See merge request redox-os/kernel!116
2020-04-11 12:09:20 +00:00
4lDO2 0e2e515dbd Replace Arc<Box<dyn Scheme>> with Arc<dyn Scheme>. 2020-04-11 12:29:35 +02:00
Jeremy Soller 0ccf3b4e53 Merge branch 'lapic' into 'master'
Extend the IRQ scheme to allow allocation of all available interrupt vectors.

See merge request redox-os/kernel!115
2020-04-04 12:54:44 +00:00
4lDO2 0fd24f6061 Cleanup. 2020-04-04 10:57:00 +02:00
4lDO2 b716ec4bc1 Remove currently unused APIC timer code. 2020-03-28 13:37:03 +01:00
4lDO2 d23ed0cfc3 Remove debug local APIC functions. 2020-03-28 13:37:03 +01:00
4lDO2 157a3e5c0d Improve MSI. 2020-03-28 13:37:03 +01:00
4lDO2 772003138d Add a backwards-compatible interface for more IRQs. 2020-03-28 13:37:03 +01:00
4lDO2 c154effd1c Get a working local apic timer. 2020-03-28 13:37:03 +01:00
4lDO2 c11d6d9e46 Update the x86 crate. 2020-03-28 13:37:03 +01:00
4lDO2 65e8abb449 Allow multiple processes to share IRQs.
I haven't been able to receive xhc interrupt anyway.
2020-03-28 13:37:03 +01:00
Jeremy Soller 53570f0164 Merge branch 'fix-warnings' into 'master'
Fix warnings

See merge request redox-os/kernel!114
2020-03-06 20:46:01 +00:00
Skallwar ae14eda866 Run rustfmt 2020-03-06 21:05:26 +01:00
Skallwar b82f596ef6 Fix unnecessary syntax 2020-03-06 21:02:20 +01:00
Skallwar 7671e92216 Fix borrow of packed field 2020-03-06 21:01:18 +01:00
Jeremy Soller b616fdb067 Keep track of ticks each context uses 2020-02-18 21:16:53 -07:00
Jeremy Soller d4d14c78c3 Ensure page table locking at runtime 2020-02-12 20:34:49 -07:00
Jeremy Soller b892603501 Require mutable context to perform page table modifications 2020-02-10 17:58:44 -07:00
Jeremy Soller 7721a0a4c6 Fix assignment of cpu_id 2020-02-09 11:05:02 -07:00
Jeremy Soller d42c1ba14e Remove unused feature 2020-02-09 09:50:48 -07:00
Jeremy Soller 388ab2c87d option -> opt 2020-02-09 09:50:40 -07:00
Jeremy Soller aec92c1617 Make PIT_TICKS thread_local 2020-02-09 09:49:49 -07:00
Jeremy Soller c860322cfc Merge branch 'master' of https://gitlab.redox-os.org/redox-os/kernel 2020-02-07 20:06:39 -07:00
Jeremy Soller 7658193271 Remove some warnings 2020-02-07 20:06:33 -07:00
Jeremy Soller 8eaa809b29 Merge branch 'master' into 'master'
Update README's debugging instructions

See merge request redox-os/kernel!113
2020-01-26 01:12:22 +00:00
Joshua Abraham 4a4d8601d1 Update README's debugging instructions 2020-01-25 20:03:57 -05:00
Jeremy Soller 64f962e02b Merge branch 'master' into 'master'
Fix deadlock in sys: scheme

See merge request redox-os/kernel!112
2020-01-25 23:07:24 +00:00
Joshua Abraham 6a48ae3d8b Fix deadlock in sys: scheme
This patch fixes a deadlock in the sys: scheme that is triggered
when the iostat resource() is called in the same scope where the RwLock
protecting the scheme's handles is write-locked.
2020-01-25 17:39:51 -05:00
Jeremy Soller 57a6359333 Do not add newline to sys:exe 2019-12-22 18:23:36 -07:00
Jeremy Soller 72ea559da4 Do not log mprotects 2019-12-06 19:59:18 -07:00
Jeremy Soller e13107b441 Remove warning 2019-11-13 19:41:34 -07:00
Jeremy Soller f7f4013cf0 Do not use COM3 or COM4 2019-11-13 19:39:45 -07:00
Jeremy Soller 90b113f047 Add lpss_debug 2019-11-13 19:33:21 -07:00
Jeremy Soller 331590e129 Support COM3 and COM4 2019-11-01 20:35:02 -06:00
Jeremy Soller c27a6c149b Support SerialPort<Mmio<u32>> 2019-11-01 20:34:03 -06:00
Jeremy Soller 752138de1d Merge branch 'nanosleep' into 'master'
implement remainder for nanosleep

See merge request redox-os/kernel!110
2019-10-08 19:01:15 +00:00
Timothy DeHerrera f75e1c4802 implement remaninder for nanosleep 2019-10-08 11:54:02 -06:00
Jeremy Soller af93866c41 Add more clippy lints 2019-10-06 11:15:01 -06:00
Jeremy Soller 63e2a835e0 Fix clippy.sh script and fix a number of clippy warnings 2019-10-06 11:04:06 -06:00
Jeremy Soller a57ea6a72b Merge branch 'ptrace-end' into 'master'
Final few ptrace changes

See merge request redox-os/kernel!109
2019-08-21 21:00:13 +00:00
jD91mZM2 ab1a12ad4a Remove deadlock-prone mutex in proc.rs
I believe this could cause a deadlock if a blocking I/O operation was
interrupted by a signal or otherwise, and decided to exit and close
all files. It's unlikely to happen, but it can happen nontheless. This
removes the mutex, but it's difficult to keep the code tidy. Hopefully
this is good enough.
2019-08-15 16:07:38 +02:00
jD91mZM2 cf0a7620df Add ptrace exit breakpoint
This will let you stop at process exit and inspect it right before the
process dies.
2019-08-15 14:23:54 +02:00
jD91mZM2 070f1fa913 Delete ptrace-related TODO 2019-08-15 12:26:29 +02:00
jD91mZM2 2544feb33f Disallow changing CS which contains CPL 2019-08-15 12:26:29 +02:00
Jeremy Soller 6160de495f Make multi_core require acpi 2019-08-12 19:33:50 -06:00
Jeremy Soller 3694395dfb Fix compilation of acpi feature 2019-08-12 19:33:03 -06:00
Jeremy Soller 8c6e1d0541 Update syscall 2019-07-31 18:30:57 -06:00
Jeremy Soller d28b578681 Merge branch 'ptrace-6' into 'master'
Ptrace overhaul & bitflags

See merge request redox-os/kernel!107
2019-07-31 20:29:54 +00:00
jD91mZM2 40449d32b5 Allow catching int3 2019-07-31 16:43:49 +02:00
jD91mZM2 ad5f3814fa Add way to ignore signals 2019-07-30 15:54:25 +02:00
jD91mZM2 62cd298202 Merge ProtFlags with MapFlags 2019-07-30 11:45:54 +02:00
jD91mZM2 a7b2bd22c1 More cleanup... 2019-07-27 15:39:09 +02:00
jD91mZM2 538ca49ee2 Suggestion: Switch to bitflags 2019-07-26 12:23:21 +02:00
jD91mZM2 0e2b0d0fd4 Fix a few details 2019-07-26 10:29:31 +02:00
jD91mZM2 3ac1416dba First step for ptrace overhaul 2019-07-24 21:42:33 +02:00
Jeremy Soller e95cb74d0b Resolve cross-scheme links 2019-07-23 21:06:16 -06:00
Jeremy Soller e570f35279 Update syscall 2019-07-23 20:04:43 -06:00
Jeremy Soller 3533cb3757 Merge branch 'ptrace-5' into 'master'
Drive ptrace into a wall, prepare for overhaul

See merge request redox-os/kernel!106
2019-07-24 02:04:06 +00:00
jD91mZM2 1137692809 WIP(ptrace): Allow setting RIP 2019-07-23 19:55:11 +02:00
jD91mZM2 a7da393cf5 WIP(ptrace): Better support for signals
Signals now cause an event, and there's a way to continue until the
next signal. I can see this being used for detection of `int3`
although I'm not entirely sure as it may prove being too late to stop
abortion of process.
2019-07-21 19:58:32 +02:00
jD91mZM2 7426e48105 WIP(ptrace): Extract repeated arch-specific code to ptrace module 2019-07-21 13:28:31 +02:00
jD91mZM2 4c2d8599d8 Add missing debug definitions
See [strace-redox#ea42589d](https://gitlab.redox-os.org/redox-os/strace-redox/commit/ea42589d36923e9c018a4d802a5cd0c3449d0e6c)
2019-07-21 10:06:28 +02:00
jD91mZM2 6a3825d408 WIP(ptrace): Only use non-signal stack when using a default handler
This is a curious problem and it's really hard to solve it in a way
that doesn't feel hacky. On one hand, of course you want to be able to
modify and intercept what happens when you use a signal, right? On the
other hand, changes made to the context (especially singlestepping)
while a signal is handled (such as `SIGSTOP`) are not preserved since
the stack is restored after the signal handler was invoked.

I think what we have in this change makes sense anyway, as we don't
really want users modifying registers and other data in the default
signal behavior that occurs **in kernel mode**. Also trying to use
`PTRACE_SINGLESTEP` will set the singlestep flag only if in a
user-mode signal handler, else it will set it on the instruction after
the signal handling, which I guess makes sense since it can't affect
the kernel-mode code that runs the default handler.

I don't know. Help. Pls.
2019-07-20 22:45:33 +02:00
jD91mZM2 8695ecd82b Fix sigaction Undefind Behavior
Rust does not allow a `fn`-pointer to be null. This fixes that, while
luckily doing it in a way that leaves system calls
backwards-compatible :)
2019-07-20 22:41:54 +02:00
jD91mZM2 be867ae5f1 WIP(ptrace): Add ptrace event system for catching child forks 2019-07-20 09:45:07 +02:00
jD91mZM2 3d44242407 WIP(ptrace): Finally add stronger security checks 2019-07-20 09:45:07 +02:00
jD91mZM2 e3d8f23c71 WIP(ptrace): Add dbg! macro and fix waitpid immediately after exit 2019-07-20 09:45:01 +02:00
Jeremy Soller 532ffe25cf Unmounting support 2019-07-18 21:00:36 -06:00
Jeremy Soller 113af69434 Remove scheme if closed 2019-07-18 20:58:06 -06:00
Jeremy Soller 4b2c15f0b9 Remove scheme by ID 2019-07-18 20:57:51 -06:00
Jeremy Soller 5af7f71a99 Fix warning 2019-07-18 20:57:41 -06:00
Jeremy Soller 5a42b6dd76 Add notify_signal method to WaitCondition to simulate being woken by a signal 2019-07-18 19:48:54 -06:00
Jeremy Soller 76e0ed2e37 Make all wait_map members public 2019-07-18 19:48:27 -06:00
Jeremy Soller bfc559a8a7 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/kernel 2019-07-14 11:17:52 -06:00
Jeremy Soller 6e8729bac2 Disable RTC NMI and do not wait for an entire update cycle before reading time 2019-07-14 11:17:45 -06:00
Jeremy Soller cbc892d1d5 Merge branch 'ptrace-3' into 'master'
Ptrace memory reading and floating point registers support

See merge request redox-os/kernel!104
2019-07-07 17:07:05 +00:00
jD91mZM2 6fbb4fbae1 Ptrace memory reading and floating point registers support 2019-07-07 17:07:04 +00:00
Jeremy Soller 788526a3b3 Bare-bones ptracing functionality
Since even a very basic ptrace can be nice to have, I thought I would split
the, perhaps rather big, ptrace project up in multiple PRs to make as few
changes as necessary in each. This PR contains the initial registry modifying
bits and only a very basic security measure. Letting this out to the community
should be good for spotting bugs and maybe getting some hype ;)
2019-07-02 07:38:26 -06:00
Jeremy Soller 45ea634798 Revert "Merge branch 'ptrace' into 'master'"
This reverts merge request !103
2019-07-02 11:56:11 +00:00
Jeremy Soller 527353d377 Merge branch 'ptrace' into 'master'
Bare-bones ptracing functionality

See merge request redox-os/kernel!103
2019-07-01 22:50:19 +00:00
jD91mZM2 effe02bd45 Remove change I am faaairly certain I did NOT add :O
I'm guessing it's some issue after a rebase or something...
2019-07-01 22:50:19 +00:00
Jeremy Soller 42f977e7da Disable debug messages 2019-06-27 16:29:28 -06:00
Jeremy Soller 144ac70b12 Allow access to other thread's TLS with pointers 2019-06-23 20:21:22 -06:00
Jeremy Soller 78e79fc4d6 Merge branch '2018' into 'master'
Switch to 2018 edition

See merge request redox-os/kernel!102
2019-06-21 12:19:38 +00:00
jD91mZM2 fe705d9b63 Switch to 2018 edition
Most of this was generated by the absolutely extraordinary `cargo fix`
subcommand. There were still 2 errors and a few warnings to patch up,
but compared to the normal 600+ errors, I'd say the fixer did a damn
good job! I'm also amazed that I could still start the VM after this,
I half expected some kinds of runtime failure...
2019-06-21 12:12:01 +02:00
Jeremy Soller 1be77c2ab4 Store sigmask 2019-06-02 18:45:06 -06:00
Jeremy Soller fcd8ce7e1b Fix event logic for pipes 2019-04-28 13:32:24 -06:00
Jeremy Soller afa3f38310 Allow seek in root scheme directory listings 2019-04-27 08:13:20 -06:00
Jeremy Soller afab96fa06 Do not allow unreachable patterns (often a logic issue) 2019-04-27 08:10:49 -06:00
Jeremy Soller eecc9a442c Fix missing name override option when calling fexec_kernel 2019-04-15 21:01:19 -06:00
Jeremy Soller 126009f83c Keep process name when using interpreter 2019-04-15 21:00:42 -06:00
Jeremy Soller b66fef0479 Copy TCB if it was not initialized using kernel-allocated TLS 2019-04-15 20:47:27 -06:00
Jeremy Soller 6da3ab283e Clone grants 2019-04-15 20:47:03 -06:00
Jeremy Soller dc198cef6e Keep track of leaked grants and allow for cloning of grants 2019-04-15 20:42:41 -06:00
Jeremy Soller d432f7ce8c Add debugging for mprotect 2019-04-14 21:32:31 -06:00
Jeremy Soller 3a0671d20f Fix dropping grants without unmapping if they have no file descriptor (such as those from anonymous maps) 2019-04-14 19:23:23 -06:00
Jeremy Soller 339d68ac8d Remove debugging messages 2019-04-14 19:12:13 -06:00
Jeremy Soller 434e799f2a Place TCB at thread-specific location to avoid overlapping TCBs 2019-04-14 19:05:25 -06:00
Jeremy Soller 21e46b6a55 More cleanup of TLS mapping 2019-04-14 14:50:29 -06:00
Jeremy Soller 9762431a33 Cleanup TLS mapping 2019-04-13 22:00:27 -06:00
Jeremy Soller 8120131897 Add interpreter capability 2019-04-13 21:59:46 -06:00
Jeremy Soller dc28023be1 Remove unnecessary clone 2019-04-13 21:58:34 -06:00
Jeremy Soller 28cd51efed Update goblin 2019-04-13 21:57:58 -06:00
Jeremy Soller 58f9e5a801 0.1.54 - Add support for cache disable 2019-04-08 17:57:25 -06:00
Jeremy Soller f042bd5d07 Update for new rust 2019-04-07 10:57:33 -06:00
Jeremy Soller ff2ad4322a Update syscall 2019-04-07 10:51:51 -06:00
Jeremy Soller f36506613b Update funmap support 2019-04-06 20:13:55 -06:00
Jeremy Soller 4329aa4366 Update syscall 2019-04-06 18:58:34 -06:00
Jeremy Soller c8104a70b9 Merge branch 'prevent-race-condition' into 'master'
Lock resources before checking if we need to clean them.

See merge request redox-os/kernel!101
2019-04-01 15:38:00 +00:00
Noam Kleinburd 129d4e3ae5 Lock resources before checking if we need to clean them.
See the comments deleted by this commit for more details as to how
the race condition could effect the system.
2019-04-01 17:01:29 +03:00
Jeremy Soller e5cf6efa64 Support specification of stack with clone system call and CLONE_STACK flag 2019-03-31 14:35:45 -06:00
Jeremy Soller 9ccaed7103 Remove bochs breakpoint in kernel 2019-03-31 08:36:55 -06:00
Jeremy Soller ec66bf2ed1 Rerun build script if INITFS_FOLDER changes 2019-03-24 11:35:54 -06:00
Jeremy Soller d2095d8d0f Add in-memory logging, retrievable from sys:log 2019-03-17 09:31:34 -06:00
Jeremy Soller f7c9712977 Fix warning in irq scheme 2019-03-17 09:31:03 -06:00
Jeremy Soller e2a6233c12 New fevent functionality to prevent missing events 2019-03-13 13:57:07 -06:00
Jeremy Soller 483ee05ebc Fix unused import 2019-03-12 20:48:28 -06:00
Jeremy Soller a0e9f4a8a0 Use serial for debugging by default 2019-03-11 19:54:54 -06:00
Jeremy Soller b80f38b039 More debugging output options 2019-03-11 19:50:50 -06:00
Jeremy Soller 445b8ad96d Merge branch 'rustc-demangle' into 'master'
Use rustc-demangle in the stack traces

See merge request redox-os/kernel!100
2019-02-22 02:35:13 +00:00
Tibor Nagy 2ec775905a Use rustc-demangle in the stack traces 2019-02-14 15:54:17 +01:00
Jeremy Soller 6042cdb0a2 Remove unused import 2019-02-02 14:04:53 -07:00
Jeremy Soller b4575711c7 Fix logic error when cloning file descriptor in user scheme fmap 2019-02-02 08:11:07 -07:00
Jeremy Soller ca511b98f3 Add code to shut down QEMU with it's default ACPI settings, run cli hlt in loop 2019-02-01 20:12:06 -07:00
Jeremy Soller 504e93d11b Store file descriptor for mapped files until they are unmapped 2019-01-28 19:27:20 -07:00
Jeremy Soller 78d07d41cb FileDescriptor is now must_use 2019-01-28 19:26:50 -07:00
Jeremy Soller 613e5b45f7 Update dependencies 2019-01-20 19:47:50 -07:00
Jeremy Soller f6e2d44383 Add syscall setup to kstart_ap 2019-01-20 19:41:18 -07:00
Jeremy Soller 5c31c0991c 0.1.51 2019-01-20 19:37:55 -07:00
Jeremy Soller 36820c0346 Add somewhat magical code for syscall instruction 2019-01-20 19:35:52 -07:00
Jeremy Soller 931a7bb251 WIP: Support for syscall instruction 2019-01-20 15:49:18 -07:00
Jeremy Soller 30f1265c36 Add pages to use for head and tail of buffers in userscheme 2019-01-01 12:37:23 -07:00
Jeremy Soller 257e4a6eb5 WIP: improve speed of Grant::map_inactive
Use recursive page table address to calculate p4 entry
2019-01-01 12:28:45 -07:00
Jeremy Soller 8fcbf152eb Add mprotect 2018-12-31 21:04:21 -07:00
Jeremy Soller b18e322c3f WIP: itimer and sigprocmask 2018-12-28 21:53:40 -07:00
Jeremy Soller 0df93423a2 Add no_execute to heap now that mmap prot_exec is working 2018-12-28 19:57:51 -07:00
Jeremy Soller a31af81f8b Update fmap support 2018-12-28 15:35:21 -07:00
Jeremy Soller ef919f3d52 Implement EINTR for anything using wait_queue 2018-12-22 08:02:00 -07:00
Jeremy Soller 46a6325678 Update lock file 2018-12-14 20:08:21 -07:00
Jeremy Soller 69cbb548fb Mark heap executable for mesa (temporary) 2018-12-11 21:03:57 -07:00
Jeremy Soller 876e01e539 Update syscall 2018-12-11 21:03:40 -07:00
Jeremy Soller ecc0e747fc Prevent adding empty variables to environment 2018-12-02 19:25:28 -07:00
Jeremy Soller e356262f03 Correct init path 2018-12-02 19:14:13 -07:00
Jeremy Soller 69e3fe105d Update debugging to ignore clock_gettime 2018-12-02 16:31:24 -07:00
Jeremy Soller fe74ecee95 Update lock file 2018-12-01 09:28:14 -07:00
Jeremy Soller f443126dff Update syscall 2018-11-26 11:45:39 -07:00
Jeremy Soller 9af4d6a2e0 Fix compilation of graphical_debug feature and remove live feature warnings. 2018-11-21 19:38:14 -07:00
Jeremy Soller ee5c43ed45 Add umask to debug 2018-11-16 21:22:38 -07:00
Jeremy Soller 7e2a7d0cea Update lock file 2018-11-16 20:08:08 -07:00
Jeremy Soller efff2cb797 Update syscall to 0.1.42 2018-11-16 19:48:50 -07:00
Jeremy Soller 14c15d3bbb Update syscall 2018-11-16 19:45:13 -07:00
Jeremy Soller 4c38107055 Add umask 2018-11-16 19:43:37 -07:00
Jeremy Soller 885fe7d0ae update syscall 2018-11-12 20:55:49 -07:00
Jeremy Soller 5b31bf57be Update to latest rust 2018-11-08 17:25:57 -07:00
Jeremy Soller 120b4733ff Update for new rust 2018-11-08 17:11:06 -07:00
Jeremy Soller 1b091d3c9f Set name of process using full path of executable 2018-10-26 10:31:47 -06:00
Jeremy Soller 15313f98af Remove unnecessary dup implementations 2018-10-20 08:08:31 -06:00
Jeremy Soller 9570de21d1 Merge remote-tracking branch 'origin/relibc' 2018-10-14 16:43:54 -06:00
Jeremy Soller 3b1bf1bac1 Call TLB IPI when mapping grants 2018-09-25 20:58:24 -06:00
Jeremy Soller b08fa10277 Implement tlb IPI 2018-09-25 20:57:59 -06:00
Jeremy Soller f5fcbc12b8 Move ipi for pit to after EOI 2018-09-25 18:05:10 -06:00
Jeremy Soller e867326df1 Attempt to schedule other processors more often by waking them up with a context switch when a process is created 2018-09-25 18:01:38 -06:00
Jeremy Soller 0d510a4f74 Remove multi-core and acpi again 2018-09-23 11:44:34 -06:00
Jeremy Soller 7a97867868 Make multi-core support the default
Make IPIs less architecture specific
2018-09-23 10:40:55 -06:00
Jeremy Soller 22aa5f48d7 Merge branch 'master' into 'master'
Implement fmap for memory:

See merge request redox-os/kernel!93
2018-09-22 15:51:18 +00:00
Jeremy Soller a2ce83f60a Merge branch 'trace' into 'master'
trace: Break on RBP OVERFLOW

See merge request redox-os/kernel!96
2018-08-17 12:10:20 +00:00
Jeremy Soller 2ba21b33ad Merge branch 'relibc' into 'relibc'
Push null after argv

See merge request redox-os/kernel!97
2018-08-13 11:47:24 +00:00
jD91mZM2 1d817fa41d Push null after argv 2018-08-13 12:14:29 +02:00
Jeremy Soller 1718d28d39 Push null pointer to indicate end of environment 2018-08-12 08:30:12 -06:00
Jeremy Soller 69766ce3b9 Update syscall 2018-08-11 16:47:48 -06:00
Jeremy Soller 23f4c76ebb Fixes for launching init 2018-08-11 11:51:58 -06:00
Jeremy Soller 30e68f917e Remove env scheme and env field on context, fix all warnings 2018-08-11 11:34:32 -06:00
Jeremy Soller fe90664e33 Copy variables to USER_ARG_OFFSET 2018-08-11 11:18:45 -06:00
Jeremy Soller c7b3765d6f Remove execve, replace with fexec 2018-08-11 11:14:32 -06:00
Jeremy Soller a198cb22f5 Merge remote-tracking branch 'origin/master' into relibc 2018-08-11 09:03:35 -06:00
Ian Douglas Scott 8455d2bad4 trace: Break on RBP OVERFLOW
There's not point in continuing the loop once this occurs. It just
results in printing 'RBP OVERFLOW' repeatedly.
2018-08-08 12:35:04 -07:00
Jeremy Soller 875d89cef8 Merge branch 'master' into 'master'
Add more documentation to the redox kernel

See merge request redox-os/kernel!95
2018-07-30 12:28:11 +00:00
17liamnaddell 2de83eb932 fix small documentation bug 2018-07-21 21:46:11 -04:00
17liamnaddell 2c2a96a935 futex and slight changes 2018-07-21 21:41:47 -04:00
17liamnaddell c06f403dd2 second round of documentation 2018-07-21 20:48:33 -04:00
17liamnaddell 9d1fb3013d First round of documentation changes 2018-07-18 22:48:08 -04:00
jD91mZM2 55f2303d2c Implement fmap for memory: 2018-07-05 14:17:58 +02:00
Jeremy Soller b86672b81e Support for relibc 2018-07-03 19:42:23 -06:00
Jeremy Soller 054fc41beb Merge commit 'c28c147' 2018-06-19 18:18:36 -06:00
Jeremy Soller c28c147add Update to new dependencies 2018-06-19 18:17:16 -06:00
Jeremy Soller 9a7f04723b Merge branch 'fix-linked-list-allocator' into 'master'
Use older linked_list_allocator version

See merge request redox-os/kernel!92
2018-06-15 18:52:06 +00:00
Deepak Sirone 231cab75fe Use older linked_list_allocator verison 2018-06-15 23:46:07 +05:30
Jeremy Soller 3f08676e21 Merge branch 'fix-graphical-debug' into 'master'
Fix compilation error for graphical_debug

See merge request redox-os/kernel!91
2018-06-15 16:54:24 +00:00
Deepak Sirone ccbd858043 Fix compilation error for graphical_debug 2018-06-15 22:08:02 +05:30
Jeremy Soller 145785e206 Update links to gitlab 2018-06-12 12:30:44 -06:00
Jeremy Soller fc0db71dd4 Update syscall 2018-05-30 09:43:22 -06:00
Jeremy Soller 897b583360 Update lock file 2018-05-30 09:19:19 -06:00
Jeremy Soller 41bdb31645 Update syscall 2018-05-30 09:19:06 -06:00
Jeremy Soller 92ebd4d16a Merge branch 'master' of https://github.com/redox-os/kernel 2018-05-24 08:31:59 -06:00
Jeremy Soller 764f28ada5 Update cargo.lock 2018-05-24 08:31:52 -06:00
Jeremy Soller 3f2bd559bf Merge pull request #90 from jabedude/master
Fix TODO: Use triple fault to guarantee reboot
2018-05-22 06:33:20 -06:00
Josh Abraham aff0c339b4 Fix TODO: Use triple fault to guarantee reboot
Cause interrupt, since the IDT is dorked we can't find the INT 3
handler (double fault), and the double fault handler can't be
found (triple fault).
2018-05-21 17:14:58 -10:00
Jeremy Soller 5cfe3f822b Update syscall 2018-05-20 16:26:45 -06:00
Jeremy Soller 94c6550580 Reduce messages from fevent warning 2018-05-20 16:25:11 -06:00
Jeremy Soller 7d0f9a7ce8 Require correct event id return 2018-05-20 13:18:51 -06:00
Jeremy Soller 43a163d8d6 Debug scheme will return correct event id 2018-05-20 12:56:37 -06:00
Jeremy Soller 4ec46ee786 Send new flags to scheme 2018-05-20 12:48:22 -06:00
Jeremy Soller cb94d334ac Fix issue with debug fevent 2018-05-20 12:33:54 -06:00
Jeremy Soller 99a3bff2da WIP: New event system 2018-05-20 11:08:37 -06:00
Jeremy Soller 63351f4ca6 Fix documentation in pipe scheme 2018-05-20 07:18:13 -06:00
Jeremy Soller e01d397dc1 Return ECHILD if child process does not exist before blocking on it 2018-05-14 20:34:47 -06:00
Jeremy Soller d0b78cd8ff Remove stop print 2018-05-14 20:03:48 -06:00
Jeremy Soller be1e87922c Set rust_oom no_mangle 2018-04-28 22:08:23 -06:00
Jeremy Soller 48007b8f1e Update to new allocation API (WIP) 2018-04-28 22:07:43 -06:00
Jeremy Soller 36989e21f2 Merge branch 'master' of https://github.com/redox-os/kernel 2018-04-28 21:45:23 -06:00
Jeremy Soller c5752242d0 Update linked_list_allocator 2018-04-28 21:45:19 -06:00
Jeremy Soller a64522e580 Merge pull request #88 from raw-bin/aarch64
Add a toolchain target spec for AArch64
2018-04-16 06:39:10 -06:00
Robin Randhawa 19d4868e6c Add a toolchain target spec for AArch64 2018-04-16 15:36:59 +05:30
Jeremy Soller 9dc42102bf Merge pull request #87 from raw-bin/aarch64-redox-port-outline-doc
Add an outline document for a port of the Redox kernel to the Arm AAr…
2018-04-15 17:57:10 -06:00
Robin Randhawa 9a0f8391a6 Update status: Toolchain spec done
Also fix a typo with the device_crate URL.
2018-04-16 02:53:59 +05:30
Robin Randhawa 09a7eaea4b Add an outline document for a port of the Redox kernel to the Arm AArch64 architecture. 2018-04-14 14:10:51 +05:30
Jeremy Soller 9ddda9bbfb Ensure GDT and IDT state is sane before attempting to set up paging 2018-04-11 21:06:13 -06:00
Jeremy Soller f83f61b51a Enable graphical debug 2018-03-20 20:33:49 -06:00
Jeremy Soller d9ee3e05cc Merge pull request #86 from ids1024/sig0
kill: support signal number 0
2018-03-19 10:50:41 -06:00
Ian Douglas Scott 3b09c8f858 kill: support signal number 0
Tests process existence, but does not send a signal. Matches POSIX
behavior.
2018-03-18 21:52:48 -07:00
Jeremy Soller 6dfed91ac3 Fix index check for accessfield 2018-03-11 12:58:43 -06:00
Jeremy Soller 402266e3e4 Check length on more objects 2018-03-11 12:56:48 -06:00
Jeremy Soller 74e673e68d Return errors if data is too small when parsing acpi objects 2018-03-11 12:52:30 -06:00
Jeremy Soller 734622fb9a Fix mapping code for physbaseptr 2018-03-11 12:16:51 -06:00
Jeremy Soller 9c7c010cc0 Fix graphical debug sync error, add unmapping, map with write combine 2018-03-11 12:12:54 -06:00
Jeremy Soller 819f77daf3 Add support for graphical debug, to be used during ACPI phase 2018-03-11 11:36:58 -06:00
Jeremy Soller 133c433f60 Fix warning in context::switch 2018-03-11 11:35:41 -06:00
Jeremy Soller c020ce7d8a Fix delivery of signals when a signal uses the default handler, make context status update on every switch 2018-02-24 17:47:46 -07:00
Jeremy Soller 3af2964955 Add ACPI feature 2018-02-18 16:24:34 -07:00
Jeremy Soller 797d86b7a7 Remove debug message 2018-01-29 21:36:17 -07:00
Jeremy Soller 761fe30bf3 Add linked list allocator with automatic resizing
Fix memory leaks in exec
Remove warnings
2018-01-29 21:29:24 -07:00
Jeremy Soller 015b79430e Updates for new nightly 2018-01-28 14:59:01 -07:00
Jeremy Soller 50bbdd3f5e Update lock file 2018-01-28 14:45:52 -07:00
Jeremy Soller fdaf3c2fbc Merge pull request #76 from weclaw1/master
Use slab allocator for kernel heap
2018-01-28 14:16:23 -07:00
Jeremy Soller 86ef2c4eb3 Merge pull request #83 from biotty/memword
Operate on word size as possible
2018-01-25 06:57:54 -07:00
Christian Øien c2e972f21a Operate on word size as possible 2018-01-24 22:15:30 -06:00
Jeremy Soller f3205e6e34 Fix #81 by limiting arguments to 4095
Fix #79 by limiting mappable sections to the 2GB mark
2018-01-21 20:46:53 -07:00
Jeremy Soller dcb49be481 Fix potential overflows in validate_slice and validate_slice_mut, require memory to be userspace 2018-01-21 19:21:43 -07:00
Jeremy Soller 89df5e5343 Remove debugging print 2018-01-19 20:26:41 -07:00
Jeremy Soller fee95a0406 Disable PTI by default 2018-01-19 20:07:18 -07:00
Jeremy Soller dd0376ed69 Merge branch 'pti' 2018-01-19 20:06:59 -07:00
Robert Węcławski 3e06a37215 Use slab allocator for kernel heap 2018-01-17 23:31:27 +01:00
Jeremy Soller 1e17bfdd53 Merge pull request #75 from dlrobertson/master
Update debugging docs
2018-01-10 19:49:40 -07:00
Jeremy Soller 98fb50a086 Remove comment from linker file 2018-01-10 19:27:05 -07:00
Jeremy Soller 1e533b3ad5 Use fninit in start 2018-01-10 19:26:33 -07:00
Jeremy Soller 5b389c7ffa Update PTI patch to inline PTI functions 2018-01-10 17:25:31 -07:00
Dan Robertson a16b9230a8 Update debugging docs 2018-01-10 21:31:28 +00:00
Jeremy Soller d82ffd16cb WIP: Add per-cpu interrupt stack used before mapping kernel heap 2018-01-09 22:16:14 -07:00
Jeremy Soller 192a8ce793 Add rbx to saved registers in syscall stack 2018-01-09 21:46:48 -07:00
Jeremy Soller a6550341bb Add trampolines for PTI support 2018-01-08 22:31:50 -07:00
Jeremy Soller 670d7b00d3 Add PML4 constants 2018-01-08 20:32:27 -07:00
Jeremy Soller 32028f66fe Merge pull request #74 from wartman4404/master
Write hpet timer twice
2018-01-07 19:46:08 -07:00
wartman4404 4f90a0f5c1 Write hpet timer 0 twice to set accumulator and period
This allows booting with implementations that require them to be set separately.
Also, check for the availability of legacy-replacement mode and periodic interrupts before using hpet
2018-01-07 17:06:07 -06:00
Jeremy Soller 083c444a68 Implement waitpid on PGID 2018-01-05 20:31:15 -07:00
Jeremy Soller 9313909fe9 Fix stop signal by switching context after stopping 2018-01-04 09:03:41 -07:00
Jeremy Soller 49d5c33928 Add support for WCONTINUED and WUNTRACED
Fix issues with SIGCONT
2018-01-03 22:34:50 -07:00
Jeremy Soller b6878760c7 Use seperate stopped status 2018-01-03 21:33:56 -07:00
Jeremy Soller c912f42800 Fix TLS when forking, fix signal delivery to self 2018-01-03 21:33:24 -07:00
Jeremy Soller 7906f6891e Add support for stop/cont signals 2018-01-02 22:05:29 -07:00
Jeremy Soller 22aca69ac9 Use TLS alignment to fix https://github.com/redox-os/redox/issues/1124 2017-12-29 14:58:04 -07:00
Jeremy Soller caa607eb28 Merge pull request #70 from redox-os/clippy
Add clippy lints, action some clippy items
2017-12-27 21:32:23 -07:00
Jeremy Soller 059cc8078d Add frename 2017-12-27 20:19:37 -07:00
Jeremy Soller 58e1d92eb5 Add clippy lints, action some clippy items 2017-12-24 22:19:00 -07:00
Jeremy Soller e08f56a2de Merge pull request #69 from NilSet/check_namespace
Check if current namespace exists
2017-12-24 07:28:35 -07:00
Tommie Levy 04e1034088 Check if current namespace exists 2017-12-24 02:36:11 -05:00
Jeremy Soller 7bfe1739fd Merge pull request #67 from Arcterus/master
Move null and zero from kernel space to user space
2017-12-18 16:25:11 -07:00
Alex Lyon 66a5379ff6 Move null and zero from kernel space to user space 2017-12-18 14:33:06 -08:00
Jeremy Soller a9fa08fd72 Merge pull request #66 from weclaw1/page_table_optimization
Page table optimization
2017-12-17 19:19:15 -07:00
Robert Węcławski 3c466892de change assert to debug_assert 2017-12-17 20:29:35 +01:00
Robert Węcławski a8ecfc86dd Better comment and mask representation 2017-12-17 19:54:52 +01:00
Robert Węcławski 08a4c33b77 New entries are set to zero 2017-12-17 19:46:19 +01:00
Robert Węcławski 2d041bbb51 don't change counter in set_unused 2017-12-17 18:45:41 +01:00
Robert Węcławski 82bae0b314 entry::set doesn't reset counter, counter mask is a const 2017-12-17 18:22:27 +01:00
Robert Węcławski ab687852d3 Convert entry count to u64, remove unnecessary parentheses 2017-12-17 17:19:06 +01:00
Robert Węcławski a48ec82f20 Use unused bits 52-61 in first entry of each page table as counter for number of page table entries 2017-12-17 16:53:20 +01:00
Jeremy Soller c2644adf3d Improve multi_core support 2017-12-05 21:26:45 -07:00
Jeremy Soller cd54352f47 Merge branch 'master' of https://github.com/redox-os/kernel 2017-12-05 20:24:43 -07:00
Jeremy Soller dd7c61b830 Allow other processors to pick up work 2017-12-05 20:24:03 -07:00
Jeremy Soller 8ad13539dc Merge pull request #65 from dlrobertson/master
Add documentation on using gdb
2017-12-04 20:29:08 -07:00
Dan Robertson 2e6949e66d Add documentation on using gdb 2017-12-05 01:25:54 +00:00
Jeremy Soller 9b327ccba8 Update Cargo.lock 2017-12-03 08:53:47 -07:00
Jeremy Soller 45e8effa8a Merge pull request #64 from dlrobertson/master
Do not discard .debug section
2017-12-02 19:27:45 -07:00
Dan Robertson 025ec0def2 Do not discard .debug section
Do not discard the .debug section. If the builder would like to discard
this section, they can do so explicitly with objcopy.
2017-12-02 19:38:16 +00:00
Jeremy Soller 578c57840a 0.1.32 2017-11-28 21:48:28 -07:00
Jeremy Soller 789e290c9b Add fchown, fchmod 2017-11-28 21:48:10 -07:00
Jeremy Soller ed05564011 Remove SwitchResult, use out of band data to detect interruption
Update debugging code
2017-11-14 21:16:35 -07:00
Jeremy Soller da954096e0 Merge pull request #62 from xTibor/fix-nightly
Fix for the latest nightly
2017-11-14 20:28:03 -07:00
Jeremy Soller 9368b2ba4c Merge pull request #63 from pzmarzly/patch-1
elf.rs: do not inline constant from goblin library
2017-11-13 12:38:26 -07:00
Paweł Zmarzły 20f262c4ed elf.rs: do not inline constant from goblin library
SELFMAG is declared [here](https://github.com/m4b/goblin/blob/de8aecc8f1e7f3de7d66a1511d3976cdf0335e0c/src/elf/header.rs#L91).
2017-11-13 20:24:50 +01:00
Tibor Nagy eadade4c0f Fix for the latest nightly 2017-11-10 21:42:28 +01:00
Jeremy Soller 9e9f80ef13 Add futex timeout 2017-11-06 22:04:42 -07:00
Jeremy Soller 2de7bd7f79 Merge pull request #61 from sajattack/patch-1
add a LOC badge
2017-11-05 06:29:35 -07:00
Paul b5dac25d55 add a LOC badge 2017-11-05 00:30:20 -07:00
Jeremy Soller 1e553b744c Fix errors from waitpid 2017-10-29 16:02:54 -06:00
Jeremy Soller eebf12bec5 Fix returning too many errors from waitpid 2017-10-29 15:41:59 -06:00
Jeremy Soller 1f99d038c4 Make debug function never return error 2017-10-29 15:31:35 -06:00
Jeremy Soller ffad0f2ace Merge pull request #59 from xTibor/libcollections
Migrate from collections
2017-10-27 21:39:51 -06:00
Tibor Nagy e6b9f850d1 Migrate from collections 2017-10-28 02:42:08 +02:00
Jeremy Soller 8ec5d4726b Hack to allow rustc to wait on non-child process.
Add sys:syscall for seeing active system calls
2017-10-22 21:13:29 -06:00
Jeremy Soller ef70cd257c Uncomment AML value variant 2017-10-22 19:41:31 -06:00
Jeremy Soller 58c6ef0ecf Merge branch 'master' of https://github.com/redox-os/kernel 2017-10-21 20:30:26 -06:00
Jeremy Soller 51339cb8c9 Cleanup warnings
Implement interrupt on signal in pipe:
2017-10-21 20:30:20 -06:00
Jeremy Soller 62e0713d9b Merge pull request #58 from GabrielMajeri/update-bitflags
Update to `bitflags` version 1.0
2017-10-11 07:44:49 -06:00
Gabriel Majeri 305e7980d8 Update to bitflags 1.0 2017-10-11 15:59:14 +03:00
Jeremy Soller 31d742e6be Merge pull request #57 from redox-os/cap
Capability mode support using null namespace
2017-10-09 20:24:22 -06:00
Jeremy Soller e07c3ac0b9 Set init namespace to 1 2017-10-09 20:20:38 -06:00
Jeremy Soller 244069cf43 Implement a capability namespace with no available schemes 2017-10-09 20:12:08 -06:00
Jeremy Soller b023a715f9 Merge pull request #56 from jaje/externs
Deduplicate memcpy, memmove, memset and memcmp functions
2017-10-05 08:54:07 -06:00
Jan Jedelský 05dc9140a4 Update comment in externs.rs 2017-10-05 14:27:01 +02:00
Jan Jedelský 528ffa985a Deduplicate memcpy, memmove, memset and memcmp functions 2017-10-05 14:19:25 +02:00
Jeremy Soller c417f0cf00 Add target-c-int-width to x86_64 target 2017-10-04 18:25:59 -06:00
Jeremy Soller 808447cbfb Move location of live disk 2017-10-01 14:24:21 -06:00
Jeremy Soller 0794926493 Pass env to first function 2017-09-30 18:09:48 -06:00
Jeremy Soller 41ee250eea Reformat kernel arguments 2017-09-30 16:12:37 -06:00
Jeremy Soller ce87b7fc6c Allow listing of root scheme 2017-09-30 14:52:57 -06:00
Jeremy Soller 49ef95a156 Downgrade goblin 2017-09-26 20:04:48 -06:00
Jeremy Soller aa3c1515a0 Update README.md 2017-09-26 14:35:05 -06:00
Jeremy Soller 01a881243b hybrid -> micro 2017-09-26 14:15:01 -06:00
Jeremy Soller fcf8120eec Update features for latest nightly 2017-09-26 14:12:30 -06:00
Jeremy Soller bdff0dd004 Fix documentation 2017-09-26 13:57:16 -06:00
Jeremy Soller 9a9f5d17cb Update dependencies 2017-09-26 13:29:21 -06:00
Jeremy Soller 37c9250a52 Fix output of build script 2017-09-26 13:17:15 -06:00
Jeremy Soller 23e30c14a8 Create LICENSE 2017-09-26 12:57:43 -06:00
Jeremy Soller 735802366f Update README.md 2017-09-26 12:57:04 -06:00
Jeremy Soller 55ed5f81c3 Update README.md 2017-09-26 12:55:34 -06:00
Jeremy Soller 1fa963be45 Merge pull request #54 from L3nn0x/patch-1
Correct small bug in memcpy 32bits implementation
2017-09-20 07:52:41 -06:00
L3nn0x eebba9291a Update externs.rs
I'm not entirely sure about it, but the rest of the file treats 32 bits as groups of 4 so it makes sense that memcpy does the same.
2017-09-20 09:49:40 +01:00
Jeremy Soller d6b9768dc3 More efficient live filesystem method
Reduce kernel heap to 64 MB
Fix issue in build.rs
2017-09-19 20:21:04 -06:00
Jeremy Soller 1f81866afa Update dependencies 2017-09-19 19:28:43 -06:00
Jeremy Soller 5248ce70db Merge pull request #52 from ids1024/spin-override
Add temporary override for spin-rs
2017-09-19 17:22:11 -06:00
Ian Douglas Scott fee3561282 Add temporary override for spin-rs 2017-09-19 16:17:48 -07:00
Jeremy Soller bec9610947 Change unreachable to enosys 2017-09-17 16:49:34 -06:00
Jeremy Soller 5839641b41 Update debugging code 2017-09-17 09:40:29 -06:00
Jeremy Soller 18a911578c Merge pull request #51 from ids1024/debug_syscall
Add commented out system call debug printing code
2017-09-16 21:34:41 -06:00
Ian Douglas Scott 29a2b9fbcd Add commented out system call debug printing code 2017-09-16 20:25:54 -07:00
Jeremy Soller 6e8de21b7c Implement events on pipe
Add syscall name debugging
Update debugging code
2017-09-16 12:04:20 -06:00
Jeremy Soller 917d30c193 Fix the mapping of TLS - it will now be page aligned 2017-09-13 22:16:02 -06:00
Jeremy Soller a5f3e5057b Remove warnings
Improve error information
Cleanup interrupt macros
2017-09-13 21:32:08 -06:00
Jeremy Soller cf45bd34e1 Merge pull request #48 from CWood1/master
Fully implemented AML parser, some amendments to ACPI infrastructure
2017-08-31 17:53:16 -06:00
Connor Wood f0bc8cca23 Merge 2017-08-31 13:28:24 +01:00
Connor Wood 7145e2390c Converted DDB handle to integer and vice versa 2017-08-31 11:25:08 +01:00
Connor Wood 1cce42b691 Moved DDB handles over to using signature scheme 2017-08-31 11:07:01 +01:00
Connor Wood 1bcd8530d2 Stored signature to include OEM signature and OEM table ID 2017-08-31 10:52:59 +01:00
Connor Wood 5592484d07 Eliminated dead code 2017-08-30 19:09:08 +01:00
Connor Wood c3d07e4caa Refactored ACPI initialisation code to be better conducive to DDB Handle stuff 2017-08-30 19:03:39 +01:00
Connor Wood 9f55367906 Implemented notification API 2017-08-29 17:29:07 +01:00
Connor Wood d23241d800 Implemented copy 2017-08-29 12:25:41 +01:00
Connor Wood d75dfd3c20 Implemented externam 2017-08-29 12:02:03 +01:00
Connor Wood 71c5301448 Implemented concat 2017-08-29 11:32:48 +01:00
Connor Wood 60edb9da68 Implemented type checking and coersion upon store 2017-08-29 10:11:01 +01:00
Connor Wood b78f7139b9 Completed Get method 2017-08-29 09:38:36 +01:00
Jeremy Soller d487e1d23f Make syscall a submodule 2017-08-27 10:54:11 -06:00
Jeremy Soller 9fcaf30513 Fix PIT 2017-08-21 20:27:13 -06:00
Connor Wood d5d156a3d2 Implemented buffer field index modify 2017-08-19 15:10:47 +01:00
Jeremy Soller 81a931629f Merge pull request #47 from ids1024/exec
Support arguments in #!
2017-08-16 14:08:31 -06:00
Ian Douglas Scott f60d9fc969 Support arguments in #! 2017-08-16 12:30:20 -07:00
Connor Wood aa35967f72 Made index modification recursion resolve 2017-08-13 19:02:25 +02:00
Connor Wood f0a185741a Implemented recursive index modifications 2017-08-13 16:13:57 +02:00
Connor Wood 328a89c224 Completed context modify, aside from BufferFields and nested Indexes 2017-08-10 14:28:30 +02:00
Jeremy Soller 5c5e5da7c2 Update syscall crate 2017-08-09 21:06:00 -06:00
Jeremy Soller b43f1503b7 Merge pull request #46 from ids1024/dupfd
Implement F_DUPFD
2017-08-08 14:58:49 -06:00
Ian Douglas Scott 1623baa137 Implement F_DUPFD in fcntl 2017-08-08 10:59:11 -07:00
Ian Douglas Scott 9e2d39b5b8 Move duplication in dup() and dup2() to new function 2017-08-07 21:57:25 -07:00
Jeremy Soller 64d7d24174 Merge pull request #45 from ids1024/filelock
Prevent freezing due to double locking
2017-08-06 13:39:50 -06:00
Ian Douglas Scott ade6e0d421 Prevent freezing due to double locking 2017-08-06 12:08:50 -07:00
Jeremy Soller d8d78ffbef Update Cargo.lock 2017-08-02 19:06:59 -06:00
Jeremy Soller 8932daf04a Merge pull request #44 from ids1024/fifo
Use fifo flag for pipe
2017-08-02 12:41:48 -06:00
Ian Douglas Scott 2eab3ea6b0 Use fifo flag for pipe 2017-08-02 11:13:44 -07:00
Jeremy Soller b364d052f2 Merge pull request #43 from cookie545445/machdep
Move x86_64-specific code to arch/x86_64
2017-07-30 20:52:21 -06:00
Tommy Hudson 0e1d664bf0 Rearrange serial I/O code and make 16550 driver generic over T: Io 2017-07-30 20:54:36 +01:00
Tommy Hudson 621b657f87 Move x86_64-specific code to arch/x86_64 2017-07-30 15:46:34 +01:00
Connor Wood 94f27a1a9c Merge branch 'aml-namespace' of github.com:cwood1/kernel into aml-namespace 2017-07-30 13:38:50 +03:00
Connor Wood 41ce7fdf1f Implemented much of ctx::modify and ctx::get 2017-07-30 11:23:32 +03:00
Jeremy Soller 21d033a1a8 Update syscall 2017-07-29 08:17:28 -06:00
Connor Wood 6122b21997 Moved event signal/wait code into context 2017-07-29 12:57:53 +03:00
Connor Wood ab98746879 Moved lock manipulation into context 2017-07-29 12:39:08 +03:00
Jeremy Soller 2e66912ce1 Merge pull request #42 from ids1024/description
Use file descriptions, shared between file descriptors
2017-07-28 17:41:55 -06:00
Ian Douglas Scott 374213f155 F_GETFD and F_SETFD 2017-07-28 15:06:50 -07:00
Ian Douglas Scott 6b504a9493 Remove unused imports 2017-07-28 14:26:15 -07:00
Ian Douglas Scott 3756fb5606 Use file description alongside file descriptior, matching posix 2017-07-28 13:59:31 -07:00
Jeremy Soller 2261452492 Update to new nightly API 2017-07-26 20:58:40 -06:00
Jeremy Soller b474136af4 Add cargo.lock 2017-07-26 07:44:24 -06:00
Connor Wood f25df99a41 Implemented derefof 2017-07-25 14:48:07 +01:00
Connor Wood ada5ba6dbc Implemented condrefof 2017-07-25 13:12:42 +01:00
Connor Wood afc93f82a9 Implemented RefOf 2017-07-25 13:06:10 +01:00
Connor Wood 968fd30b0a Fixed object references 2017-07-25 11:51:43 +01:00
Connor Wood 8a5ec3a26b Implemented SizeOf 2017-07-25 11:37:49 +01:00
Connor Wood 0652bc8099 Implemented ToBuffer 2017-07-25 11:29:32 +01:00
Connor Wood 6df99953dc Implemented defBuffer 2017-07-25 11:25:29 +01:00
Connor Wood 1cd124a852 Fixed bank name issue 2017-07-25 10:36:56 +01:00
Connor Wood a115d21495 Converted all types to string 2017-07-24 19:02:09 +01:00
Connor Wood a5382534e6 Converted to integer fully 2017-07-24 18:53:21 +01:00
Connor Wood d7229d7132 Completed simple type conversions 2017-07-24 17:50:41 +01:00
Connor Wood fdcacd7d18 Implemented numerous "simple" type conversions 2017-07-24 17:27:01 +01:00
Connor Wood e7edaceec0 All conversions to BufferField, dependent on the conversion to Buffer 2017-07-24 16:15:18 +01:00
Connor Wood 9408e71dcd Converted BufferField into Buffer 2017-07-24 16:02:19 +01:00
Connor Wood 82762863df Converted string to buffer 2017-07-24 09:56:54 +01:00
Connor Wood c6ecf105ad Converted Integer to Buffer 2017-07-24 09:48:27 +01:00
Connor Wood a70b26555e Error handling in namespace path assembly 2017-07-24 09:21:53 +01:00
Connor Wood 59b176c24e Implemented path parent character "^" when calculating scope paths 2017-07-24 09:09:07 +01:00
Jeremy Soller a3b0c8ebff Merge pull request #40 from ids1024/components
Strip extra slashes from path
2017-07-23 20:23:40 -06:00
Ian Douglas Scott 1367c7814f Strip extra slashes from path
Fixes strange behavior like 'cd .//////; pwd'
2017-07-23 18:09:49 -07:00
Jeremy Soller ef8c120533 Prevent nested signals, fix check for PID > 0 2017-07-23 16:02:48 -06:00
Jeremy Soller 07262fd866 Implement sending signals to process groups. Modify max context value to fit inside of isize 2017-07-23 15:55:47 -06:00
Jeremy Soller d6848a1995 Add PGID 2017-07-23 14:47:41 -06:00
Connor Wood c79eb0eeab Implemented table API in full 2017-07-23 13:42:30 +01:00
Connor Wood 4288182106 Implemented Load 2017-07-23 10:34:50 +01:00
Jeremy Soller 6a061665e4 Use EINVAL instead of ENOENT 2017-07-22 13:21:15 -06:00
Jeremy Soller fc914e0cae Make it an error to supply a dup buffer to schemes that do not handle it 2017-07-22 12:54:28 -06:00
Connor Wood 82e814469c Shutdown on fatal error 2017-07-22 13:52:48 +01:00
Connor Wood 3c2b3b3f5e Fixed a bunch of warnings 2017-07-22 13:32:02 +01:00
Connor Wood 76316aa8d6 Implemented toHexString 2017-07-22 13:10:45 +01:00
Connor Wood 5873e553e9 Implemented toDecimalString 2017-07-22 12:56:53 +01:00
Connor Wood 797262df5c Several conversion operators 2017-07-22 12:48:23 +01:00
Connor Wood 79b6afd608 Implemented to integer 2017-07-22 12:12:31 +01:00
Connor Wood f8e433c4e7 Implemented sleep 2017-07-22 11:13:30 +01:00
Connor Wood ff23827155 Implemented stall 2017-07-22 11:02:53 +01:00
Connor Wood b7d9ad60bb Implemented Event synchronisation objects 2017-07-22 10:55:09 +01:00
Connor Wood b0b8a7e85d Handled mutexes 2017-07-22 10:06:20 +01:00
Connor Wood 8e98cdf971 Processed acquire mutex 2017-07-22 09:57:44 +01:00
Connor Wood 8412339ae9 Every context has an ID 2017-07-22 09:10:37 +01:00
Connor Wood 1938ca0435 Memory handler API 2017-07-21 14:11:29 +01:00
Connor Wood 0365b6f2b7 Created a function to control the global S state 2017-07-21 12:51:30 +01:00
Connor Wood 5c05b48921 GenericAddressStructure now handles reads and writes itself 2017-07-21 12:42:11 +01:00
Connor Wood 2256e0288b Removed spurious file 2017-07-21 12:04:36 +01:00
Connor Wood a14266fc82 Parallelized ACPI subsystem 2017-07-21 12:03:55 +01:00
Jeremy Soller 4ae6ed9d4c Pass syscall data to syscall, implement iopl 2017-07-19 14:51:12 -06:00
Jeremy Soller f7b961ddff Reduce scope of contexts lock 2017-07-18 22:02:22 -06:00
Jeremy Soller b4d502c763 Add reset code 2017-07-18 20:55:00 -06:00
Jeremy Soller 76aa3116d7 Merge pull request #39 from ids1024/uname
sys:uname
2017-07-18 18:48:35 -06:00
Ian Douglas Scott 2ab539d2e4 sys:uname 2017-07-18 15:42:42 -07:00
Connor Wood dba65f3128 Remove all namespace changes made within methods 2017-07-18 10:16:26 +01:00
Jeremy Soller c7664674d3 Update fs.rs 2017-07-17 21:25:20 -06:00
Connor Wood 258cab878c Implemented index references 2017-07-17 13:22:06 +01:00
Connor Wood c01a04148b Implemented method return values 2017-07-17 12:20:04 +01:00
Connor Wood d315914f29 Implmented method execution and method invocations 2017-07-17 11:54:19 +01:00
Connor Wood d38b1d7aa9 Implemented loop control 2017-07-17 11:26:33 +01:00
Connor Wood af80bfa258 Timer now returns monotonic counter 2017-07-15 10:51:59 +01:00
Connor Wood fe681d57a1 Implemented opcodes 2017-07-15 10:14:53 +01:00
Connor Wood eeea65f5c1 Implemented match 2017-07-15 10:14:53 +01:00
Connor Wood e0bd497bb8 Implemented further opcodes in full, added get to context 2017-07-15 10:14:53 +01:00
Connor Wood 38263bf700 Fixed number of bugs 2017-07-15 10:14:53 +01:00
Connor Wood 2a6bbeb584 Added object modification 2017-07-15 10:14:53 +01:00
Connor Wood 7527915027 Added a context manager 2017-07-15 10:14:53 +01:00
Connor Wood 6c74a02382 Refactored parser to execute in the parse step for efficiency and simplicity 2017-07-15 10:14:52 +01:00
Connor Wood f131cc6f1f Rolled parsing and execution steps into one for namespace modifiers 2017-07-15 10:14:52 +01:00
Connor Wood 5213d59237 Namespaces can now be concatenated, handling of SSDTs is now performed 2017-07-15 10:14:52 +01:00
Connor Wood 21c9d824cc Finalized ACPIType 2017-07-15 10:14:52 +01:00
Connor Wood a79e275cc0 Moved AccessType into namespace 2017-07-15 10:14:52 +01:00
Connor Wood 82124a59d5 Moved ConnectFieldBufferData to the namespace 2017-07-15 10:14:52 +01:00
Connor Wood 1babfb4b32 Moved ConnectFieldNameString into namespace 2017-07-15 10:14:52 +01:00
Connor Wood ee012a482b Moved DataRegion into namespace - more infrastructure required 2017-07-15 10:14:52 +01:00
Connor Wood 94b8bd19d6 Moved indexfield to namespace 2017-07-15 10:14:51 +01:00
Connor Wood 7911853951 Moved arbitrary length buffer field into namespace 2017-07-15 10:14:51 +01:00
Connor Wood f287638996 Moved BufferFields into namespace 2017-07-15 10:14:51 +01:00
Connor Wood 9ae9e3b190 Moved BankField to the namespace 2017-07-15 10:14:51 +01:00
Connor Wood 61776f7af8 Removed temporary files 2017-07-15 10:14:51 +01:00
Connor Wood 94b0e7de37 Moved Event to namespace 2017-07-15 10:14:51 +01:00
Connor Wood 9575c6fed3 Moved Mutex to namespace 2017-07-15 10:14:51 +01:00
Connor Wood e52d4c98a3 Moved PowerResource into namespace 2017-07-15 10:14:51 +01:00
Connor Wood b4ddaeadbb Moved Processor to namespace, and refactored namespace layout to use BTreeMap 2017-07-15 10:14:50 +01:00
Connor Wood 73562b3f56 Moved ComputationalData::String into namespace 2017-07-15 10:14:01 +01:00
Connor Wood c58aa38247 Moved DefDevice and DefThermalZone to namespace 2017-07-15 10:14:01 +01:00
Connor Wood 07cf7385e9 Moved Alias to the namespace 2017-07-15 10:14:01 +01:00
Jeremy Soller 1085fa3838 Merge pull request #38 from ids1024/espipe
Make seek on pipe return ESPIPE
2017-07-14 17:15:31 -06:00
Ian Douglas Scott 89f695dd28 Make seek on pipe return ESPIPE 2017-07-14 15:58:24 -07:00
Jeremy Soller ff9f2322a6 Merge pull request #37 from ids1024/cloexec
Make dup/dup2 clear cloexec
2017-07-14 12:56:28 -06:00
Ian Douglas Scott 09a4980442 Make dup/dup2 clear cloexec 2017-07-14 08:48:42 -07:00
Jeremy Soller 30385fec48 Merge pull request #36 from CWood1/hpet
HPET Driver
2017-07-14 08:32:52 -06:00
Connor Wood 0b6bde7c68 Moved PIT driver into kernel 2017-07-14 15:26:04 +01:00
Connor Wood 0bd6f11a4f Implemented HPET driver 2017-07-14 13:58:06 +01:00
Connor Wood 0cbdb2d0c0 Saved HPET table for global access 2017-07-14 10:39:50 +01:00
Connor Wood 387cd41e5e Implemented ACPI table 2017-07-14 10:36:27 +01:00
Jeremy Soller 56ba795845 Merge pull request #34 from ids1024/dup2
Make dup2() work if second file descriptor doesn't exist
2017-07-13 15:55:16 -06:00
Ian Douglas Scott 6f081f4bbd Make dup2() work if second file descriptor doesn't exist 2017-07-13 14:43:55 -07:00
Jeremy Soller 2c0cc3a8a1 Merge pull request #33 from ids1024/path
Pass relative, not canonicalized, path to script
2017-07-13 09:49:59 -06:00
Ian Douglas Scott f020fe2ac5 Pass relative, not canonicalized, path to script 2017-07-13 08:09:36 -07:00
Jeremy Soller 6981f0cd36 Merge pull request #32 from ids1024/process
Strip whitspaces after #!
2017-07-13 07:11:39 -06:00
Ian Douglas Scott b5da98396e Strip whitspaces after #!
Autotools configure scripts seem to use "#! /bin/sh"
2017-07-12 23:03:53 -07:00
Jeremy Soller 687f991ab4 Merge pull request #31 from ids1024/fstat
Implement fstat() for pipe scheme
2017-07-12 07:05:46 -06:00
Ian Douglas Scott f81a276536 Implement fstat() for pipe scheme 2017-07-11 21:26:35 -07:00
Jeremy Soller a03457a9eb Simpler debug message 2017-07-10 20:33:29 -06:00
Jeremy Soller a3493d16fd Allow simple signal delivery to PID 1 (the kernel idle process) 2017-07-10 20:28:10 -06:00
Jeremy Soller 268ba3ece7 Remove syscall replacement 2017-07-10 20:13:01 -06:00
Jeremy Soller a0b06a2835 Merge branch 'master' of https://github.com/redox-os/kernel 2017-07-10 20:09:01 -06:00
Jeremy Soller ab738cede5 Restore kernel parameters on sigreturn 2017-07-10 20:08:57 -06:00
Jeremy Soller 8f6268eef7 Merge pull request #30 from ids1024/pipe
Revert "pipe: make read() return when write end is closed"
2017-07-10 17:10:16 -06:00
Ian Douglas Scott 79a45a2580 Revert "pipe: make read() return when write end is closed"
This reverts commit 09a67641c6.
2017-07-10 11:15:45 -07:00
Jeremy Soller b5ff0aabd5 WIP: Signal handling 2017-07-09 21:34:38 -06:00
Jeremy Soller 7e52541f39 Implement passthrough of futimens 2017-07-09 15:43:26 -06:00
Jeremy Soller 3f40af0687 Update to new allocator API 2017-07-08 19:50:58 -06:00
Jeremy Soller 22e87d94d4 Merge pull request #29 from ids1024/pipe
pipe: make read() return when write end is closed
2017-07-08 06:56:36 -06:00
Connor Wood fa24650ca7 Implemented opcodes 2017-07-08 10:20:33 +01:00
Ian Douglas Scott 09a67641c6 pipe: make read() return when write end is closed 2017-07-07 21:05:38 -07:00
Connor Wood 59936e25e6 Implemented match 2017-07-07 11:39:08 +01:00
Connor Wood 00591235e1 Implemented further opcodes in full, added get to context 2017-07-07 10:37:09 +01:00
Jeremy Soller ae5a32cf98 Merge pull request #28 from ids1024/dup
Pass empty second argument to dup in exec
2017-07-06 18:29:07 -06:00
Ian Douglas Scott 074ce2e57d Pass empty second argument to dup in exec 2017-07-06 16:44:54 -07:00
Jeremy Soller d0c3a5d2aa Merge pull request #27 from ids1024/clone
Pass empty second argument to dup() call in clone
2017-07-06 05:54:59 -06:00
Ian Douglas Scott b2df8d676f Pass empty second argument to dup() call in clone
I don't know if this was there for a reason, but it was making the dup()
fail with tcpd, and I don't seem this being handled specially in redoxfs
or anywhere else.
2017-07-05 22:45:27 -07:00
Jeremy Soller d4e295a385 Revert syscall path 2017-07-05 21:46:40 -06:00
Jeremy Soller 0e8e1b5c4e WIP: Signal handling 2017-07-05 21:45:53 -06:00
Connor Wood 980065d4d6 Fixed number of bugs 2017-07-05 14:36:40 +01:00
Connor Wood def456a8e5 Added object modification 2017-07-03 11:11:07 +01:00
Connor Wood 50ac9d3abe Added a context manager 2017-07-03 10:31:01 +01:00
Connor Wood 590610f4a5 Refactored parser to execute in the parse step for efficiency and simplicity 2017-07-02 13:07:43 +01:00
Jeremy Soller a4c3afb446 Merge pull request #26 from ids1024/getppid
Implement getppid system call
2017-06-29 06:34:49 -06:00
Ian Douglas Scott dddd87c2c3 Implement getppid system call 2017-06-28 22:05:01 -07:00
Jeremy Soller 12d487ec9c Merge pull request #19 from bjorn3/fix_warnings
Fix most lint warnings, check multicore code even if disabled
2017-06-26 06:52:50 -06:00
bjorn3 2dcd563709 Merge branch 'master' into fix_warnings 2017-06-26 14:22:17 +02:00
Connor Wood f72f97ef36 Rolled parsing and execution steps into one for namespace modifiers 2017-06-23 14:02:40 +01:00
Connor Wood 9fb15e7e92 Namespaces can now be concatenated, handling of SSDTs is now performed 2017-06-22 19:12:40 +01:00
Connor Wood be1a75e472 Finalized ACPIType 2017-06-22 16:25:19 +01:00
Connor Wood c83cefee08 Moved AccessType into namespace 2017-06-22 15:43:00 +01:00
Connor Wood fb0e5137e8 Moved ConnectFieldBufferData to the namespace 2017-06-22 15:22:19 +01:00
Connor Wood c8eca653b8 Moved ConnectFieldNameString into namespace 2017-06-22 15:09:04 +01:00
Connor Wood 0a67ad4b23 Moved DataRegion into namespace - more infrastructure required 2017-06-22 13:34:05 +01:00
Connor Wood 443c1ac1f8 Moved indexfield to namespace 2017-06-22 12:45:58 +01:00
Connor Wood 94e391c9b6 Moved arbitrary length buffer field into namespace 2017-06-22 12:23:14 +01:00
Connor Wood cef562c832 Moved BufferFields into namespace 2017-06-22 12:16:30 +01:00
Connor Wood 12e7d1ad4d Moved BankField to the namespace 2017-06-22 12:02:17 +01:00
Connor Wood 2e64cea81f Removed temporary files 2017-06-21 20:54:29 +01:00
Connor Wood 312aff03c4 Moved Event to namespace 2017-06-21 20:50:08 +01:00
Connor Wood 19ccb3612b Moved Mutex to namespace 2017-06-21 20:27:46 +01:00
Connor Wood fceba822eb Moved PowerResource into namespace 2017-06-21 20:13:44 +01:00
Connor Wood 636d94fd20 Moved Processor to namespace, and refactored namespace layout to use BTreeMap 2017-06-21 20:02:05 +01:00
Jeremy Soller 0478e5f7fb Merge pull request #25 from ids1024/env
Make env: return ENOENT on non-existent; support unlink()
2017-06-20 17:06:13 -06:00
Ian Douglas Scott b9f659dadf Make env: return ENOENT on non-existent; support unlink() 2017-06-20 15:56:44 -07:00
Connor Wood 7095219316 Moved ComputationalData::String into namespace 2017-06-19 14:12:26 +01:00
Connor Wood 3ed94405aa Moved DefDevice and DefThermalZone to namespace 2017-06-19 13:49:37 +01:00
Connor Wood 190686a853 Moved Alias to the namespace 2017-06-19 13:33:20 +01:00
Jeremy Soller cd67aabd5a Switch collections::boxed for alloc::boxed 2017-06-18 20:05:19 -06:00
Jeremy Soller bbcd5197a4 Aml parser (#24)
* Initial parser proof of concept

* Added better error handling to the parser

* Refactored into a better directory structure

* Parse package length

* Implemented named string, scope op

* Properly bounds checked namestring

* Fixed namestring regressions

* Started work parsing DefRegionOp. NB: As TermArg is not yet implemented, a bug is present parsing the address offset and length. Additionally, a bug was fixed in NameString

* Completed DefOpRegion implementation. TermArg remains unimplemented, stubbed out

* Implemented TermArg parsing

* Implemented integer parts of computational data

* Implemented defField, and associated FieldList. FieldElement still remains stubbed

* Implmenented FieldElement

* Implmenented named field

* Parsed DefMethod

* Parsed ToHexString

* Parsed ToBuffer

* Parsed both subtract and sizeof

* Fixed size bug in sizeof parsing

* Parsed Store, fixed a parse bug where Target should be a SuperName not a TermArg

* Parsed while

* Parsed LLess

* Parsed DerefOf

* Parse Index

* Parse increment

* Parse device

* Parse device

* Parsed create dword field

* Parsed if/else block

* Properly parsed Target, rendered an AST from existing parse code, and stubbed out MethodInvocation parser method

* Implemented deferred loading, and deferred method invocation parses

* Parsed Or

* Fixed a bunch of off-by-one errors. Shows what I get for copying code around

* Parsed Return

* Fixed a boolean logic error in the handling of the extended instruction namespace

* Added DefBuffer to ComputationalData

* Removed a temporary file

* Parsed ReservedField

* Parsed DefPackage, DefAnd, and ComputationalData::String

* Parsed DefMutex

* Parsed DefAlias and RevisionOp

* Parsed DebugObj

* Parsed DefRefOf

* Parsed type 6 opcodes

* Added ObjectReference and DDBHandle to DataRefObj parsing

* Parsed DefVarPackage, in both Type2OpCode, and in DataObj

* Parsed DefBankField

* Parsed AccessField

* Parsed ConnectField

* Parsed CreateBitField

* Parsed CreateByteField

* Parsed CreateWordField

* Parsed CreateQWordField

* Parsed CreateField

* Parsed DefDataRegion

* Parsed DefEvent

* Parsed IndexField

* Parsed DefPowerRes

* Parsed DefProcessor

* Parsed DefThermalZone:

* Parsed ExtendedAccessField

* Parsed DefBreak, DefBreakPoint, DefContinue and DefNoop (all type 1 opcodes with no parameters and one byte)

* Parsed DefFatal

* Parsed DefLoad

* Parsed DefNotify

* Parsed DefRelease

* Parsed DefReset

* Parsed DefSignal

* Parsed DefSleep

* Parsed DefStall

* Parsed DefUnload

* Parsed DefAcquire

* Parsed DefAnd

* Parsed DefConcat

* Parsed ConcatRes

* Switched Concat and ConcatRes opcodes

* Parsed CondRefOf

* Parsed DefDecrement and DefCopyObject

* Parsed DefDivide, fixed length calculation bug in a bunch of parse routines

* Parsed DefFindSetLeftBit

* Parsed DefFindSetRightBit

* Parsed DefFromBCD

* Parsed DefLAnd

* Parsed DefLGreater

* Parsed LNot

* Parsed DefLOr

* Parsed DefLoadTable

* Parsed DefMatch

* Parsed DefMid

* Parsed DefMod

* Parsed DefMultiply

* Parsed DefNAnd

* Parsed DefNOr

* Parsed DefNot

* Parsed DefObjectType

* Parsed DefShiftLeft and DefShiftRight

* Parsed DefTimer

* Parsed DefToBCD, DefToDecimalString, DefToInteger and DefToString

* Parsed DefXor

* Parsed DefWait

* Implemented a parser, abstract syntax tree, and basic infrastructure for the AML subsystem of the ACPI module. The entire AML grammar is parsed and placed into an abstract syntax tree, with one exception: method invocations, rather than parsing, defer the load until later on in the process, due to the way the grammar works.

Still to be done:
 - Refactor the code: a lot of the parser is very repetitive, and could easily be refactored with the aid of macros. This would reduce the length and improve legibility, though not affect function.
 - More rigorous testing of parser: the parser has, thus far, only been tested on the DSDT in QEMU. There may be bugs present that are hidden.
 - Parse the SSDTs: the SSDTs should be parsed after the DSDT, and contain more AML bytecode to be treated as modifying the same namespace. Adding this would be simple, though not urgent.
 - Transform the AST into a concrete executable tree: the CET is what will hold all information necessary to execute control methods and evaluate namespace objects. While this could be done in the AST, due to the way AML is laid out this would be very inefficient and require a lot of repetitive transformations every time something is to be executed. Therefore, perform the transformations upfront.
 - Parse the deferred loads, and the method invocations contained within: Once the AST has been rendered into a CET, sufficient information will be present to parse method invocations and add those to the namespace.
 - Bytecode interpreter: Once the CET has been finalized with method invocation parsing, it can then be called and executed.
 - Control method executor: this should walk the namespace, locating the relevant control method, then calling the interpreter on it.
 - Namespace enumerator: the executor shall use this to walk the namespace, and it should also be publicly accessible to allow outside code to determine what devices are present in the system.
 - Memory accessor API: ACPI AML has a concept of memory access in certain device domains - for example, the PCI BAR registers. These are all device specific offsets, therefore device drivers, or more accurately bus drivers, should be capable of installing handlers to manage this memory access.
 - CET concatenation: The DSDT and SSDTs all affect the same namespace, therefore concatenating the resulting trees should be possible.
 - Type checking: some operations in AML are typed. This should be handled at tree transformation time or earlier, and could indeed done in the parse step with some modification to the parser. This is currently not the case.

* Initial parser proof of concept

* Added better error handling to the parser

* Refactored into a better directory structure

* Parse package length

* Implemented named string, scope op

* Properly bounds checked namestring

* Fixed namestring regressions

* Started work parsing DefRegionOp. NB: As TermArg is not yet implemented, a bug is present parsing the address offset and length. Additionally, a bug was fixed in NameString

* Completed DefOpRegion implementation. TermArg remains unimplemented, stubbed out

* Implemented TermArg parsing

* Implemented integer parts of computational data

* Implemented defField, and associated FieldList. FieldElement still remains stubbed

* Implmenented FieldElement

* Implmenented named field

* Parsed DefMethod

* Parsed ToHexString

* Parsed ToBuffer

* Parsed both subtract and sizeof

* Fixed size bug in sizeof parsing

* Parsed Store, fixed a parse bug where Target should be a SuperName not a TermArg

* Parsed while

* Parsed LLess

* Parsed DerefOf

* Parse Index

* Parse increment

* Parse device

* Parse device

* Parsed create dword field

* Parsed if/else block

* Properly parsed Target, rendered an AST from existing parse code, and stubbed out MethodInvocation parser method

* Implemented deferred loading, and deferred method invocation parses

* Parsed Or

* Fixed a bunch of off-by-one errors. Shows what I get for copying code around

* Parsed Return

* Fixed a boolean logic error in the handling of the extended instruction namespace

* Added DefBuffer to ComputationalData

* Removed a temporary file

* Parsed ReservedField

* Parsed DefPackage, DefAnd, and ComputationalData::String

* Parsed DefMutex

* Parsed DefAlias and RevisionOp

* Parsed DebugObj

* Parsed DefRefOf

* Parsed type 6 opcodes

* Added ObjectReference and DDBHandle to DataRefObj parsing

* Parsed DefVarPackage, in both Type2OpCode, and in DataObj

* Parsed DefBankField

* Parsed AccessField

* Parsed ConnectField

* Parsed CreateBitField

* Parsed CreateByteField

* Parsed CreateWordField

* Parsed CreateQWordField

* Parsed CreateField

* Parsed DefDataRegion

* Parsed DefEvent

* Parsed IndexField

* Parsed DefPowerRes

* Parsed DefProcessor

* Parsed DefThermalZone:

* Parsed ExtendedAccessField

* Parsed DefBreak, DefBreakPoint, DefContinue and DefNoop (all type 1 opcodes with no parameters and one byte)

* Parsed DefFatal

* Parsed DefLoad

* Parsed DefNotify

* Parsed DefRelease

* Parsed DefReset

* Parsed DefSignal

* Parsed DefSleep

* Parsed DefStall

* Parsed DefUnload

* Parsed DefAcquire

* Parsed DefAnd

* Parsed DefConcat

* Parsed ConcatRes

* Switched Concat and ConcatRes opcodes

* Parsed CondRefOf

* Parsed DefDecrement and DefCopyObject

* Parsed DefDivide, fixed length calculation bug in a bunch of parse routines

* Parsed DefFindSetLeftBit

* Parsed DefFindSetRightBit

* Parsed DefFromBCD

* Parsed DefLAnd

* Parsed DefLGreater

* Parsed LNot

* Parsed DefLOr

* Parsed DefLoadTable

* Parsed DefMatch

* Parsed DefMid

* Parsed DefMod

* Parsed DefMultiply

* Parsed DefNAnd

* Parsed DefNOr

* Parsed DefNot

* Parsed DefObjectType

* Parsed DefShiftLeft and DefShiftRight

* Parsed DefTimer

* Parsed DefToBCD, DefToDecimalString, DefToInteger and DefToString

* Parsed DefXor

* Parsed DefWait

* Implemented a parser, abstract syntax tree, and basic infrastructure for the AML subsystem of the ACPI module. The entire AML grammar is parsed and placed into an abstract syntax tree, with one exception: method invocations, rather than parsing, defer the load until later on in the process, due to the way the grammar works.

Still to be done:
 - Refactor the code: a lot of the parser is very repetitive, and could easily be refactored with the aid of macros. This would reduce the length and improve legibility, though not affect function.
 - More rigorous testing of parser: the parser has, thus far, only been tested on the DSDT in QEMU. There may be bugs present that are hidden.
 - Parse the SSDTs: the SSDTs should be parsed after the DSDT, and contain more AML bytecode to be treated as modifying the same namespace. Adding this would be simple, though not urgent.
 - Transform the AST into a concrete executable tree: the CET is what will hold all information necessary to execute control methods and evaluate namespace objects. While this could be done in the AST, due to the way AML is laid out this would be very inefficient and require a lot of repetitive transformations every time something is to be executed. Therefore, perform the transformations upfront.
 - Parse the deferred loads, and the method invocations contained within: Once the AST has been rendered into a CET, sufficient information will be present to parse method invocations and add those to the namespace.
 - Bytecode interpreter: Once the CET has been finalized with method invocation parsing, it can then be called and executed.
 - Control method executor: this should walk the namespace, locating the relevant control method, then calling the interpreter on it.
 - Namespace enumerator: the executor shall use this to walk the namespace, and it should also be publicly accessible to allow outside code to determine what devices are present in the system.
 - Memory accessor API: ACPI AML has a concept of memory access in certain device domains - for example, the PCI BAR registers. These are all device specific offsets, therefore device drivers, or more accurately bus drivers, should be capable of installing handlers to manage this memory access.
 - CET concatenation: The DSDT and SSDTs all affect the same namespace, therefore concatenating the resulting trees should be possible.
 - Type checking: some operations in AML are typed. This should be handled at tree transformation time or earlier, and could indeed done in the parse step with some modification to the parser. This is currently not the case.

* Partial refactor of AML code

* Further refactoring

* Fully refactored type 2 opcode selector

* Refactored type 6 opcode selector

* Further refactored Type 2 opcode parsing

* Implemented basic infrastructure in order to render the AST down to a namespace object

* Resolved scopes into the namespace

* Put OpRegion into namespace

* Rendered field parsing to the namespace object

* Methods now placed in namespace

* Moved DefName into the namespace

* Moved packages into the namespace

* Converted shutdown sequence to use AML parser

* Moved shutdown over to use AML parsing fully

* Removed the no longer needed DSDT code

* Better messages on unmapping failure

* Disable preemption until paging bug is fixed

* Refactor kernel mapping so that symbol table is mapped

* Add symbol lookup (still very WIP)

* Improve method of getting symbol name

* Reenable preemption

* Demangle symbols

* Fix overallocation

* Remove tilde files
2017-06-17 18:47:27 -06:00
Jeremy Soller 73a71a7d85 Increase size of kernel heap when live disk is loaded 2017-06-17 14:32:31 -06:00
Jeremy Soller 85c02365c9 Fix overallocation 2017-06-14 20:26:05 -06:00
Jeremy Soller c9cbdab9f1 Demangle symbols 2017-06-14 20:25:49 -06:00
Jeremy Soller 7ef2401db3 Reenable preemption 2017-06-14 20:25:38 -06:00
Jeremy Soller 9b19ab9439 Improve method of getting symbol name 2017-06-13 21:56:20 -06:00
Jeremy Soller acab23d1e1 Add symbol lookup (still very WIP) 2017-06-13 21:43:37 -06:00
Jeremy Soller d6354aeb56 Refactor kernel mapping so that symbol table is mapped 2017-06-13 20:42:04 -06:00
Jeremy Soller 8b05863ebb Disable preemption until paging bug is fixed 2017-06-13 19:10:32 -06:00
Jeremy Soller e3020db04f Better messages on unmapping failure 2017-06-11 08:40:27 -06:00
Jeremy Soller 8d89925842 Align ELF segments to avoid subtract overflow 2017-06-04 18:34:45 -06:00
Jeremy Soller 138463b74a Merge pull request #21 from ids1024/unique
Update for changes in std::ptr::Unique API
2017-06-02 20:56:01 -06:00
Ian Douglas Scott 3c5b262b0e Update for changes in std::ptr::Unique API 2017-05-21 13:44:10 -07:00
Jeremy Soller 4d2808a012 Remove free count print 2017-05-12 21:04:52 -06:00
Jeremy Soller 32b0c06314 Remove hardcoded live filesystem 2017-05-11 21:16:07 -06:00
Jeremy Soller 62d3f4bd93 Add Xargo support 2017-05-10 21:38:40 -06:00
bjorn3 586f249069 Add trailing newline to Cargo.toml 2017-04-29 17:52:55 +02:00
bjorn3 6f6f8f7391 Check multicore code even if disabled 2017-04-29 17:46:36 +02:00
bjorn3 37b4ac151b Fix some warnings 2017-04-29 17:45:43 +02:00
Jeremy Soller b3a25bd3a3 Merge pull request #14 from bjorn3/ls_root_scheme
Ls root scheme
2017-04-29 06:49:55 -06:00
Jeremy Soller d8630faccb Merge pull request #15 from bjorn3/remove_pit_ticks_assert
Remove PIT_TICKS assert
2017-04-29 06:40:28 -06:00
bjorn3 248cfa51ae Remove PIT_TICKS assert 2017-04-29 10:46:07 +02:00
bjorn3 ca8b6f522e Fix closing ls handle 2017-04-29 10:43:50 +02:00
bjorn3 8ffe704e7a Remove yet another unnecessary change 2017-04-28 18:44:37 +02:00
bjorn3 4441b750cf Remove unnecessary change 2017-04-28 18:43:39 +02:00
bjorn3 c9fdc4beae Make it working 2017-04-28 18:42:33 +02:00
bjorn3 4c006bca48 Remove UserOrListHandle 2017-04-28 16:18:41 +02:00
bjorn3 80afcc8879 Implement listing all schemes using : scheme 2017-04-28 15:40:15 +02:00
Jeremy Soller 0a457bdced Merge pull request #12 from InsidiousMind/fix-pit-not-context-switching
Fix PIT Interrupt Not Context Switching [irq]
2017-04-25 17:41:55 -06:00
Andrew Plaza 2fc4454f5e set PIT_TICKS to 0 in context::switch() 2017-04-25 16:59:14 -04:00
Andrew Plaza 5ba02ca940 Reset PIT_TICKS to 0 on context::switch, change condition for context::switch [irq]
Set the counter to 0 when context is to be switched in the PIT interrupt,
and change the condition for context switching from % 10 to >= 10.
2017-04-25 14:40:23 -04:00
Andrew Plaza 7127e14b5d Fix PIT Interrupt Not Context Switching [irq]
PIT interrupt should context switch or else all of redox crashes.
This will fix programs like the Snake game crashing all of Redox.
A global AtomicUSize counter was added, and a line to switch contexts
on every 10 PIT interrupts in irq.rs.
2017-04-24 22:07:32 -04:00
Jeremy Soller dd98bfec5c Fix typo in live scheme 2017-04-19 22:00:30 -06:00
Jeremy Soller efd64d55e1 Bug fixes for fcntl and o_cloexec
Add fcntl to schemes
Fix debug: hang
2017-04-19 21:56:09 -06:00
Jeremy Soller 40ff16e42d Add __rust_allocate_zeroed to work with newest nightly 2017-04-18 21:26:18 -06:00
Jeremy Soller d036c667a1 Perform cloexec logic in kernel 2017-04-16 12:49:54 -06:00
Jeremy Soller ea1150cd9b Implement CLOEXEC for root scheme and initfs 2017-04-15 22:35:05 -06:00
Jeremy Soller 9d39317f95 Fix issue where ppid changes during child close 2017-04-15 20:29:08 -06:00
Jeremy Soller 66120cf201 Fix deallocation issues by ignoring deallocation on temporary page 2017-04-15 19:56:48 -06:00
Jeremy Soller 800e6c6de7 Free page tables during unmap, if empty 2017-04-15 19:22:17 -06:00
Jeremy Soller 1e8df4b905 Add sys:iostat 2017-04-15 09:58:03 -06:00
Jeremy Soller a38f32c735 Add path implementation to most kernel schemes 2017-04-15 09:50:02 -06:00
Jeremy Soller 7b5873e460 Allow allocation of larger sizes 2017-04-14 21:17:31 -06:00
Jeremy Soller b3a3caf191 Fix memmove 2017-04-14 21:07:02 -06:00
Jeremy Soller 6fef10bcb1 Merge branch 'master' of https://github.com/redox-os/kernel 2017-04-14 20:59:32 -06:00
Jeremy Soller a9d92df5fa Implement frame recycler 2017-04-14 20:59:27 -06:00
Jeremy Soller 903432f057 Fix issue with reusing temporary page frame 2017-04-14 20:59:01 -06:00
Jeremy Soller 7c1d5d8306 Disable SMP startup, fix issue with reusing trampoline frame 2017-04-14 20:58:23 -06:00
Jeremy Soller 0a72d1cbd8 Merge pull request #11 from pi-pi3/faster-externs
A faster implementation of the memcpy family
2017-04-14 16:49:58 -06:00
pi_pi3 5c1e619063 Avoid multiplication in memcpy family functions
Instead of multiplying everything by 8[/4], now addition is used. That
way code is prettier.
2017-04-14 14:51:04 +02:00
pi_pi3 c4fc76f844 A faster implementation of the memcpy family
The default implementation of the memcpy, memmove, memset and memcmp
functions in the kernel file `extern.rs` uses a naive implementation
by copying, assigning or comparing bytes ony by one. This can be slow.
This commit proposes a reimplementation of those functions by copying,
assigning or comparing in group of 8 bytes by using the u64 type and
its respective pointers instead of u8. Alternative version for 32-bit
architectures are also supplied for future compatibility with x86.
Both version first copy whatever they can with wide word types. The
tail, i.e. the final few bytes that do not fit in a dword or qword
are then copied byte by byte.

Here is a comparison of copying 64kiB (65536 bytes) on stack:

x86_64-unknown-linux-gnu: (64-bit)
       | naive (ns) | fast (ns) | speedup (x)
-------|------------|-----------|------------
memcpy |   204430   |   32994   |   ~6.20
memmove|   202540   |   33186   |   ~6.10
memset |   163391   |   23884   |   ~6.84
memcmp |   205663   |   34385   |   ~5.98

i686-unknown-linux-gnu: (32-bit)
       | naive (ns) | fast (ns) | speedup (x)
-------|------------|-----------|------------
memcpy |   206297   |   66858   |   ~3.09
memmove|   204576   |   70326   |   ~2.91
memset |   165599   |   50227   |   ~3.30
memcmp |   204262   |   70572   |   ~2.89

Copying on the heap behaves simmilarly.

All tests performed on Intel i5 6600K (4x4.2GHz),
ArchLinux Kernel 4.8.12-3 x86_64.
2017-04-14 14:37:32 +02:00
Jeremy Soller 56a533fbbc Add linker flavor 2017-04-13 19:46:48 -06:00
Jeremy Soller 4204d9905e Merge branch 'master' of https://github.com/redox-os/kernel 2017-04-11 21:27:44 -06:00
Jeremy Soller c4fb60f216 Implement script file support 2017-04-11 21:27:39 -06:00
Jeremy Soller d9e95448a4 Merge pull request #10 from xTibor/fix_initfs
Fix the listing of `initfs:` directories
2017-04-11 06:23:28 -06:00
xTibor 1f5bea611d Fix the listing of initfs: directories
There was a bug at the `initfs` generation which made the listing of the contents of the `initfs:`subdirectories impossible from the command line.

The subdirectory listing data had the full paths of the files (like `bin/ahcid\nbin/bgad\n...`) when it should just only be the names of the files (`ahcid\nbgad\n...`)
2017-04-11 05:26:10 +02:00
Jeremy Soller e43f5dda81 Implement timeouts
Cleanup utf8 path error handling
2017-04-08 21:59:30 -06:00
Jeremy Soller b286e69c9d Fix shutdown by disabling APs 2017-04-07 21:49:32 -06:00
Jeremy Soller a7f35e14cc Cleanup debug scheme 2017-04-05 20:11:51 -06:00
Jeremy Soller d26a9ee990 Fix goblin include 2017-04-05 19:10:17 -06:00
Jeremy Soller e860c9efdc Merge pull request #9 from redox-os/refactor
Refactor
2017-04-05 17:36:36 -06:00
Jeremy Soller 2087544ea7 Move all files to src 2017-04-03 21:47:01 -06:00
Jeremy Soller ff93e9cb82 Cleanup some 2017-04-03 21:16:50 -06:00
Jeremy Soller be7f8d64e6 Increase kernel heap, use crates version of goblin 2017-04-01 21:10:55 -06:00
Jeremy Soller cbacd0eea7 Merge pull request #7 from AdamNiederer/patch-1
Fix spelling & grammar in README.md
2017-03-27 06:56:01 -06:00
Adam Niederer 0ae08c52f6 Fix spelling & grammar in README.md 2017-03-26 22:51:28 -04:00
Jeremy Soller 7817122662 Loop on serial input
Fix issue with serial and cascade interrupts not being ackd
2017-03-24 20:38:02 -06:00
Jeremy Soller 906ef94ffd Fix bug with sleep - wake is not cleared after it occurs
Do not initialize waitcondition with capacity
2017-03-21 20:30:46 -06:00
Jeremy Soller ffd7594971 Disable century register for now 2017-03-20 21:47:18 -06:00
Jeremy Soller 228cd79cd4 Refactor ACPI, implement poweroff correctly using the DSDT in ACPI 2017-03-19 16:45:19 -06:00
Jeremy Soller e726234bc6 Fix style of new ACPI code, reduce warnings 2017-03-19 09:34:54 -06:00
Jeremy Soller 643e1f6552 Merge pull request #6 from CWood1/rtc-century
Implemented reading from RTC Century counter in x86_64 arch, if available
2017-03-19 07:29:30 -06:00
Connor Wood f79424aeac Fully implemented reading the RTC century counter, and laid out initial infrastructure for ACPI information to be used across the kernel, in the x86_64 architecture.
- Implemented a global variable, ACPI_TABLE, behind a mutex, which contains the ACPI information pertinent to the rest of the kernel, currently solely containing a pointer to the FADT.
- Split device initialization into two categories - "core" devices, such as the PIC and local APIC, necessary for initializing the rest of the kernel, and "non-core" devices such as serial and RTC, which are to be initialized last.
- Checked for the presence of the century register, and consequentially read from, in the RTC code, now factored into the date calculation. The location of the register is pulled from the "century" field in the FADT.
- Modified page unmapping in the ACPI code, such that any tables to be stored globally (currently only the FADT) are not unmapped after reading, such that they can be stored in globally accessible pointers without causing page faults.
2017-03-18 16:08:45 +00:00
Connor Wood 661ebb6390 Saved FADT in a pointer accessible elsewhere in the kernel 2017-03-18 15:12:42 +00:00
Jeremy Soller 1d5c7d6a4e Merge branch 'master' of https://github.com/redox-os/kernel 2017-03-16 22:50:16 -06:00
Jeremy Soller 05bb497fe4 Use normal EOI mode 2017-03-16 22:50:09 -06:00
Jeremy Soller ab4193d4fc Merge pull request #5 from tones111/cpuid_panic
Prevent cpuid get_extended_function_info panic
2017-03-16 22:15:02 -06:00
Paul Sbarra d667fa61e6 Prevent cpuid get_extended_function_info panic
A kernel panic occurs on some CPUs (notably qemu-system-x86_64) when
calling rust-cpuid's get_extended_function_info.  This is fixed upstream
in commit c3ebfc553cdff98d19d29777fd85c4f9182bfb66 but has yet to make
it crates.io.

The panic can by triggered by running "ls sys:" from ion and causes
redox to become unresponsive.
2017-03-16 22:32:57 -05:00
Jeremy Soller 7dd8de777d Merge pull request #3 from kolipka/standalone_support
Remove hardcoded initfs folder
2017-02-27 11:18:03 -07:00
Konrad Lipner 5ccbd788f3 Remove hardcoded initfs folder
initfs folder should be specified in INITFS_FOLDER environment variable
As a result kernel module can be compiled on it's own.
2017-02-15 21:54:38 +01:00
Jeremy Soller b9793deb59 Disable secondary processors with hlt 2017-02-13 22:15:42 -07:00
Jeremy Soller 473a7b6832 USe auto-eoi mode, mask off interrupts that happen and allow userspace to clear the mask 2017-02-11 21:09:16 -07:00
Jeremy Soller 0e22ba24be Initialize PIC in Rust 2017-02-11 20:54:14 -07:00
Jeremy Soller 571b2aa2e7 Add reminder 2017-02-07 22:14:53 -07:00
Jeremy Soller 776bb83a70 Unstick system by acknowledging IRQs on boot 2017-02-07 22:14:28 -07:00
Jeremy Soller be43673df6 Merge pull request #2 from little-dude/master
remove unused #[macro_use]
2017-01-24 12:48:08 -07:00
Corentin Henry 4d2499e4d3 remove unused #[macro_use] 2017-01-24 11:14:12 -08:00
Jeremy Soller 0d3aa234ff Add target definitions 2017-01-16 10:10:16 -07:00
Jeremy Soller 04d9d6b40a Specify crates.io versions 2017-01-13 15:09:56 -07:00
Jeremy Soller 35c2297724 Fix from @yoric - incorrect initialization of spin loop 2017-01-11 13:59:10 -07:00
Jeremy Soller ed69fac232 Allow memory: to be accessed in all namespaces 2017-01-10 09:59:30 -07:00
Jeremy Soller ba4588e84f Simplify path parsing 2017-01-10 09:22:59 -07:00
Jeremy Soller 433746e13c Move skipping to loop encompasing entire path 2017-01-10 09:19:02 -07:00
Jeremy Soller e20135575c Refactor to move alloc_kernel in tree, and move io into syscall 2017-01-09 20:35:54 -07:00
Jeremy Soller 1c7b5680a4 Use syscall crate from git 2017-01-09 19:47:44 -07:00
Jeremy Soller 375e8addd2 Merge pull request #1 from cactorium/master
Allow for more complicated directory paths
2017-01-07 07:37:10 -07:00
Kelvin Ly b0cafc1890 Correctly handle relative paths starting from the root directory 2017-01-07 08:00:16 -05:00
Kelvin Ly 046d8ac0c5 Fix typo and add functionality to more properly handle the parent of the root of the filesystem 2017-01-07 00:49:45 -05:00
Kelvin Ly fc94bd411a Allow for more complicated directory paths 2017-01-07 00:41:32 -05:00
Jeremy Soller 06118a23dd Remove profiles 2017-01-04 16:33:51 -07:00
Jeremy Soller 882e64bdb9 Ignore Cargo.lock and target 2017-01-04 15:52:38 -07:00
Jeremy Soller 0c8ba636f4 Cleanup Redox repo, update Rust, remove old target 2017-01-03 15:55:00 -07:00
Jeremy Soller 04ed700216 Force flush of tables 2017-01-03 14:09:15 -07:00
Jeremy Soller 2cb8b1fd53 Use variable for temporary page location 2017-01-01 18:00:24 -07:00
Jeremy Soller 5ddd2ca458 Update coreutils, remove sys:memory 2016-12-28 17:22:10 -07:00
Jeremy Soller aebe7152ce Add memory scheme to live configuration 2016-12-28 12:42:54 -07:00
Jeremy Soller eb3f76f204 Add memory scheme, implement fstatvfs 2016-12-28 11:38:42 -07:00
Jeremy Soller 164648c200 Compile using real libstd, with no crate overrides 2016-12-27 16:47:08 -07:00
Jeremy Soller 515aa3671b Implement dup2. Add debugging lines. 2016-12-27 11:18:41 -07:00
Jeremy Soller 6c308ada46 Workaround for an issue where a leftover grant is not unmapped before reap 2016-12-13 20:41:43 -07:00
Jeremy Soller 4b5271b52b Remove debug message 2016-12-06 15:27:49 -07:00
Jeremy Soller a46a68b5c7 Use isohybrid to generate a USB stick friendly ISO
Add assertions to verify that grants are unmapped
Fix grant unmapping in exec and exit, thus fixing some crashes without network cards
2016-12-06 14:47:05 -07:00
Jeremy Soller 528ce22617 More path cleanup 2016-11-29 18:15:53 -07:00
Jeremy Soller ddac22a242 Cleanup path usage 2016-11-29 18:14:10 -07:00
Jeremy Soller cc9fd700cf Update to make libstd use redox_syscall 2016-11-28 18:14:21 -07:00
Jeremy Soller 2b302bd6ea Implement O_DIRECTORY, switch to open for mkdir 2016-11-25 18:24:38 -07:00
Jeremy Soller bbe2dd0ff4 Implement rfc 4 2016-11-25 12:09:54 -07:00
Jeremy Soller 5ef013eecf Fix warnings, increase size of fs 2016-11-19 20:23:25 -07:00
Jeremy Soller b17444e3ce Allow compiling both livedisk and harddrive 2016-11-19 20:19:41 -07:00
Jeremy Soller 6b084d3ff5 Allow initfs to be written 2016-11-18 08:46:11 -07:00
Jeremy Soller 71fbf2e8f4 Add statvfs 2016-11-18 08:44:03 -07:00
Jeremy Soller f2e15b81bd Update orbutils, fix warnings 2016-11-17 14:23:41 -07:00
Jeremy Soller a5f95cd2b1 Replace setuid, setgid with setreuid, setregid 2016-11-17 14:16:39 -07:00
Jeremy Soller 1fe0dae848 Cleanup zombies in container - show scheme namespace in context list 2016-11-17 12:24:46 -07:00
Jeremy Soller 93d43f7dbc Add signal support - exit on signal 2016-11-17 12:12:02 -07:00
Jeremy Soller 3da2ea9d9a More advanced setns syscall 2016-11-16 22:14:02 -07:00
Jeremy Soller c290fd78db Add ability to contain a process in a scheme sandbox 2016-11-16 20:54:38 -07:00
Jeremy Soller 0dd2befe4d Pass through fcntl 2016-11-15 17:09:28 -07:00
Jeremy Soller a9c7a4e773 Update to add chmod 2016-11-15 17:08:14 -07:00
Jeremy Soller 3e5a43d47d Update syscall and rust, add fcntl for permissions 2016-11-15 16:12:51 -07:00
Jeremy Soller 3363859cb7 FileHandle from in exec close 2016-11-15 14:09:08 -07:00
Jeremy Soller 7c35351dc2 Merge branch 'cap2' of https://github.com/Yoric/redox into Yoric-cap2 2016-11-15 14:05:43 -07:00
Jeremy Soller 41f8e349af Pass clone and exec to dup to identify dup location, make exec dup to implement cloexec 2016-11-14 20:55:31 -07:00
Jeremy Soller 7a241b28bf Add sys:exe to get current executable 2016-11-14 20:54:33 -07:00
Jeremy Soller 3469310a19 Add fcntl 2016-11-14 12:15:34 -07:00
Jeremy Soller a7bfe1232a Implement more test arch features 2016-11-14 11:04:31 -07:00
Jeremy Soller c3f38be7ca Use core intrinsics instead of memset 2016-11-14 10:50:00 -07:00
David Teller 53c2c7a332 Converting file handles into a new type FileHandle
Keeping file handles (and pids, and scheme id, ...) as usize is a
footgun. Let's remove it.
2016-11-14 07:46:43 +01:00
David Teller 008ca3c207 Converting pids into a new type ContextId
Keeping pid (and file descriptor, and scheme id, ...) as usize is a
footgun. Let's remove it.
2016-11-14 07:46:43 +01:00
David Teller 3aa2f2d0c4 Converting scheme ids into a new type SchemeId
Keeping scheme ids (and pids, and file handles, ...) as usize is a
footgun. Let's remove it.
2016-11-14 07:46:43 +01:00
David Teller c7735dd177 Introducing macros for defining SchemeId, Pid, ... 2016-11-14 07:46:43 +01:00
Jeremy Soller 99a15e791d Get CPU features 2016-11-07 13:56:02 -07:00
Jeremy Soller 25988d6b71 Add memory information 2016-11-07 12:47:32 -07:00
Jeremy Soller e3f7c9a692 Update scheme documentation 2016-11-04 13:38:40 -06:00
Jeremy Soller 194b674155 Add some documentation 2016-11-03 20:29:19 -06:00
Jeremy Soller e9ae9b190c Fix eventing in kernel 2016-11-03 16:02:44 -06:00
David Teller dcf0a21da2 Improving self-documentation of the implementation of Registry. (#732) 2016-11-03 09:06:44 -06:00
pythoneer 6b8b7c03ab increase process id range (#729) 2016-11-03 07:36:12 -06:00
Jeremy Soller 3fc5e52c64 Remove resource_sceme, Fix syscall crate name, add fmap 2016-11-02 19:48:25 -06:00
Jeremy Soller 190ccc2ef1 Fix #725 by checking mode in chdir 2016-11-01 14:49:51 -06:00
Jeremy Soller fb20ed5436 Add contributing and readme 2016-11-01 12:04:50 -06:00
Jeremy Soller dc53add6a9 Correct init process, allow waiting on any children, reap zombies in init 2016-11-01 11:04:53 -06:00
Jeremy Soller a33ddef38f remove take message 2016-10-31 22:12:10 -06:00
Jeremy Soller 7952e3ed63 Add null: and zero: 2016-10-31 21:54:56 -06:00
Jeremy Soller aad20b0e8b Remove debugging 2016-10-31 19:40:27 -06:00
Jeremy Soller fd71b5e3f1 Fixes for TLS 2016-10-31 19:09:22 -06:00
Jeremy Soller b98a814dfc Remove rd/wrfsbase 2016-10-31 18:04:28 -06:00
Jeremy Soller ed9c2b9d6c Smp (#23)
* Fire up multiple processors

* Use IPIs to wake up secondary processors

* Much better exception information

* Modifications to show more information on fault

* WIP: Use real libstd

* Add TLS (not complete)

* Add random function, export getpid, cleanup

* Do not spin APs until new context

* Update rust

* Update rust

* Use rd/wrfsbase

* Implement TLS

* Implement compiler builtins and update rust

* Update rust

* Back to Redox libstd

* Update rust
2016-10-31 10:49:00 -06:00
Jeremy Soller 1a1fb1f5e1 Redo networking (#22)
* Rewriting network functions

* Add buffer to dup
Fix non-blocking handling by triggering once on enabling events to read to EOF

* Modifications for UDP API

* Implement TCP client side

* Add active close

* Add DMAR parser

* Implement basic TCP listening. Need to improve the state machine

* Reduce debugging

* Fixes for close procedure

* Updates to fix path processing in libstd
2016-10-26 13:19:56 -06:00
David Teller 580f30e520 Documenting use of enable_and_halt(). (#21) 2016-10-24 16:03:03 -06:00
Jeremy Soller e7a4b786b0 Add CPU ID lock 2016-10-23 11:24:10 -06:00
Jeremy Soller c680f2531e Make all perCPU mappings available in all contexts - this will allow APs to pick up threads 2016-10-23 09:13:12 -06:00
Jeremy Soller ad152ad968 Remove unnecessary context switch in waitpid 2016-10-20 21:50:11 -06:00
Jeremy Soller a97aa95c23 Improve wait condition performance 2016-10-20 21:49:47 -06:00
Jeremy Soller 962836aa47 Do not block on IRQ read, add more debugging to RTL8168/9 2016-10-20 15:49:17 -06:00
Jeremy Soller 9c3a06b8f9 Add nonblocking root scheme 2016-10-20 12:31:39 -06:00
Jeremy Soller 71ff7af970 Send multiple events if there are multiple packets 2016-10-14 22:06:43 -06:00
Jeremy Soller 99fee86ef9 Significant improvements for events - switch to event queue in orbital 2016-10-14 20:12:21 -06:00
Jeremy Soller bc72488851 Allow O_NONBLOCK to be passed to pipe 2016-10-14 19:34:00 -06:00
Jeremy Soller f852450610 Add specification to vesad
Fix piping
Fix bug where resources are not closed
Add arpd
Remove question_mark features
2016-10-14 18:22:57 -06:00
Jeremy Soller 92b4514895 Fixes for updating submodules 2016-10-14 12:00:25 -06:00
Jeremy Soller c294b5b92c Disable orbital by default 2016-10-13 21:19:02 -06:00
Jeremy Soller 2fc605a88d Allow schemes to be listed 2016-10-13 21:13:37 -06:00
Jeremy Soller c484241e1c Add sys scheme to allow inspection of processes. WIP: Signals. 2016-10-13 21:00:51 -06:00
Jeremy Soller d778f0b040 Orbital (#16)
* Port previous ethernet scheme

* Add ipd

* Fix initfs rebuilds, use QEMU user networking addresses in ipd

* Add tcp/udp, netutils, dns, and network config

* Add fsync to network driver

* Add dns, router, subnet by default

* Fix e1000 driver. Make ethernet and IP non-blocking to avoid deadlocks

* Add orbital server, WIP

* Add futex

* Add orbutils and orbital

* Update libstd, orbutils, and orbital
Move ANSI key encoding to vesad

* Add orbital assets

* Update orbital

* Update to add login manager

* Add blocking primitives, block for most things except waitpid, update orbital

* Wait in waitpid and IRQ, improvements for other waits

* Fevent in root scheme

* WIP: Switch to using fevent

* Reorganize

* Event based e1000d driver

* Superuser-only access to some network schemes, display, and disk

* Superuser root and irq schemes

* Fix orbital
2016-10-13 17:21:42 -06:00
Jeremy Soller 7841f3617a Time (#11)
* WIP: Time syscalls

* Count time from PIT using low tickrate

* Implement realtime

* Implement nanosleep with a tight loop
2016-10-06 20:50:14 -06:00
Jeremy Soller 7a96e6c9be Add pipe2 2016-10-06 18:46:24 -06:00
Jeremy Soller df87992af4 Add sudo command, add effective UID and GID, and groups file 2016-10-05 20:31:59 -06:00
Jeremy Soller 965941cd1c Implement unix permissions 2016-10-05 18:01:05 -06:00
Jeremy Soller ea4fa78f72 Merge branch 'encoded_syscall' 2016-10-05 15:43:35 -06:00
Jeremy Soller 82d2c49543 Add permissions to the filesystem, preliminary permissions to the syscalls 2016-10-05 14:24:08 -06:00
Jeremy Soller 4f73b7b5a5 Implement vfork 2016-09-28 21:33:54 -06:00
Jeremy Soller fc5a35d22a 64-bit stat size, read entire executable in one go 2016-09-28 20:42:03 -06:00
Jeremy Soller bfaa564afd Fix CWD without trainling slash 2016-09-28 11:52:29 -06:00
Jeremy Soller d50a1485a7 mkdir and rmdir 2016-09-28 11:26:49 -06:00
Jeremy Soller af5b43ca0b Fix dup 2016-09-28 11:22:01 -06:00
Jeremy Soller 62d151c9e8 Unlink syscall 2016-09-28 11:18:28 -06:00
Jeremy Soller f79570d42f Fix kernel user scheme fpath 2016-09-28 10:29:17 -06:00
Jeremy Soller 2c9a953295 Remove unnecessary slash 2016-09-26 17:39:58 -06:00
Jeremy Soller bc4f29d3c8 WIP: AHCI drivers and more memory syscalls 2016-09-26 17:00:06 -06:00
Jeremy Soller 5877c8ac16 Encode many of the file syscalls 2016-09-25 11:20:59 -06:00
Jeremy Soller 1e2e5a5d31 Event support - demonstration in example scheme 2016-09-23 17:54:39 -06:00
Jeremy Soller e390c2d00c WIP: Kevent 2016-09-23 15:47:53 -06:00
Jeremy Soller 3034daac31 Add env 2016-09-23 11:01:53 -06:00
Jeremy Soller 750a2c1f9d Fix path lookup 2016-09-22 21:27:33 -06:00
Jeremy Soller 879d582e44 Implement fpath in initfs 2016-09-22 21:13:17 -06:00
Jeremy Soller bbacabce4f Trim in env scheme, do not debug initfs 2016-09-22 20:49:28 -06:00
Jeremy Soller 733a812259 Folders in initfs 2016-09-22 20:26:33 -06:00
Jeremy Soller fcc701cf66 Bring in some coreutils 2016-09-22 19:38:09 -06:00
Jeremy Soller 35ad65bbda Enable SSE and FPU 2016-09-22 16:14:45 -06:00
Jeremy Soller 2e9697353c Add wnohang, make PS/2 driver write input to display scheme, which then passes it to the shell 2016-09-22 10:10:27 -06:00
Jeremy Soller 57b50ba819 Add login process. Remove debugging. Fix order of arguments 2016-09-22 08:43:22 -06:00
Jeremy Soller 10a6e148f0 WIP: Userspace console 2016-09-21 12:18:48 -06:00
Jeremy Soller ec240ef778 Clone grants 2016-09-20 22:14:08 -06:00
Jeremy Soller b01eb8e47b WIP: VESA driver. Make initfs generated by code 2016-09-20 21:52:45 -06:00
Jeremy Soller 2b6fae0138 Validate memory pointers 2016-09-20 18:03:14 -06:00
Jeremy Soller e2ec6fd220 Implement more system calls 2016-09-20 16:57:45 -06:00
Jeremy Soller 4ee9a6b492 Create example userspace scheme. Remove kernel duplication of syscalls, use syscall crate instead 2016-09-20 16:23:28 -06:00
Jeremy Soller 3ae7dc8d98 Grant to allow passing data to scheme handler 2016-09-20 14:50:04 -06:00
Jeremy Soller 863c59d3c2 Increase buffer size when reading executable, update libstd 2016-09-20 09:51:26 -06:00
Jeremy Soller eeb1cd0a52 Fix deadlock 2016-09-20 09:21:54 -06:00
Jeremy Soller 7a5d9d440c Implement user schemes. Example in pcid. Currently deadlocks in UserInner 2016-09-20 08:47:16 -06:00
Jeremy Soller 2f06e18743 WIP: User scheme 2016-09-19 21:24:54 -06:00
Jeremy Soller fcbc8951da Minimize locking in schemes. Reenable pcid and ion launch in init. WIP: Userspace schemes 2016-09-19 18:29:28 -06:00
Jeremy Soller fe234e4bf1 Remove warnings 2016-09-19 17:28:22 -06:00
Jeremy Soller 5276c76963 PS/2 driver convert to char 2016-09-19 10:24:19 -06:00
Jeremy Soller 298d999300 Seperate PS/2 keyboard and mouse driver 2016-09-19 09:43:30 -06:00
Jeremy Soller 4403e3e7ac Allow userspace to handle IRQs (WIP). Create basic keyboard handler 2016-09-18 20:17:08 -06:00
Jeremy Soller de53701ed9 Add mechanism to read IRQ count 2016-09-18 18:59:46 -06:00
Jeremy Soller af2f6fc6df Add fsync. Add env scheme, currently hardcoded to get ion to launch. Make serial IRQ send data to debug scheme 2016-09-18 17:55:35 -06:00
Jeremy Soller 8ba97b8cff Canonicalize paths in open 2016-09-18 12:54:10 -06:00
Jeremy Soller 4821357934 Complete execve - add argument support using safe ABI 2016-09-17 21:44:50 -06:00
Jeremy Soller 75016bfe39 Update libstd. Add CWD and associated syscalls. Remove debugging 2016-09-17 19:01:34 -06:00
Jeremy Soller c5afb10b00 Add exit status to status enum 2016-09-17 09:23:36 -06:00
Jeremy Soller 959ecdad04 Fix creation of kstack 2016-09-17 09:18:35 -06:00
Jeremy Soller 9bc242c179 Implement the typical use of waitpid 2016-09-16 18:50:47 -06:00
Jeremy Soller 5f570fa5b4 Allow cloning of files and memory 2016-09-16 18:27:54 -06:00
Jeremy Soller 91fc7c96ab work on shared memory accross threads 2016-09-16 17:51:27 -06:00
Jeremy Soller 236b2f0e04 Panic upon use of unsupported flags 2016-09-16 13:45:00 -06:00
Jeremy Soller 356ba325ea Collapse status of context into one status variable 2016-09-16 11:10:53 -06:00
Jeremy Soller 0f27cd24ce Organize context module 2016-09-16 10:44:52 -06:00
Jeremy Soller 5cbd30988c Do not have interrupts enabled during context switch 2016-09-15 08:40:16 -06:00
Jeremy Soller dee5b4dd9e Remove debugging 2016-09-15 08:39:20 -06:00
Jeremy Soller 1711303ef8 Fix implementation of clone and exec. Now the init process can load and execute the pci driver 2016-09-15 08:35:07 -06:00
Jeremy Soller 8607367058 WIP: Create new page table for clone 2016-09-14 22:21:52 -06:00
Jeremy Soller 1acb84afbb Higher-half kernel mapping. Unmap where possible, freeing up lower memory 2016-09-14 20:47:55 -06:00
Jeremy Soller 932026fed8 WIP: Copy usermode stack 2016-09-13 21:27:27 -06:00
Jeremy Soller b042f40847 Fix userspace clone by clobbering all variables on clone 2016-09-13 20:31:45 -06:00
Jeremy Soller d3ace7dcad Allow cloning of kernel threads. Userspace breaks potentially due to stack aliasing 2016-09-13 20:06:39 -06:00
Jeremy Soller d1c0e3b5da Use flush_all instead of flush for performance 2016-09-13 11:20:55 -06:00
Jeremy Soller efaeb22163 Map kernel TLS to general area 2016-09-12 15:02:03 -06:00
Jeremy Soller d4ca131391 cr3 in context 2016-09-12 12:21:34 -06:00
Jeremy Soller 70bf79a977 Implement exit, partly 2016-09-11 22:03:03 -06:00
Jeremy Soller 0bb1ad38c9 Clear memory on demand 2016-09-11 21:47:44 -06:00
Jeremy Soller db3255dd82 Add comments 2016-09-11 21:35:02 -06:00
Jeremy Soller 011c8f7f2b Cleanup heap management 2016-09-11 21:18:18 -06:00
Jeremy Soller efd41a857e Store context memory information 2016-09-11 21:04:34 -06:00
Jeremy Soller 86597331cc Allow exec, emulate clone by pretending to be child 2016-09-11 18:03:10 -06:00
Jeremy Soller cf27b3a3ad Fix close, add dup 2016-09-11 17:31:21 -06:00
Jeremy Soller 7a928a5f97 Improve init process, debug missing syscalls, fix error codes in syscall return 2016-09-11 16:48:58 -06:00
Jeremy Soller 038cf5aba1 PCI driver WIP 2016-09-11 15:56:48 -06:00
Jeremy Soller 9371120f0f Flush TLB correctly when remapping
Seperate mouse and keyboard structs in PS/2 driver
2016-09-11 15:02:35 -06:00
Jeremy Soller 9b17495dd6 Implement exec
Implement brk
2016-09-10 22:06:09 -06:00
Jeremy Soller 4692e9b267 Load init from initfs 2016-09-10 19:42:26 -06:00
Jeremy Soller c30f4208d4 Implement sched_yield, enable interrupts in userspace 2016-09-10 19:18:59 -06:00
Jeremy Soller 486bfea62c Remove debugging messages, launch elf on APs 2016-09-10 19:03:31 -06:00
Jeremy Soller 0d115508be Seperate kernel and userspace targets 2016-09-09 19:08:04 -06:00
Jeremy Soller 531497d7af Remove debug warnings 2016-09-09 17:30:22 -06:00
Jeremy Soller 3837b2606f Connect schemes so that they can be used 2016-09-08 20:06:33 -06:00
Jeremy Soller 7036ed4c63 Cleanup to use question mark 2016-09-08 19:31:26 -06:00
Jeremy Soller ef9a7c0988 Add syscall library, make init program Rust 2016-09-08 19:10:50 -06:00
Jeremy Soller 44e57773a3 Debug reads writes better, set up stdio for BSP 2016-09-07 21:32:09 -06:00
Jeremy Soller 7c0b17d070 Load a very simple ELF and launch it in usermode 2016-09-07 21:16:30 -06:00
Jeremy Soller 4b98fb8ca3 Improve efficiency of kernel console 2016-09-01 14:39:45 -06:00
Jeremy Soller 5c91017579 Draw on VESA for console using ransid 2016-09-01 11:51:33 -06:00
Jeremy Soller ac9a475ef5 Warnings removal 2016-09-01 11:14:47 -06:00
Jeremy Soller 6269f68b03 Fill in all exception and IRQ entries. Handle PIT, keyboard IRQs 2016-08-31 17:45:21 -06:00
ticki b8f1971329 Merge branch 'master' of github.com:redox-os/kernel 2016-08-31 17:02:47 +02:00
ticki 4966842d72 Add the Fd definition file.
Damn, I forgot to `git add` it.
2016-08-31 17:01:08 +02:00
Jeremy Soller 8c0191564f Add file descriptor type 2016-08-30 16:27:10 -06:00
Jeremy Soller 2ccc13d212 Merge branch 'master' of https://github.com/redox-os/kernel 2016-08-30 16:23:56 -06:00
Jeremy Soller 9bddf55e93 Improvements for context switching 2016-08-30 16:23:51 -06:00
ticki 9ca3559cc8 Newtype file descriptors.
To avoid various bugs regarding the typing of file descriptors, we
newtype them into a simple wrapper type.

- Document some stuff.
2016-08-29 11:58:31 +02:00
Jeremy Soller f2d2b233f3 Simple, unsafe context switch 2016-08-28 18:38:53 -06:00
Jeremy Soller 5c2b6878a6 Arm! 2016-08-25 17:03:01 -06:00
Jeremy Soller 24bfb2c81f Fix the build. Sorry 2016-08-24 19:30:14 -06:00
Jeremy Soller 84873532af Arch context in kernel context 2016-08-24 10:35:42 -06:00
Jeremy Soller aecfa50029 Initialize contexts, add getpid 2016-08-20 14:32:45 -06:00
Jeremy Soller 47280a921a Context list class, static context ID magic 2016-08-20 13:43:35 -06:00
Jeremy Soller 645524fdf5 Setup independent page tables, map heap to a single location 2016-08-19 14:53:16 -06:00
Jeremy Soller 74b40f0a25 Switch to goblin as executable parser 2016-08-19 07:57:24 -06:00
Jeremy Soller b46c7e71c0 Add syscall handler, still work in progress
Add elf files
2016-08-18 19:44:31 -06:00
Jeremy Soller 954af453dc Remove clone from context 2016-08-18 09:02:31 -06:00
Jeremy Soller 8fc113adef Refactor context list 2016-08-18 08:30:45 -06:00
Jeremy Soller 0bd1cda1b6 Cleanup schemes list, remove lazy_static 2016-08-18 08:10:08 -06:00
Jeremy Soller b9e721d4e1 Print out more useful information about AP and BSP, create kmain_ap 2016-08-17 19:38:04 -06:00
Jeremy Soller 996996b0a9 Keep track of AP count, allocate bigger AP stack, stack trace function 2016-08-17 19:34:33 -06:00
Jeremy Soller 1993e701dd Remove warnings 2016-08-17 16:54:48 -06:00
Jeremy Soller 9f79abe542 Lazy static init of schemes 2016-08-16 11:04:14 -06:00
Jeremy Soller 26397084f6 Cleanup, use spinlock for allocator 2016-08-15 15:01:24 -06:00
Jeremy Soller e0daabde05 GDT and IDT in kernel space
Paging constructs completed, remap kernel before jumping to kmain
Panic will do a stack trace
Remove SSE from none target
2016-08-15 14:34:20 -06:00
Jeremy Soller 7da6696a34 Add simple paging, use rust libcore and compile without sse 2016-08-15 11:30:14 -06:00
Jeremy Soller 74ccbaa4a6 Bump allocator 2016-08-14 22:05:32 -06:00
Jeremy Soller 38f1a4fb76 WIP: Schemes 2016-08-14 21:38:32 -06:00
Jeremy Soller 946fd79e83 Test for BadFile 2016-08-14 19:17:55 -06:00
Jeremy Soller dd280a5d1a Add stdout/stderr tests 2016-08-14 18:22:50 -06:00
Jeremy Soller f79d6ce12b Add context and file structs 2016-08-14 18:16:56 -06:00
Jeremy Soller 04a6a45fac WIP: Exec 2016-08-14 16:07:41 -06:00
Jeremy Soller 6cfa38c5ba Add syscall module 2016-08-14 15:58:35 -06:00
Jeremy Soller 621de7fa8a Add test architecture 2016-08-14 14:59:18 -06:00
ticki 916a87fb33 Merge branch 'master' of github.com:redox-os/kernel 2016-08-14 20:55:19 +02:00
ticki 2b50588c29 Interrupt tables.
We add lookup table for interrupt descriptions containing information
about the CPU exceptions etc.
2016-08-14 20:54:23 +02:00
Jeremy Soller faa2b3ac63 Add comment 2016-08-14 12:11:53 -06:00
Jeremy Soller 4cb9df8fa8 Move arch to seperate crate 2016-08-14 11:45:47 -06:00
ticki fb99ec7e6d Strongly typed virtual/physical memory seperation.
This minicommit introduces two newtpyes, `Physical` and `Virtual`,
respectively. These serves as a way to segregate the different forms of
addresses to avoid the issues we had in the old kernel.
2016-08-14 19:21:21 +02:00
ticki b2fe1799fd Rename the src directory to kernel. 2016-08-14 18:42:32 +02:00
1780 changed files with 41555 additions and 105473 deletions
+5
View File
@@ -0,0 +1,5 @@
[build]
rustflags = [
# Kernel should preserve floating-point registers
"-Ctarget-feature=-sse,-sse2",
]
-7
View File
@@ -1,7 +0,0 @@
[**.c]
indent_size = 4
indent_style = space
[**.yml]
indent_size = 4
indent_style = space
+3 -11
View File
@@ -1,11 +1,3 @@
.idea/ target
prefix/ /config.toml
sysroot/ .gitlab-ci-local/
**/target/
.gdb_history
*.patch
*.swp
*.swo
/.vim
.vscode/
+54 -37
View File
@@ -5,69 +5,86 @@ variables:
workflow: workflow:
rules: rules:
- if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_NAMESPACE == "redox-os"' - if: '$CI_PROJECT_NAMESPACE == "redox-os"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
stages: stages:
- build - build
- cross-build - cross-build
- test - test
before_script: - other-features
cargo install cbindgen # TODO: benchmarks and profiling (maybe manually enabled for relevant MRs)?
fmt:
stage: build
needs: []
script:
- rustup component add rustfmt-preview
- ./fmt.sh -- --check
linux:
stage: build
script:
- ./check.sh --host
x86_64: x86_64:
stage: build stage: build
script: script:
- ./check.sh --arch=x86_64 - mkdir -p target/${ARCH}
- redoxer env make BUILD=target/${ARCH}
i586: variables:
stage: cross-build ARCH: "x86_64"
script:
- ./check.sh --arch=i586
aarch64: aarch64:
stage: cross-build stage: cross-build
image: "redoxos/redoxer:aarch64" image: "redoxos/redoxer:aarch64"
script: script:
- ./check.sh --arch=aarch64 - mkdir -p target/${ARCH}
- redoxer env make BUILD=target/${ARCH}
variables:
ARCH: "aarch64"
i586:
stage: cross-build
script:
- mkdir -p target/${ARCH}
- TARGET=${ARCH}-unknown-redox redoxer env make BUILD=target/${ARCH}
variables:
ARCH: "i586"
riscv64gc: riscv64gc:
stage: cross-build stage: cross-build
script: script:
- ./check.sh --arch=riscv64gc - mkdir -p target/${ARCH}
- TARGET=${ARCH}-unknown-redox redoxer env make BUILD=target/${ARCH}
variables:
ARCH: "riscv64gc"
test:linux: fmt:
stage: test stage: build
needs: [linux]
script: script:
- ./check.sh --host --test - rustup component add rustfmt
- rustfmt --check
test:x86_64: x86_64:boot:
stage: test stage: test
needs: [x86_64] needs: [x86_64]
script: script:
# timeout: https://gitlab.redox-os.org/redox-os/relibc/-/issues/238 - mkdir -p target/${ARCH}
- timeout -s KILL 9m ./check.sh --arch=x86_64 --test - export COOKBOOK_SOURCE_IDENT=$CI_COMMIT_SHA
- redoxer env make BUILD=target/${ARCH}
- timeout -s KILL 9m redoxer exec --folder target/${ARCH}/:/usr/lib/boot uname -a
variables:
ARCH: "x86_64"
test:aarch64: x86_64:relibc:
stage: test stage: test
needs: [aarch64] needs: [x86_64]
image: "redoxos/redoxer:aarch64" script:
# many issues that not exist in x86_64, and lack of interest to fix so far - redoxer pkg relibc-tests-bins
- export COOKBOOK_SOURCE_IDENT=$CI_COMMIT_SHA
- mkdir -p target/${TARGET}/sysroot/{usr/lib/boot,root} target/${TARGET}/root
- redoxer env make BUILD=target/${TARGET}/sysroot/usr/lib/boot
- (cd target/${TARGET}/sysroot && mv home/user/relibc-tests/* root/)
- timeout -s KILL 9m redoxer exec --folder target/${TARGET}/sysroot/:/ make run
# It is fine if failing sometimes
allow_failure: true
variables:
TARGET: "x86_64-unknown-redox"
profiling-compile:
stage: other-features
allow_failure: true allow_failure: true
script: script:
- timeout -s KILL 9m ./check.sh --arch=aarch64 --test make check
variables:
#TODO: Enable more arch once dynamic linker working ARCH: "x86_64"
KERNEL_CHECK_FEATURES: profiling
+4 -7
View File
@@ -1,7 +1,4 @@
[submodule "openlibm"] [submodule "redox-path"]
path = openlibm path = redox-path
url = https://gitlab.redox-os.org/redox-os/openlibm.git url = https://gitlab.redox-os.org/redox-os/redox-path.git
branch = master branch = main
[submodule "src/dlmalloc-rs"]
path = dlmalloc-rs
url = https://gitlab.redox-os.org/redox-os/dlmalloc-rs.git
+2
View File
@@ -0,0 +1,2 @@
[editor]
auto-format = false
+13
View File
@@ -0,0 +1,13 @@
[[language]]
name = "rust"
[[language-server.rust-analyzer.config.cargo]]
extraEnv = ["RUST_TARGET_PATH=targets"]
# Select one of targets to make lsp work for your confguration
# Do not commit this change
# TODO: find a better way to do this
# target = "aarch64-unknown-kernel"
[[language-server.rust-analyzer.config.check]]
targets = ["x86_64-unknown-kernel", "i686-unknown-kernel", "aarch64-unknown-kernel"]
+79
View File
@@ -0,0 +1,79 @@
# Porting the core Redox kernel to arm AArch64: An outline
## Intro
This document is [my](https://github.com/raw-bin) attempt at:
* Capturing thinking on the work needed for a core Redox kernel port
* Sharing progress with the community as things evolve
* Creating a template that can be used for ports to other architectures
Core Redox kernel means everything needed to get to a non-graphical console-only multi-user shell.
Only the 64-bit execution state (AArch64) with the 64-bit instruction set architecture (A64) shall be supported for the moment. For more background/context read [this](https://developer.arm.com/products/architecture/a-profile/docs/den0024/latest/introduction).
This document is intended to be kept *live*. It will be updated to reflect the current state of work and any feedback received.
It is hard~futile to come up with a strict sequence of work for such ports but this document is a reasonable template to follow.
## Intended target platform
The primary focus is on [qemu's virt machine platform emulation for the AArch64 architecture](https://github.com/qemu/qemu/blob/master/hw/arm/virt.c#L127).
Targeting a virtual platform is a convenient way to bring up the mechanics of architectural support and makes the jump to silicon easier. The preferred boot chain for AArch64 (explained later) is well supported on this platform and boot-over-tftp from localhost makes the debug cycle very efficient.
Once the core kernel port is complete a similar follow on document will be created that is dedicated to silicon bring-up.
## Boot protocol elements
| Item | Notes |
|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Linux kernel boot protocol for AArch64](https://www.kernel.org/doc/Documentation/arm64/booting.txt) | The linked document describes assumptions made from the bootloader which are field tested and worthwhile to have for Redox an AArch64. <br/> The intent is to consider most of the document except anything tied to the Linux kernel itself. |
| [Flattened Device Tree](https://elinux.org/Device_Tree_Reference) | FDT binary blobs supplied by the bootloader shall provide the Redox kernel with misc platform \{memory, interrupt, devicemem} maps. Qemu's virt machine platform synthetically creates an FDT blob at a specific address which is very handy. |
## Boot flow elements
The following table lists the boot flow in order.
| Item | Notes |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ARM Trusted Firmware (TF-A)](https://github.com/ARM-software/arm-trusted-firmware) | TF-A is a de-facto standard reference firmware implementation and proven in the field. <br/> TF-A runs post power-on on Armv8-A implementations and eventually hands off to further stages of the boot flow.<br />For qemu's virt machine platform, it is essentially absent but I mean to rely on it heavily for silicon bring up hence mentioning it here. |
| [u-boot](https://www.denx.de/wiki/U-Boot) | u-boot will handle early console access, media access for fetching redox kernel images from non-volatile storage/misc disk subsystems/off the network. <br /> u-boot supports loading EFI applications. If EFI support to AArch64 Redox is added in the future that should essentially work out of the box. <br /> u-boot will load redox and FDT binary blobs into RAM and jump to the redox kernel. |
| Redox early-init stub | For AArch64, the redox kernel will contain an A64 assembly stub that will setup the MMU from scratch. This is akin to the [x86_64 redox bootloader](https://github.com/redox-os/bootloader/blob/master/x86_64/startup-x86_64.asm). <br /> This stub sets up identity maps for MMU initialization, maps the kernel image itself as well as the device memory for the UART console. At present this stub shall be a part of the kernel itself for simplicity. |
| Redox kstart entry | The early init stub hands off here. kstart will then re-init the MMU more comprehensively. |
## Supported devices
The following devices shall be supported. All necessary information specific to these devices will be provided to the redox kernel by the platform specific FDT binary blob.
| Device | Notes |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Generic Interrupt Controller v2](https://developer.arm.com/products/architecture/a-profile/docs/ihi0048/b/arm-generic-interrupt-controller-architecture-version-20-architecture-specification) | The GIC is an Arm-v8A architectural element and is supported by all architecturally compliant processor implementations. GICv2 is supported by qemu's virt machine emulation and most subsequent GIC implementations are backward compatible to GICv2. |
| [Generic Timer](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0500d/BGBBIJCB.html) | The Generic Timer Architecture is an Arm-v8A architectural element and is implemented by all compliant processor implementations. It is supported by qemu. |
| [PrimeCell UART PL011](http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf) | The PL011 UART is supported by qemu and most ARM systems. |
## Intended development sequence and status
| Item | Description | Status | Notes |
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|-------------------------------------------------------------------------------|
| Redox AArch64 toolchain | Create an usable redox AArch64 toolchain specification | Done | Using this JSON spec in isolated tests produces valid AArch64 soft float code |
| Stubbed kernel image | Stub out AArch64 kernel support using the existing x86_64 arch code as a template <br /> Modify redox kernel build glue and work iteratively to get a linkable (non-functional) image | Not done yet | |
| Boot flow | Create a self hosted u-boot -> redox kernel workflow <br /> Should obtain the stubbed image from a local TFTP server, load it into RAM and jump to it | Not done yet | |
| GDB Debug flow | Create a debug workflow centered around qemu's GDB stub <br /> This should allow connecting to qemu's GDB stub and debug u-boot/redox stub via a GDB client and single stepping through code | Not done yet | |
| Verify Redox entry | Verify that control reaches the redox kernel from u-boot | Not done yet | |
| AArch64 early init stub | Add support for raw asm code for early AArch64 init in the redox kernel <br /> Verify that this code is located appropriately in the link map and that control reaches this code from u-boot | Not done yet | |
| Basic DTB support | Integrate the [device_tree crate](https://mbr.github.io/device_tree-rs/device_tree/) <br /> Use the crate to access the qemu supplied DTB image and extract the memory map | Not done yet | |
| Basic UART support | Use the device_tree crate to get the UART address from the DTB image and set up the initial console <br /> This is a polling mode only setup | Not done yet | |
| Initial MMU support | Implement initial MMU support in the early init stub <br /> This forces the MMU into a clean state overriding any bootloader specific setup <br /> Create an identity map for MMU init <br /> Create a mapping for the kernel image <br /> Create a mapping for any devices needed at this stage (UART) | Not done yet | |
| kmain entry | Verify that kmain entry works post early MMU init | Not done yet | |
| Basic Redox MMU support | Get Redox to create a final set of mappings for everything <br /> Verify that this works as expected | Not done yet | |
| Basic libc support | Flesh out a basic set of libc calls as required for simple user-land apps | Not done yet | |
| userspace_init entry | Verify user-space entry and /sbin/init invocation | Not done yet | |
| Basic Interrupt controller support | Add a GIC driver <br /> Verify functionality | Not done yet | |
| Basic Timer support | Add a Generic Timer driver <br /> Verify functionality | Not done yet | |
| UART interrupt support | Add support for UART interrupts | Not done yet | |
| Task context switch support | Add context switching support <br /> Verify functionality | Not done yet | |
| Login shell | Iteratively add and verify multi-user login shell support | Not done yet | |
| Publish development branch on github | Work with the community to post work done after employer approval | Not done yet | |
| Break out the Bubbly | Drink copious quantities of alcohol to celebrate | Not done yet | |
| Silicon bring-up | Plan silicon bring-up | Not done yet | |
-123
View File
@@ -1,123 +0,0 @@
# Contributing
## Table of contents
1. [What to do](#what-to-do)
2. [Code style](#code-style)
3. [Sending merge requests](#sending-merge-requests)
4. [Writing tests](#writing-tests)
5. [Running tests](#running-tests)
Maintaining a libc is tough work, and we'd love some help!
## What to do
For now, we are still trying to get full libc compatibility before we move on to
any optimisation.
- We currently have a number of unimplemented functions. Search for
`unimplemented!()` and hop right in!
- If you notice any missing functionality, feel free to add it in
## Code style
We have a `rustfmt.toml` in the root directory of relibc. Please run `./fmt.sh`
before sending in any merge requests as it will automatically format your code.
With regards to general style:
### Where applicable, prefer using references to raw pointers
This is most obvious when looking at `stdio` functions. If raw pointers were
used instead of references, then the resulting code would be significantly
uglier. Instead try to check for pointer being valid with `pointer::as_ref()`
and `pointer::as_mut()` and then immediately use those references instead.
Internal functions should always take references.
### Use the c types exposed in our platform module instead of Rust's inbuilt integer types
This is so we can guarantee that everything works across platforms. While it is
generally accepted these days that an `int` has 32 bits (which matches against
an `i32`), some platforms have `int` as having 16 bits, and others have long as
being 32 bits instead of 64. If you use the types in platform, then we can
guarantee that your code will "just work" should we port relibc to a different
architecture.
### Use our internal functions
If you need to use a C string, don't reinvent the wheel. We have functions in
the platform module that convert C strings to Rust slices.
We also have structures that wrap files, wrap writable strings, and wrap various
other commonly used things that you should use instead of rolling your own.
## Sending merge requests
If you have sent us a merge request, first of all, thanks for taking your time
to help us!
The first thing to note is that we do most of our development on our
[GitLab server](https://gitlab.redox-os.org/redox-os/relibc), and as such it is
possible that none of the maintainers will see your merge request if it is
opened on GitHub.
In your merge request, please put in the description:
- What functions (if any) have been implemented or changed
- The rationale behind your merge request (e.g. why you thought this change was
required. If you are just implementing some functions, you can ignore this)
- Any issues that are related to the merge request
We have CI attached to our GitLab instance, so all merge requests are checked to
make sure that they are tested before they are merged. Please write tests for
the functions that you add/change and test locally on your own machine
***before*** submitting a merge request.
## Writing tests
Every function that gets written needs to have a test in C in order to make sure
it works as intended. Here are a few guidelines for writing good tests.
### Ensure that any literals you have are mapped to variables instead of being directly passed to a function.
Sometimes compilers take literals put into libc functions and run them
internally during compilation, which can cause some false positives. All tests
are compiled with `-fno-builtin`, which theoretically solves this issue, but
just in case, it'd be a good idea to map inputs to variables.
```c
#include "string.h"
#include "stdio.h"
int main(void) {
// Don't do this
printf("%d\n", strcspn("Hello", "Hi"));
// Do this
char *first = "Hello";
char *second = "Hi";
printf("%d\n", strcspn(first, second));
}
```
### Ensure your tests cover every section of code.
What happens if a string in `strcmp()` is shorter than the other string? What
happens if the first argument to `strcspn()` is longer than the second string?
In order to make sure that all functions work as expected, we ask that any tests
cover as much of the code that you have written as possible.
## Running tests
Running tests is an important part in trying to find bugs. Before opening a
merge request, we ask that you test on your own machine to make sure there are
no regressions.
You can run tests with `make test` in the root directory of relibc to compile
relibc, compile the tests and run them. This *will* print a lot of output to
stdout, so be warned!
You can test against verified correct output with `make verify` in the tests
directory. You will need to manually create the correct output and put it in the
tests/expected directory. Running any `make` commands in the tests directory
will ***not*** rebuild relibc, so you'll need to go back to the root directory
if you need to rebuild relibc.
Generated
+213 -519
View File
@@ -3,39 +3,40 @@
version = 4 version = 4
[[package]] [[package]]
name = "argon2" name = "ahash"
version = "0.5.3" version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
dependencies = [ dependencies = [
"base64ct", "cfg-if",
"blake2", "once_cell",
"cpufeatures", "version_check",
"password-hash", "zerocopy",
] ]
[[package]] [[package]]
name = "autocfg" name = "arrayvec"
version = "1.5.1" version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]] [[package]]
name = "base64ct" name = "bit_field"
version = "1.8.3" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6"
[[package]] [[package]]
name = "bcrypt-pbkdf" name = "bitfield"
version = "0.10.0" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aeac2e1fe888769f34f05ac343bbef98b14d1ffb292ab69d4608b3abc86f2a2" checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
dependencies = [
"blowfish", [[package]]
"pbkdf2", name = "bitflags"
"sha2", version = "1.3.2"
] source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
@@ -43,54 +44,13 @@ version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "blowfish"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7"
dependencies = [
"byteorder",
"cipher",
]
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29b6ad25ae296159fb0da12b970b2fe179b234584d7cd294c891e2bbb284466b"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.22" version = "1.2.66"
source = "git+https://github.com/tea/cc-rs?branch=riscv-abi-arch-fix#588ceacb084af41415690c57688e338a32a1f1b4" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d6cac793997bd970000024b2934968efe83b382de4fdcf4fcb46b6ee4ad996"
dependencies = [ dependencies = [
"find-msvc-tools",
"shlex", "shlex",
] ]
@@ -101,174 +61,81 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]] [[package]]
name = "chrono" name = "equivalent"
version = "0.4.45" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "fdt"
version = "0.2.0-alpha1"
source = "git+https://github.com/repnop/fdt.git?rev=2fb1409edd1877c714a0aa36b6a7c5351004be54#2fb1409edd1877c714a0aa36b6a7c5351004be54"
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [ dependencies = [
"num-traits", "ahash",
] ]
[[package]] [[package]]
name = "chrono-tz" name = "hashbrown"
version = "0.10.4" version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "indexmap"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [ dependencies = [
"chrono", "equivalent",
"phf", "hashbrown 0.17.1",
] ]
[[package]] [[package]]
name = "cipher" name = "kernel"
version = "0.4.4" version = "0.5.12+rb0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [ dependencies = [
"crypto-common", "arrayvec",
"inout", "bitfield",
"bitflags 2.13.0",
"cc",
"fdt",
"hashbrown 0.14.5",
"linked_list_allocator",
"object",
"raw-cpuid",
"redox-path",
"redox_syscall",
"rmm",
"rustc-demangle",
"sbi-rt",
"slab",
"smallvec",
"spin",
"toml",
"x86",
] ]
[[package]] [[package]]
name = "cpufeatures" name = "linked_list_allocator"
version = "0.2.17" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" checksum = "549ce1740e46b291953c4340adcd74c59bcf4308f4cac050fd33ba91b7168f4a"
dependencies = [ dependencies = [
"libc", "spinning_top",
] ]
[[package]]
name = "crt0"
version = "0.1.0"
[[package]]
name = "crti"
version = "0.1.0"
[[package]]
name = "crtn"
version = "0.1.0"
[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
name = "dlmalloc"
version = "0.2.8"
dependencies = [
"cfg-if",
"windows-sys",
]
[[package]]
name = "drm-sys"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc8e1361066d91f5ffccff060a3c3be9c3ecde15be2959c1937595f7a82a9f8"
dependencies = [
"libc",
"linux-raw-sys",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "generic-rt"
version = "0.1.0"
[[package]]
name = "goblin"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17582616a7718cca54cec18e534a76c7c4aec11a8b9a85695712f262fd15a4c8"
dependencies = [
"log",
"plain",
"scroll",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "inout"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
"generic-array",
]
[[package]]
name = "ioslice"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e571352c8a3b89074d12e3ee5173ffe162159105352aaaf1fc5764da747e31b"
[[package]]
name = "ld_so"
version = "0.1.0"
[[package]]
name = "libc"
version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "libm"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "libredox"
version = "0.1.18+rb0.3.0"
dependencies = [
"bitflags",
"libc",
"plain",
]
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.14" version = "0.4.14"
@@ -278,96 +145,26 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "log"
version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
[[package]]
name = "md-5"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
dependencies = [
"cfg-if",
"digest",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.8.2" version = "2.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.7" version = "0.37.3"
source = "git+https://gitlab.redox-os.org/andypython/object#7270e3f0d06e5ef4c2b80abc6166d31f4ddf4fea" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
[[package]] [[package]]
name = "password-hash" name = "once_cell"
version = "0.5.0" version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
dependencies = [
"base64ct",
"rand_core 0.6.4",
"subtle",
]
[[package]]
name = "pbkdf2"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
dependencies = [
"digest",
"hmac",
"sha2",
]
[[package]]
name = "phf"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_shared"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981"
dependencies = [
"siphasher",
]
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]]
name = "posix-regex"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66df580334caab2f744839ab1be85493d7ec731a92d6cf928008ab0b212bf3bc"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
@@ -388,147 +185,54 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rand" name = "raw-cpuid"
version = "0.10.2" version = "10.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332"
dependencies = [ dependencies = [
"rand_core 0.10.1", "bitflags 1.3.2",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_jitter"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdcd80e68f0a8f9ca5ec7cfd02fd5fbb8fbe6ef4e9b90ea2f48bb929b74f88e"
dependencies = [
"libc",
"rand_core 0.10.1",
"windows-sys",
]
[[package]]
name = "rand_xorshift"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf"
dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "redox-ioctl"
version = "0.1.0"
dependencies = [
"drm-sys",
"redox_syscall",
] ]
[[package]] [[package]]
name = "redox-path" name = "redox-path"
version = "0.3.1" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717" checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7"
[[package]]
name = "redox-rt"
version = "0.1.0"
dependencies = [
"bitflags",
"generic-rt",
"goblin",
"ioslice",
"libredox",
"plain",
"redox-path",
"redox_syscall",
]
[[package]]
name = "redox_event"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5018d583d6d2f5499352aea8d177e9067d1eb03ab17c78169d5ba7a30001b15"
dependencies = [
"bitflags",
"libredox",
"redox_syscall",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.9.0+rb0.3.0" version = "0.9.0+rb0.3.0"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.13.0",
] ]
[[package]] [[package]]
name = "relibc" name = "rmm"
version = "0.6.0+rb0.3.0" version = "0.1.0"
dependencies = [ dependencies = [
"argon2", "bitflags 2.13.0",
"base64ct",
"bcrypt-pbkdf",
"bitflags",
"cbitset",
"cc",
"chrono",
"chrono-tz",
"dlmalloc",
"generic-rt",
"ioslice",
"libc",
"libm",
"libredox",
"log",
"md-5",
"memchr",
"object",
"pbkdf2",
"plain",
"posix-regex",
"rand",
"rand_jitter",
"rand_xorshift",
"redox-ioctl",
"redox-path",
"redox-rt",
"redox_event",
"redox_syscall",
"sc",
"scrypt",
"sha-crypt",
"sha2",
"spin",
"unicode-width",
] ]
[[package]] [[package]]
name = "salsa20" name = "rustc-demangle"
version = "0.10.2" version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
[[package]]
name = "sbi-rt"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fbaa69be1eedc61c426e6d489b2260482e928b465360576900d52d496a58bd0"
dependencies = [ dependencies = [
"cipher", "sbi-spec",
] ]
[[package]] [[package]]
name = "sc" name = "sbi-spec"
version = "0.2.7" version = "0.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" checksum = "e6e36312fb5ddc10d08ecdc65187402baba4ac34585cb9d1b78522ae2358d890"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
@@ -537,19 +241,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "scroll" name = "serde"
version = "0.13.0" version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [ dependencies = [
"scroll_derive", "serde_core",
] ]
[[package]] [[package]]
name = "scroll_derive" name = "serde_core"
version = "0.13.1" version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed76efe62313ab6610570951494bdaa81568026e0318eaa55f167de70eeea67d" checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -557,49 +270,31 @@ dependencies = [
] ]
[[package]] [[package]]
name = "scrypt" name = "serde_spanned"
version = "0.11.0" version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
dependencies = [ dependencies = [
"password-hash", "serde",
"pbkdf2",
"salsa20",
"sha2",
]
[[package]]
name = "sha-crypt"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88e79009728d8311d42d754f2f319a975f9e38f156fd5e422d2451486c78b286"
dependencies = [
"base64ct",
"sha2",
]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
] ]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]] [[package]]
name = "siphasher" name = "slab"
version = "1.0.3" version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "smallvec"
version = "1.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
[[package]] [[package]]
name = "spin" name = "spin"
@@ -611,10 +306,13 @@ dependencies = [
] ]
[[package]] [[package]]
name = "subtle" name = "spinning_top"
version = "2.6.1" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
dependencies = [
"lock_api",
]
[[package]] [[package]]
name = "syn" name = "syn"
@@ -628,10 +326,45 @@ dependencies = [
] ]
[[package]] [[package]]
name = "typenum" name = "toml"
version = "1.20.1" version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"toml_write",
"winnow",
]
[[package]]
name = "toml_write"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
@@ -639,12 +372,6 @@ version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.5" version = "0.9.5"
@@ -652,78 +379,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]] [[package]]
name = "windows-sys" name = "winnow"
version = "0.59.0" version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
dependencies = [ dependencies = [
"windows-targets", "memchr",
] ]
[[package]] [[package]]
name = "windows-targets" name = "x86"
version = "0.52.6" version = "0.47.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" checksum = "55b5be8cc34d017d8aabec95bc45a43d0f20e8b2a31a453cabc804fe996f8dca"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "bit_field",
"windows_aarch64_msvc", "bitflags 1.3.2",
"windows_i686_gnu", "raw-cpuid",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
] ]
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "zerocopy"
version = "0.52.6" version = "0.8.53"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" checksum = "75726053136156d419e285b9b7eddaaea9e3fea6ce32eed44a89901f0bd98de1"
dependencies = [
"zerocopy-derive",
]
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "zerocopy-derive"
version = "0.52.6" version = "0.8.53"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" checksum = "4714fd92cf900833d49538023a9b3915155210801d1c1169eba513b2addefd71"
dependencies = [
[[package]] "proc-macro2",
name = "windows_i686_gnu" "quote",
version = "0.52.6" "syn",
source = "registry+https://github.com/rust-lang/crates.io-index" ]
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[patch.unused]] [[patch.unused]]
name = "redox-scheme" name = "libredox"
version = "0.11.2+rb0.3.0" version = "0.1.18+rb0.3.0"
+114 -128
View File
@@ -1,151 +1,137 @@
[workspace]
resolver = "3"
members = [".", "rmm"]
[package] [package]
name = "relibc" name = "kernel"
version = "0.6.0+rb0.3.0" version = "0.5.12+rb0.3.0"
authors = ["Jeremy Soller <jackpot51@gmail.com>", "vasilito <adminpupkin@gmail.com>"] authors = ["Jeremy Soller <jackpot51@gmail.com>", "vasilito <adminpupkin@gmail.com>"]
build = "build.rs"
edition = "2024" edition = "2024"
[lib]
name = "relibc"
crate-type = ["staticlib"]
[workspace]
members = [
"src/crt0",
"src/crti",
"src/crtn",
"redox-rt",
"ld_so",
"generic-rt",
]
exclude = ["tests", "dlmalloc-rs"]
[workspace.lints.clippy]
borrow_as_ptr = "deny"
cast_lossless = "warn" # TODO review occurrences
cast_possible_truncation = "allow" # TODO review occurrences
cast_possible_wrap = "allow" # TODO review occurrences
cast_precision_loss = "allow" # TODO review occurrences
cast_ptr_alignment = "allow" # TODO review occurrences
cast_sign_loss = "allow" # TODO review occurrences
missing_errors_doc = "allow" # TODO review occurrences
missing_panics_doc = "allow" # TODO review occurrences
missing_safety_doc = "allow" # TODO review occurrences
mut_from_ref = "warn" # TODO review occurrences
precedence = "deny"
ptr_as_ptr = "warn" # TODO review occurrences
ptr_cast_constness = "warn" # TODO review occurrences
ref_as_ptr = "warn" # TODO review occurrences
upper_case_acronyms = "allow" # TODO review occurrences
zero_ptr = "warn" # must allow on public constants due to cbindgen issue
[workspace.lints.rust]
dangling_pointers_from_temporaries = "deny"
dead_code = "allow" # TODO review occuurences
deprecated = "deny"
improper_ctypes_definitions = "deny"
internal_features = "allow" # core_intrinsics and lang_items
irrefutable_let_patterns = "deny"
mismatched_lifetime_syntaxes = "deny"
non_camel_case_types = "allow" # needed for most POSIX type names
non_snake_case = "allow" # TODO review occuurences
non_upper_case_globals = "allow" # TODO review occuurences
unexpected_cfgs = "deny"
unpredictable_function_pointer_comparisons = "deny"
unreachable_code = "allow" # TODO review occuurences
unsafe_op_in_unsafe_fn = "deny"
unused_imports = "deny"
unused_must_use = "deny"
unused_mut = "deny"
unused_unsafe = "deny"
unused_variables = "allow" # TODO review occurrences (too many for now)
[lints]
workspace = true
[workspace.dependencies]
bitflags = "2"
ioslice = { version = "0.6", default-features = false }
plain = "0.2"
redox-path = "0.3"
redox_protocols = { package = "libredox", path = "../libredox", default-features = false, features = ["protocol"] }
redox_syscall = { path = "../syscall" }
[build-dependencies] [build-dependencies]
cc = "1" cc = "1.0"
toml = "0.8"
[dependencies] [dependencies]
bitflags.workspace = true arrayvec = { version = "0.7.4", default-features = false }
cbitset = "0.2" bitfield = "0.13.2"
posix-regex = { version = "0.1.4", features = ["no_std"] } bitflags = "2"
fdt = { git = "https://github.com/repnop/fdt.git", rev = "2fb1409edd1877c714a0aa36b6a7c5351004be54" }
rand = { version = "0.10", default-features = false } hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "inline-more"] }
rand_xorshift = "0.5" linked_list_allocator = "0.9.0"
rand_jitter = "0.6" redox-path = "0.2.0"
redox_syscall = { path = "../syscall", default-features = false }
memchr = { version = "2.2.0", default-features = false } rmm = { path = "rmm", default-features = false }
plain.workspace = true slab = { version = "0.4", default-features = false }
unicode-width = "0.1" smallvec = { version = "1.15.1", default-features = false }
__libc_only_for_layout_checks = { package = "libc", version = "0.2.149", optional = true } spin = { version = "0.9.8" }
md5-crypto = { package = "md-5", version = "0.10.6", default-features = false }
sha-crypt = { version = "0.5", default-features = false }
base64ct = { version = "1.6", default-features = false, features = ["alloc"] }
bcrypt-pbkdf = { version = "0.10", default-features = false, features = [
"alloc",
] }
scrypt = { version = "0.11", default-features = false, features = ["simple"] }
pbkdf2 = { version = "0.12", features = ["sha2"] }
sha2 = { version = "0.10", default-features = false }
generic-rt = { path = "generic-rt" }
chrono-tz = { version = "0.10", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["alloc"] }
libm = "0.2"
log = "0.4"
spin = "0.9.8"
argon2 = "0.5.3"
[dependencies.dlmalloc]
path = "dlmalloc-rs"
default-features = false
features = ["c_api"]
[dependencies.object] [dependencies.object]
version = "0.36.7" version = "0.37.1"
git = "https://gitlab.redox-os.org/andypython/object"
default-features = false default-features = false
features = ["elf", "read_core"] features = ["read_core", "elf"]
[target.'cfg(target_os = "linux")'.dependencies] [dependencies.rustc-demangle]
sc = "0.2.7" version = "0.1.16"
default-features = false
[target.'cfg(target_os = "redox")'.dependencies] [lints.clippy]
redox_syscall.workspace = true # Overflows are very, very bad in kernel code as it may provide an attack vector for
redox-rt = { path = "redox-rt" } # userspace applications, and it is only checked in debug builds
redox-path.workspace = true # TODO: address occurrences and then deny
redox_event = { version = "0.4.8", default-features = false, features = [ arithmetic_side_effects = "warn"
"redox_syscall", cast_ptr_alignment = "warn" # TODO: address occurrences and then deny
] } identity_op = "allow" # Used to allow stuff like 1 << 0 and 1 * 1024 * 1024
ioslice.workspace = true if_same_then_else = "allow" # Useful for adding comments about different branches
redox-ioctl = { path = "redox-ioctl" } # Indexing a slice can cause panics and that is something we always want to avoid
redox_protocols.workspace = true # in kernel code. Use .get and return an error instead
# TODO: address occurrences and then deny
indexing_slicing = "warn"
many_single_char_names = "allow" # Useful in the syscall function
module_inception = "allow" # Used for context::context
# Not implementing default is sometimes useful in the case something has significant cost
# to allocate. If you implement default, it can be allocated without evidence using the
# ..Default::default() syntax. Not fun in kernel space
new_without_default = "allow"
not_unsafe_ptr_arg_deref = "deny"
or_fun_call = "allow" # Used to make it nicer to return errors, for example, .ok_or(Error::new(ESRCH))
precedence = "deny"
ptr_cast_constness = "deny"
too_many_arguments = "allow" # This is needed in some cases, like for syscall
# Avoid panicking in the kernel without information about the panic. Use expect
# TODO: address occurrences and then deny
unwrap_used = "warn"
[lints.rust]
static_mut_refs = "warn" # FIXME deny once all occurrences are fixed
# This is usually a serious issue - a missing import of a define where it is interpreted
# as a catch-all variable in a match, for example
unreachable_patterns = "deny"
unused_must_use = "deny" # Ensure that all must_use results are used
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
raw-cpuid = "10.2.0"
x86 = { version = "0.47.0", default-features = false }
[target.'cfg(any(target_arch = "riscv64", target_arch = "riscv32"))'.dependencies]
sbi-rt = "0.0.3"
[features] [features]
# to enable trace level, take out this `no_trace` default = [
default = ["check_against_libc_crate", "ld_so_cache", "no_trace"] "acpi",
check_against_libc_crate = ["__libc_only_for_layout_checks"] #"debugger",
ld_so_cache = [] "multi_core",
math_libm = [] "serial_debug",
no_trace = ["log/release_max_level_debug"] "self_modifying",
# for very verbose activity beyond trace level "x86_kvm_pv",
trace_tls = [] #"busy_panic",
#"drop_panic",
#"syscall_debug"
]
# Activates some limited code-overwriting optimizations, based on CPU features.
self_modifying = []
acpi = []
lpss_debug = []
multi_core = ["acpi"]
profiling = []
#TODO: remove when threading issues are fixed
pti = []
drop_panic = []
busy_panic = []
qemu_debug = []
serial_debug = []
system76_ec_debug = []
x86_kvm_pv = []
debugger = ["syscall_debug"]
syscall_debug = []
sys_fdstat = []
[profile.dev] [profile.dev]
# Avoids having to define the eh_personality lang item and reduces kernel size
panic = "abort" panic = "abort"
[profile.release] [profile.release]
# Avoids having to define the eh_personality lang item and reduces kernel size
panic = "abort" panic = "abort"
#lto = true
debug = "full"
# Red Bear OS Phase J: see local/sources/base/Cargo.toml for
# the rationale. Both the kernel and the base workspace need
# the libredox override so that the libredox::error::Error
# type is the same compile-time type as syscall::Error. With
# the local libredox fork at local/sources/libredox/ using
# the local syscall fork at local/sources/syscall/, the
# libredox::error::Error (re-exported from the local syscall)
# and syscall::Error (also the local syscall) are now the
# same type, so `?` conversions in scheme-utils / daemon
# compile cleanly.
[patch.crates-io] [patch.crates-io]
cc-11 = { git = "https://github.com/tea/cc-rs", branch = "riscv-abi-arch-fix", package = "cc" } # Local fork dependency rule: every crate with a local fork MUST resolve through it.
redox_syscall = { path = "../syscall" }
libredox = { path = "../libredox" } libredox = { path = "../libredox" }
redox-scheme = { path = "../redox-scheme" } redox_syscall = { path = "../syscall" }
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2018 Redox OS Copyright (c) 2017 Jeremy Soller
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+58 -218
View File
@@ -1,226 +1,66 @@
include config.mk .PHONY: all check
CARGO?=cargo SOURCE:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
CARGO_TEST?=$(CARGO) BUILD?=$(CURDIR)
CARGO_COMMON_FLAGS=-Z build-std=core,alloc,compiler_builtins export RUST_TARGET_PATH=$(SOURCE)/targets
CARGOFLAGS?=$(CARGO_COMMON_FLAGS)
CC_WRAPPER?=
RUSTCFLAGS?=
LINKFLAGS?=-lgcc
USE_RUST_LIBM?=
TESTBIN?=
export OBJCOPY?=objcopy
export CARGO_TARGET_DIR?=$(shell pwd)/target ifeq ($(TARGET),)
BUILD?=$(CARGO_TARGET_DIR)/$(TARGET) ARCH?=$(shell uname -m)
CARGOFLAGS+=--target=$(TARGET) else
EXCEPT_MATH=-not -name "math" ARCH?=$(shell echo "$(TARGET)" | cut -d - -f1)
FEATURE_MATH=
ifneq ($(USE_RUST_LIBM),)
FEATURE_MATH=--features math_libm
EXCEPT_MATH=
endif endif
TARGET_HEADERS?=$(BUILD)/include ifeq ($(ARCH),riscv64gc)
export CFLAGS=-I$(TARGET_HEADERS) override ARCH:=riscv64
GNU_TARGET=riscv64-unknown-redox
PROFILE?=release else ifeq ($(ARCH),i686)
override ARCH:=i586
HEADERS_UNPARSED=$(shell find src/header -mindepth 1 -maxdepth 1 -type d -not -name "_*" $(EXCEPT_MATH) -printf "%f\n") GNU_TARGET=i686-unknown-redox
HEADERS_DEPS=$(shell find src/header -type f \( -name "cbindgen.toml" -o -name "*.rs" \)) else
#HEADERS=$(patsubst %,%.h,$(subst _,/,$(HEADERS_UNPARSED))) GNU_TARGET=$(ARCH)-unknown-redox
SRC=\
Cargo.* \
$(shell find src/ redox-rt/src/ ld_so/src/ redox-ioctl/src/ include/ -type f)
BUILTINS_VERSION=0.1.70
.PHONY: all clean fmt install install-libs install-headers install-tests libs headers submodules test
all: | headers libs
headers: $(HEADERS_DEPS)
rm -rf $(TARGET_HEADERS)
mkdir -p $(TARGET_HEADERS)
cp -r include/* $(TARGET_HEADERS)
ifeq ($(USE_RUST_LIBM),)
cp "openlibm/include"/*.h $(TARGET_HEADERS)
cp "openlibm/src"/*.h $(TARGET_HEADERS)
endif endif
@set -e ; \
for header in $(HEADERS_UNPARSED); do \
if test -f "src/header/$$header/cbindgen.toml"; then \
echo -e "\033[0;36;49mWriting Header $$header\033[0m"; \
out=`echo "$$header" | sed 's/_/\//g'`; \
out="$(TARGET_HEADERS)/$$out.h"; \
cat "src/header/$$header/cbindgen.toml" cbindgen.globdefs.toml \
| cbindgen "src/header/$$header/mod.rs" --config=/dev/stdin --output "$$out" 2>/dev/null; \
fi \
done; echo -e "\033[0;36;49mAll headers written\033[0m";
clean:
$(CARGO) clean all: $(BUILD)/kernel $(BUILD)/kernel.sym
$(MAKE) -C tests clean
rm -rf sysroot LD_SCRIPT=$(SOURCE)/linkers/$(ARCH).ld
LOCKFILE=$(SOURCE)/Cargo.lock
MANIFEST=$(SOURCE)/Cargo.toml
TARGET_SPEC=$(RUST_TARGET_PATH)/$(ARCH)-unknown-kernel.json
KERNEL_CARGO_FEATURES?=
$(BUILD)/kernel.all: $(LD_SCRIPT) $(LOCKFILE) $(MANIFEST) $(TARGET_SPEC) $(shell find $(SOURCE) -name "*.rs" -type f)
cargo rustc \
--bin kernel \
--manifest-path "$(MANIFEST)" \
--target "$(TARGET_SPEC)" \
--release \
-Z build-std=core,alloc -Zbuild-std-features=compiler-builtins-mem -Z json-target-spec \
--features=$(KERNEL_CARGO_FEATURES) \
-- \
-C link-arg=-T -Clink-arg="$(LD_SCRIPT)" \
-C link-arg=-z -Clink-arg=max-page-size=0x1000 \
--emit link="$(BUILD)/kernel.all"
$(BUILD)/kernel.sym: $(BUILD)/kernel.all
$(GNU_TARGET)-objcopy \
--only-keep-debug \
"$(BUILD)/kernel.all" \
"$(BUILD)/kernel.sym"
$(BUILD)/kernel: $(BUILD)/kernel.all
$(GNU_TARGET)-objcopy \
--strip-debug \
"$(BUILD)/kernel.all" \
"$(BUILD)/kernel"
KERNEL_CHECK_FEATURES?=
check: check:
$(CARGO) check cargo check \
--bin kernel \
fmt: --manifest-path "$(MANIFEST)" \
./fmt.sh --target "$(TARGET_SPEC)" \
-Z build-std=core,alloc -Zbuild-std-features=compiler-builtins-mem -Z json-target-spec \
install-headers: headers libs --features=$(KERNEL_CHECK_FEATURES)
mkdir -pv "$(DESTDIR)/include"
cp -rv "$(TARGET_HEADERS)"/* "$(DESTDIR)/include"
libs: \
$(BUILD)/$(PROFILE)/libc.a \
$(BUILD)/$(PROFILE)/libc.so \
$(BUILD)/$(PROFILE)/crt0.o \
$(BUILD)/$(PROFILE)/crti.o \
$(BUILD)/$(PROFILE)/crtn.o \
$(BUILD)/$(PROFILE)/ld.so
install-libs: headers libs
mkdir -pv "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/libc.a" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/libc.so" "$(DESTDIR)/lib"
ln -vnfs libc.so "$(DESTDIR)/lib/libc.so.6"
cp -v "$(BUILD)/$(PROFILE)/crt0.o" "$(DESTDIR)/lib"
ln -vnfs crt0.o "$(DESTDIR)/lib/crt1.o"
cp -v "$(BUILD)/$(PROFILE)/crti.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/crtn.o" "$(DESTDIR)/lib"
cp -v "$(BUILD)/$(PROFILE)/ld.so" "$(DESTDIR)/$(LD_SO_PATH)"
ifeq ($(USE_RUST_LIBM),)
cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
endif
# Empty libraries for dl, pthread, and rt
$(AR) -rcs "$(DESTDIR)/lib/libdl.a"
$(AR) -rcs "$(DESTDIR)/lib/libpthread.a"
$(AR) -rcs "$(DESTDIR)/lib/librt.a"
install-tests: tests
$(MAKE) -C tests
mkdir -p "$(DESTDIR)/relibc-tests"
cp -vr tests/build_$(TARGET)/* "$(DESTDIR)/relibc-tests/"
install: install-headers install-libs
submodules:
git submodule sync
git submodule update --init --recursive
sysroot:
@mkdir -p $@
.PHONY: sysroot/$(TARGET)
sysroot/$(TARGET): | sysroot
rm -rf $@
rm -rf $@.partial
mkdir -p $@.partial
$(MAKE) install DESTDIR=$(shell pwd)/$@.partial
mv $@.partial $@
touch $@
test: sysroot/$(TARGET)
# TODO: Fix SIGILL when running cargo test
# $(CARGO_TEST) test
$(MAKE) -C tests run
test-once: sysroot/$(TARGET)
$(MAKE) -C tests run-once TESTBIN=$(TESTBIN)
$(BUILD)/$(PROFILE)/libc.so: $(BUILD)/$(PROFILE)/libc.a
$(CC) -nostdlib \
-shared \
-Wl,--gc-sections \
-Wl,-z,pack-relative-relocs \
-Wl,--sort-common \
-Wl,--whole-archive $^ -Wl,--no-whole-archive \
-Wl,-soname,libc.so.6 \
$(LINKFLAGS) \
-o $@
$(BUILD)/$(PROFILE)/ld.so: $(BUILD)/$(PROFILE)/ld_so.o $(BUILD)/$(PROFILE)/libc.a
# TODO: merge ld.so with libc.so: --dynamic-list=dynamic-list-file
$(LD) --shared -Bsymbolic --no-relax -T ld_so/ld_script/$(TARGET).ld --gc-sections $^ -o $@
$(BUILD)/$(PROFILE)/libc.a: $(BUILD)/$(PROFILE)/librelibc.a $(BUILD)/openlibm/libopenlibm.a
echo "create $@" > "$@.mri"
for lib in $^; do\
echo "addlib $$lib" >> "$@.mri"; \
done
echo "save" >> "$@.mri"
echo "end" >> "$@.mri"
$(AR) -M < "$@.mri"
# Debug targets
$(BUILD)/debug/librelibc.a: $(SRC)
$(CARGO) rustc $(CARGOFLAGS) $(FEATURE_MATH) -- --emit link=$@ -g -C debug-assertions=no $(RUSTCFLAGS)
./renamesyms.sh "$@" "$(BUILD)/debug/deps/"
./stripcore.sh "$@"
touch $@
$(BUILD)/debug/crt0.o: $(SRC)
$(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/crti.o: $(SRC)
$(CARGO) rustc --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/crtn.o: $(SRC)
$(CARGO) rustc --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/debug/ld_so.o: $(SRC)
$(CARGO) rustc --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort -g -C debug-assertions=no $(RUSTCFLAGS)
touch $@
# Release targets
$(BUILD)/release/librelibc.a: $(SRC)
$(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS)
@# TODO: Better to only allow a certain whitelisted set of symbols? Perhaps
@# use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)].
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
./stripcore.sh "$@"
touch $@
$(BUILD)/release/crt0.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/crti.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/crtn.o: $(SRC)
$(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
$(BUILD)/release/ld_so.o: $(SRC)
$(CARGO) rustc --release --manifest-path ld_so/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ -C panic=abort $(RUSTCFLAGS)
touch $@
# Other targets
$(BUILD)/openlibm: openlibm
rm -rf $@ $@.partial
mkdir -p $(BUILD)
cp -r $< $@.partial
mv $@.partial $@
touch $@
ifeq ($(USE_RUST_LIBM),)
$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/$(PROFILE)/librelibc.a
$(MAKE) -s AR=$(AR) CC="$(CC_WRAPPER) $(CC)" LD=$(LD) CPPFLAGS="$(CPPFLAGS) -fno-stack-protector -I$(shell pwd)/include -I$(TARGET_HEADERS)" -C $< libopenlibm.a
./renamesyms.sh "$@" "$(BUILD)/release/deps/"
else
$(BUILD)/openlibm/libopenlibm.a:
mkdir -p "$(BUILD)/openlibm"
$(AR) -rcs "$(BUILD)/openlibm/libopenlibm.a"
endif
+40 -132
View File
@@ -1,169 +1,77 @@
# Redox C Library (relibc) # Kernel
relibc is a portable C standard library written in Rust and is under heavy development, this library contain the following items: Redox OS Microkernel
- C, Linux, BSD functions and extensions [![docs](https://img.shields.io/badge/docs-master-blue.svg)](https://docs.rs/redox_syscall/latest/syscall/)
- POSIX compatibility layer [![SLOCs counter](https://tokei.rs/b1/github/redox-os/kernel?category=code)](https://github.com/XAMPPRocky/tokei)
- Interfaces for system components [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
The motivation for this project is twofold: Reduce issues that the Redox developers were having with [newlib](https://sourceware.org/newlib/), and create a more stable and safe alternative to C standard libraries written in C. It is mainly designed to be used under Redox, as an alternative to newlib, but it also supports Linux via the [sc](https://crates.io/crates/sc) crate. ## Requirements
Currently Redox and Linux are supported. * [`nasm`](https://nasm.us/) needs to be available on the PATH at build time.
## `redox-rt` ## Building The Documentation
`redox-rt` is a runtime library that provides much of the code that enables POSIX on Redox, like `fork`, `exec`, signal handling, etc. Use this command:
Relibc uses it as backend in `src/platform/redox`, and it's intended to eventually be usable independently, without relibc.
## Repository Layout
- `include` - Header files (mostly macros and variadic functions `cbindgen` can't generate)
- `src` - Source files
- `src/c` - C code
- `src/crt0` - Runtime code
- `src/crti` - Runtime code
- `src/crtn` - Runtime code
- `src/header` - Header files implementation
- `src/header/*` - Each folder has a `cbindgen.toml` file, it generates a C-to-Rust interface and header files
- `src/ld_so` - Dynamic loader code
- `src/platform` - Platform-specific and common code
- `src/platform/redox` - Redox-specific code
- `src/platform/linux` - Linux-specific code
- `src/pthread` - pthread implementation
- `src/sync` - Synchronization primitives
- `tests` - C tests (each MR needs to give success in all of them)
## Download the sources
To download the relibc sources run the following command:
```sh ```sh
git clone --recursive https://gitlab.redox-os.org/redox-os/relibc cargo doc --open --target x86_64-unknown-none
``` ```
## Build Instructions ## Debugging
To build relibc out of the Redox build system, do the following steps: ### QEMU
### Dependencies Running [QEMU](https://www.qemu.org) with the `-s` flag will set up QEMU to listen on port `1234` for a GDB client to connect to it. To debug the redox kernel run.
- Install `cbindgen`
```sh ```sh
cargo install cbindgen make qemu gdb=yes
``` ```
#### Install the `expect` tool This will start a virtual machine with and listen on port `1234` for a GDB or LLDB client.
- Debian, Ubuntu and PopOS: ### GDB
```sh If you are going to use [GDB](https://www.gnu.org/software/gdb/), run these commands to load debug symbols and connect to your running kernel:
sudo apt install expect
```
(gdb) symbol-file build/kernel.sym
(gdb) target remote localhost:1234
``` ```
- Fedora: ### LLDB
```sh If you are going to use [LLDB](https://lldb.llvm.org/), run these commands to start debugging:
sudo dnf install expect
```
(lldb) target create -s build/kernel.sym build/kernel
(lldb) gdb-remote localhost:1234
``` ```
- Arch Linux: After connecting to your kernel you can set some interesting breakpoints and `continue`
the process. See your debuggers man page for more information on useful commands to run.
```sh ## Notes
sudo pacman -S expect
```
### Build Relibc - Always use `foo.get(n)` instead of `foo[n]` and try to cover for the possibility of `Option::None`. Doing the regular way may work fine for applications, but never in the kernel. No possible panics should ever exist in kernel space, because then the whole OS would just stop working.
To build the relibc library objects, run the following command: - If you receive a kernel panic in QEMU, use `pkill qemu-system` to kill the frozen QEMU process.
```sh ## How To Contribute
make all
```
- Clean old library objects and tests To learn how to contribute to this system component you need to read the following document:
```sh - [CONTRIBUTING.md](https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md)
make clean
```
## Build relibc inside the Redox build system ## Development
Inside of your Redox build system, run: To learn how to do development with this system component inside the Redox build system you need to read the [Build System](https://doc.redox-os.org/book/build-system-reference.html) and [Coding and Building](https://doc.redox-os.org/book/coding-and-building.html) pages.
```sh ### How To Build
make prefix
```
If you need to rebuild `relibc` for testing a Cookbook recipe, run: To build this system component you need to download the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page.
```sh This is necessary because they only work with cross-compilation to a Redox virtual machine, but you can do some testing from Linux.
touch relibc
make prefix r.recipe-name
```
Touching (changing the "last modified time" of) the `relibc` folder is needed to trigger recompilation for `make prefix`. Replace `recipe-name` with your desired recipe name.
Note: Do not edit `relibc` inside `prefix` folder! Do your work on `relibc` folder directly inside your Redox build system instead.
## Tests
Relibc has a test suite that also runs every time a new commit get pushed. You can see `.gitlab-ci.yml` to see how it's being executed. That being said, `./check.sh` is the recommended way to run tests. Here's few examples:
+ `./check.sh` - Run build, without running the test
+ `./check.sh --test` - Run all tests in x86_64 Redox using Redoxer
+ `./check.sh --test --host` - Run all tests in host (Linux)
+ `./check.sh --test --arch=aarch64` - Run all tests in specified arch
- Arch can be `x86_64`, `aarch64`, `i586`, or `riscv64gc`
+ `./check.sh --test=stdio/printf` - Run a single test
- Can be combined with `--host` or `--arch`
- Will run statically linked test in Linux, dynamically linked in Redox
Couple of notes:
- Relibc and its tests will rebuild if files changed, however switching between arch or host requires you to run `make clean`
- Redoxer is needed to run tests for Redox without `--host`. You can install it using `cargo install redoxer`
- Tests can hangs, the test runner can anticipate this, assuming the kernel doesn't hang too.
## Issues
#### I'm building for my own platform which I run, and am getting `x86_64-linux-gnu-ar: command not found` (or similar)
The Makefile expects GNU compiler tools prefixed with the platform specifier, as would be present when you installed a cross compiler. Since you are building for your own platform, some Linux distributions (like Manjaro) don't install/symlink the prefixed executables.
An easy fix would be to replace the corresponding lines in `config.mk`, e.g.
```diff
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
- export CC=x86_64-linux-gnu-gcc
- export LD=x86_64-linux-gnu-ld
- export AR=x86_64-linux-gnu-ar
- export NM=x86_64-linux-gnu-nm
+ export CC=gcc
+ export LD=ld
+ export AR=ar
+ export NM=nm
export OBJCOPY=objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
```
## Contributing
Before starting to contribute, read [this](CONTRIBUTING.md) document.
## Supported OSes
- Redox OS
- Linux
## Supported architectures
- i586 (Intel/AMD)
- x86_64 (Intel/AMD)
- aarch64 (ARM64)
- riscv64gc (RISC-V)
## Funding - _Unix-style Signals and Process Management_ ## Funding - _Unix-style Signals and Process Management_
+91 -53
View File
@@ -1,62 +1,100 @@
extern crate cc; #![allow(clippy::unwrap_used)] // the build script can panic
use std::{env, fs}; use std::{env, path::Path, process::Command};
use toml::Table;
fn parse_kconfig(arch: &str) -> Option<()> {
println!("cargo:rerun-if-changed=config.toml");
assert!(Path::new("config.toml.example").try_exists().unwrap());
if !Path::new("config.toml").try_exists().unwrap() {
std::fs::copy("config.toml.example", "config.toml").unwrap();
}
let config_str = std::fs::read_to_string("config.toml").unwrap();
let root: Table = toml::from_str(&config_str).unwrap();
let altfeatures = root
.get("arch")?
.as_table()
.unwrap()
.get(arch)?
.as_table()
.unwrap()
.get("features")?
.as_table()
.unwrap();
#[expect(clippy::format_collect)] // TODO: remove once version is bumped
let features_list = altfeatures
.keys()
.map(|feat| format!(", {feat:?}"))
.collect::<String>();
println!("cargo::rustc-check-cfg=cfg(cpu_feature_always, values(\"\"{features_list}))");
println!("cargo::rustc-check-cfg=cfg(cpu_feature_auto, values(\"\"{features_list}))");
println!("cargo::rustc-check-cfg=cfg(cpu_feature_never, values(\"\"{features_list}))");
let self_modifying = env::var("CARGO_FEATURE_SELF_MODIFYING").is_ok();
for (name, value) in altfeatures {
let mut choice = value.as_str().unwrap();
assert!(matches!(choice, "always" | "never" | "auto"));
if !self_modifying && choice == "auto" {
choice = "never";
}
println!("cargo:rustc-cfg=cpu_feature_{choice}=\"{name}\"");
}
Some(())
}
fn main() { fn main() {
let _crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); println!("cargo::rustc-env=TARGET={}", env::var("TARGET").unwrap());
let target = env::var("TARGET").unwrap(); println!("cargo::rustc-check-cfg=cfg(dtb)");
println!("cargo:rerun-if-changed=src/c"); let out_dir = env::var("OUT_DIR").unwrap();
let arch_str = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
// The Redoxer toolchain and some upstream nightlies keep the older match &*arch_str {
// `VaList<'a>` ABI for `extern "C" fn(...)` parameters, while others "aarch64" => {
// pass `VaListImpl<'f>` and require `.as_va_list()` to obtain println!("cargo::rustc-cfg=dtb");
// `VaList<'_, '_>`. This is a host-compiler property, so probe }
// directly with the host rustc (avoiding autocfg's target probing). "x86" => {
println!("cargo:rustc-check-cfg=cfg(relibc_valist_impl)"); println!("cargo::rerun-if-changed=src/asm/x86/trampoline.asm");
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "/tmp".to_string()); let status = Command::new("nasm")
let probe_file = std::path::Path::new(&out_dir).join("relibc_valist_probe.rs"); .arg("-f")
let probe_out = std::path::Path::new(&out_dir).join("librelibc_valist_probe.rlib"); .arg("bin")
std::fs::write( .arg("-o")
&probe_file, .arg(format!("{}/trampoline", out_dir))
"#![feature(c_variadic)] pub fn _relibc_valist_probe(_: core::ffi::VaList<'_, '_>) {}", .arg("src/asm/x86/trampoline.asm")
)
.ok();
let probe_ok = std::process::Command::new(&rustc)
.args([
"--crate-type",
"lib",
"--edition",
"2024",
probe_file.to_str().unwrap(),
"-o",
probe_out.to_str().unwrap(),
])
.status() .status()
.ok() .expect("failed to run nasm");
.map_or(false, |s| s.success()); if !status.success() {
if probe_ok { panic!("nasm failed with exit status {}", status);
println!("cargo:rustc-cfg=relibc_valist_impl"); }
}
"x86_64" => {
println!("cargo::rerun-if-changed=src/asm/x86_64/trampoline.asm");
let status = Command::new("nasm")
.arg("-f")
.arg("bin")
.arg("-o")
.arg(format!("{}/trampoline", out_dir))
.arg("src/asm/x86_64/trampoline.asm")
.status()
.expect("failed to run nasm");
if !status.success() {
panic!("nasm failed with exit status {}", status);
}
}
"riscv64" => {
println!("cargo::rustc-cfg=dtb");
}
_ => (),
} }
let mut cc_builder = &mut cc::Build::new(); let _ = parse_kconfig(&arch_str);
cc_builder = cc_builder.flag("-nostdinc").flag("-nostdlib");
if target.starts_with("aarch64") {
cc_builder = cc_builder.flag("-mno-outline-atomics")
}
cc_builder
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.files(
fs::read_dir("src/c")
.expect("src/c directory missing")
.map(|res| res.expect("read_dir error").path()),
)
.compile("relibc_c");
println!("cargo:rustc-link-lib=static=relibc_c");
} }
-24
View File
@@ -1,24 +0,0 @@
# needs a leading newline
[defines]
"target_os=redox" = "__redox__"
"target_os=linux" = "__linux__"
"target_pointer_width=64" = "__LP64__"
"target_pointer_width=32" = "__ILP32__"
"target_arch=x86" = "__i386__"
"target_arch=x86_64" = "__x86_64__"
"target_arch=aarch64" = "__aarch64__"
# This is not exact. It should be `defined(__riscv) && defined(__LP64__)`, or `defined(__riscv) && __riscv_xlen==64`
# This will do however, as long as we only support riscv64 and not riscv32
"target_arch=riscv64" = "__riscv"
# XXX: silences a warning
"feature = no_std" = "__relibc__"
# Ensure attributes are passed down from Rust
# <features.h> must be included where attributes are used in relibc
[fn]
must_use = "__nodiscard"
deprecated = "__deprecated"
deprecated_with_note = "__deprecatedNote({})"
no_return = "__noreturn"
-168
View File
@@ -1,168 +0,0 @@
#!/bin/bash
RED='\033[1;38;5;196m'
GREEN='\033[1;38;5;46m'
NC='\033[0m'
show_help() {
echo "Usage: $(basename "$0") [OPTIONS]"
echo ""
echo "Description:"
echo " Wrapper for Makefile / Cargo to run checks or tests on Redox OS targets."
echo ""
echo "Options:"
echo " --test Run 'make test' instead of 'make all'"
echo " --test= Run single 'make test'"
echo " --cargo Run 'cargo check' / 'cargo test' instead"
echo " (note: cargo test is currently not maintained for relibc)"
echo " --host Run the command on host (linux) target"
echo " --all-target Run the command on all supported Redox architectures"
echo " --target=<target> Override the target architecture (e.g., i586-unknown-redox)"
echo " --arch=<arch> Override the target architecture using arch (e.g., i586)"
echo " --help Show this help message"
echo ""
echo "Supported Targets:"
for t in "${SUPPORTED_TARGETS[@]}"; do
echo " - $t"
done
echo " - $(uname -m)-unknown-linux-gnu"
echo ""
echo "Environment:"
echo " TARGET Sets the default target (overridden by --target)"
}
if ! command -v cbindgen &> /dev/null; then
echo "Error: 'cbindgen' CLI not found."
echo "Please install it: cargo install cbindgen"
exit 1
fi
SUPPORTED_TARGETS=(
"x86_64-unknown-redox"
"i586-unknown-redox"
"aarch64-unknown-redox"
"riscv64gc-unknown-redox"
)
CURRENT_TARGET="${TARGET:-x86_64-unknown-redox}"
CHECK_ALL=false
CMD_ACTION="make"
CARGO_ACTION="check"
MAKE_ACTION="all"
TEST_BIN=""
IS_HOST=0
while [[ $# -gt 0 ]]; do
case "$1" in
--all-target)
CHECK_ALL=true
;;
--test)
MAKE_ACTION="test"
CARGO_ACTION="test"
;;
--test=*)
TEST_BIN="${1#*=}"
MAKE_ACTION="test-once"
;;
--cargo)
CMD_ACTION="cargo"
;;
--host)
CURRENT_TARGET="$(uname -m)-unknown-linux-gnu"
IS_HOST=1
;;
--target=*)
CURRENT_TARGET="${1#*=}"
;;
--arch=*)
CURRENT_TARGET="${1#*=}-unknown-redox"
;;
--help)
show_help
exit 0
;;
*)
echo -e "${RED}Error: Unknown option '$1'${NC}"
show_help
exit 1
;;
esac
shift
done
if [ "$IS_HOST" -eq 0 ]; then
if ! command -v redoxer &> /dev/null; then
echo "Error: 'redoxer' CLI not found."
echo "Please install it: cargo install redoxer"
exit 1
fi
fi
run_redoxer() {
export TARGET=$1
REDOXER_ENV="redoxer env"
if [ "$IS_HOST" -eq 0 ]; then
redoxer toolchain || { echo -e "${RED}Fail: redoxer toolchain for: $target.${NC}" && exit 1; }
export CARGO_TEST="redoxer"
export TEST_RUNNER="redoxer exec --folder ../../sysroot/$TARGET/:/usr --folder . --"
# TODO: Identify hang issue with pthread/barrier and pthread/once tests in multi core to get rid of this limit
export REDOXER_QEMU_ARGS="-smp 1"
MAKE_ACTION="$MAKE_ACTION IS_REDOX=1"
else
REDOXER_ENV=""
fi
if [ "$TEST_BIN" != "" ]; then
if [ "$IS_HOST" -eq 0 ]; then
MAKE_ACTION="$MAKE_ACTION TESTBIN=bins_dynamic/$TEST_BIN"
else
MAKE_ACTION="$MAKE_ACTION TESTBIN=bins_static/$TEST_BIN"
fi
fi
if [ "$CMD_ACTION" == "make" ]; then
CMD_OPT="-j $(nproc) $MAKE_ACTION"
else
CMD_OPT="$CARGO_ACTION"
fi
echo "----------------------------------------"
echo "Running $REDOXER_ENV $CMD_ACTION $CMD_OPT for: $TARGET"
if $REDOXER_ENV $CMD_ACTION $CMD_OPT; then
return 0
else
echo -e "${RED}Fail: $CMD_ACTION $CMD_OPT for $TARGET failed.${NC}"
return 1
fi
}
if [ "$CHECK_ALL" = true ]; then
echo "Running $CMD_ACTION for all supported Redox targets..."
has_error=false
for target in "${SUPPORTED_TARGETS[@]}"; do
if ! run_redoxer "$target"; then
has_error=true
fi
done
echo "----------------------------------------"
if [ "$has_error" = true ]; then
echo -e "${RED}Summary: One or more targets failed.${NC}"
exit 1
else
echo -e "${GREEN}Summary: All targets passed!${NC}"
exit 0
fi
else
if run_redoxer "$CURRENT_TARGET"; then
echo -e "${GREEN}Success: $CARGO_ACTION for $CURRENT_TARGET passed.${NC}"
exit 0
else
exit 1
fi
fi
Executable
+7
View File
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
export RUST_TARGET_PATH="${PWD}/targets"
export RUSTFLAGS="-C debuginfo=2"
cargo clippy --lib --release --target x86_64-unknown-none "$@"
-73
View File
@@ -1,73 +0,0 @@
ifndef TARGET
export TARGET:=$(shell rustc -Z unstable-options --print target-spec-json | grep llvm-target | cut -d '"' -f4)
endif
ifeq ($(TARGET),aarch64-unknown-linux-gnu)
export CC=aarch64-linux-gnu-gcc
export LD=aarch64-linux-gnu-ld
export AR=aarch64-linux-gnu-ar
export NM=aarch64-linux-gnu-nm
export OBJCOPY=aarch64-linux-gnu-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld.so.1
endif
ifeq ($(TARGET),aarch64-unknown-redox)
export CC=aarch64-unknown-redox-gcc
export LD=aarch64-unknown-redox-ld
export AR=aarch64-unknown-redox-ar
export NM=aarch64-unknown-redox-nm
export OBJCOPY=aarch64-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld.so.1
endif
ifeq ($(TARGET),i586-unknown-redox)
export CC=i586-unknown-redox-gcc
export LD=i586-unknown-redox-ld
export AR=i586-unknown-redox-ar
export NM=i586-unknown-redox-nm
export OBJCOPY=i586-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/libc.so.1
endif
ifeq ($(TARGET),i686-unknown-redox)
export CC=i686-unknown-redox-gcc
export LD=i686-unknown-redox-ld
export AR=i686-unknown-redox-ar
export NM=i686-unknown-redox-nm
export OBJCOPY=i686-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/libc.so.1
endif
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
export CC=x86_64-linux-gnu-gcc
export LD=x86_64-linux-gnu-ld
export AR=x86_64-linux-gnu-ar
export NM=x86_64-linux-gnu-nm
export OBJCOPY=objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
ifeq ($(TARGET),x86_64-unknown-redox)
export CC=x86_64-unknown-redox-gcc
export LD=x86_64-unknown-redox-ld
export AR=x86_64-unknown-redox-ar
export NM=x86_64-unknown-redox-nm
export OBJCOPY=x86_64-unknown-redox-objcopy
export CPPFLAGS=
LD_SO_PATH=lib/ld64.so.1
endif
ifeq ($(TARGET),riscv64gc-unknown-redox)
export CC=riscv64-unknown-redox-gcc
export LD=riscv64-unknown-redox-ld
export AR=riscv64-unknown-redox-ar
export NM=riscv64-unknown-redox-nm
export OBJCOPY=riscv64-unknown-redox-objcopy
export CPPFLAGS=-march=rv64gc -mabi=lp64d
LD_SO_PATH=lib/ld.so.1
endif
+7
View File
@@ -0,0 +1,7 @@
[arch.x86_64.features]
smap = "auto"
fsgsbase = "auto"
xsave = "auto"
xsaveopt = "auto"
# vim: ft=toml
-117
View File
@@ -1,117 +0,0 @@
name: CI
on: [push, pull_request]
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
rust: stable
- os: ubuntu-latest
rust: beta
- os: ubuntu-latest
rust: nightly
- os: macos-latest
rust: stable
- os: windows-latest
rust: stable
- os: ubuntu-latest
rust: stable
target: wasm32-wasip1
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
shell: bash
# Configure cross-builds by adding the rustup target and configuring future
# cargo invocations.
- run: |
rustup target add ${{ matrix.target }}
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
if: matrix.target != ''
# For wasm install wasmtime as a test runner and configure it with Cargo.
- name: Setup `wasmtime`
uses: bytecodealliance/actions/wasmtime/setup@v1
if: matrix.target == 'wasm32-wasip1'
- run: echo CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime >> $GITHUB_ENV
if: matrix.target == 'wasm32-wasip1'
- run: cargo test
- run: cargo test --features debug
- run: cargo test --features global
- run: cargo test --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: cargo test --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: false
- run: cargo test --features debug --release
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: RUSTFLAGS='--cfg test_lots' cargo test --release
shell: bash
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
- run: RUSTFLAGS='--cfg test_lots' cargo test --release --features debug
shell: bash
env:
CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS: true
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
wasm:
name: WebAssembly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup target add wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown --release
external-platform:
name: external-platform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup target add x86_64-fortanix-unknown-sgx
- run: cargo build --target x86_64-fortanix-unknown-sgx
fuzz:
name: Build Fuzzers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz build --dev
miri:
name: Miri
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- name: Test with Miri Stack Borrows
run: cargo miri test
- name: Test with Miri Tree Borrows
run: cargo miri test
env:
MIRIFLAGS: -Zmiri-tree-borrows
-3
View File
@@ -1,3 +0,0 @@
/target/
**/*.rs.bk
Cargo.lock
-70
View File
@@ -1,70 +0,0 @@
[package]
name = "dlmalloc"
version = "0.2.8"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/alexcrichton/dlmalloc-rs"
homepage = "https://github.com/alexcrichton/dlmalloc-rs"
documentation = "https://docs.rs/dlmalloc"
description = """
A Rust port of the dlmalloc allocator
"""
edition.workspace = true
[workspace]
members = ['fuzz']
[workspace.package]
edition = '2021'
[package.metadata.docs.rs]
features = ['global']
[lib]
doctest = false
[target.'cfg(all(unix, not(target_arch = "wasm32")))'.dependencies]
libc = { version = "0.2", default-features = false, optional = true }
[dependencies]
# For more information on these dependencies see rust-lang/rust's
# `src/tools/rustc-std-workspace` folder
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
compiler_builtins = { version = '0.1.0', optional = true }
cfg-if = "1.0"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = ">=0.52.0, <=0.59.*"
features = [
"Win32_Foundation",
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_System_SystemInformation",
]
[dev-dependencies]
arbitrary = "1.3.2"
rand = { version = "0.8", features = ['small_rng'] }
[profile.release]
debug-assertions = true
[features]
# Enable implementations of the `GlobalAlloc` standard library API, exporting a
# new `GlobalDlmalloc` as well which implements this trait.
global = ["system", "rust_api"]
# Enable very expensive debug checks in this crate
debug = []
# Enables OS APIs based on the current target, can be implemented manually
# otherwise.
system = ["libc"]
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std']
c_api = []
rust_api = []
default = ["global", "rust_api"]
-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-25
View File
@@ -1,25 +0,0 @@
Copyright (c) 2014 Alex Crichton
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-40
View File
@@ -1,40 +0,0 @@
# dlmalloc-rs
A port of [dlmalloc] to Rust.
[Documentation](https://docs.rs/dlmalloc)
[dlmalloc]: https://gee.cs.oswego.edu/dl/html/malloc.html
## Why dlmalloc?
This crate is a port of [dlmalloc] to Rust, and doesn't rely on C. The primary
purpose of this crate is to serve as the default allocator for Rust on the
`wasm32-unknown-unknown` target. At the time this was written the wasm target
didn't support C code, so it was required to have a Rust-only solution.
This allocator is not the most performant by a longshot. It is primarily, I
think, intended for being easy to port and easy to learn. I didn't dive too deep
into the implementation when writing it, it's just a straight port of the C
version.
It's unlikely that Rust code needs to worry/interact with this allocator in
general. Most of the time you'll be manually switching to a different allocator
:)
# License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.
-2
View File
@@ -1,2 +0,0 @@
corpus
artifacts
-19
View File
@@ -1,19 +0,0 @@
[package]
name = "dlmalloc-fuzz"
version = "0.0.1"
publish = false
edition.workspace = true
[package.metadata]
cargo-fuzz = true
[dependencies]
arbitrary = "1.3.2"
dlmalloc = { path = '..' }
libfuzzer-sys = "0.4.7"
[[bin]]
name = "alloc"
path = "fuzz_targets/alloc.rs"
test = false
bench = false
-8
View File
@@ -1,8 +0,0 @@
#![no_main]
use arbitrary::Unstructured;
use libfuzzer_sys::fuzz_target;
fuzz_target!(|bytes: &[u8]| {
let _ = dlmalloc_fuzz::run(&mut Unstructured::new(bytes));
});
-108
View File
@@ -1,108 +0,0 @@
use arbitrary::{Result, Unstructured};
use dlmalloc::Dlmalloc;
use std::cmp;
const MAX_ALLOCATED: usize = 100 << 20; // 100 MB
pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
let mut a = Dlmalloc::new();
let mut ptrs = Vec::new();
let mut allocated = 0;
unsafe {
while u.arbitrary()? {
// If there are pointers to free then have a chance of deallocating
// a pointer. Try not to deallocate things until there's a "large"
// working set but afterwards give it a 50/50 chance of allocating
// or deallocating.
let free = match ptrs.len() {
0 => false,
0..=10_000 => u.ratio(1, 3)?,
_ => u.arbitrary()?,
};
if free {
let idx = u.choose_index(ptrs.len())?;
let (ptr, size, align) = ptrs.swap_remove(idx);
allocated -= size;
a.free(ptr, size, align);
continue;
}
// 1/100 chance of reallocating a pointer to a different size.
if ptrs.len() > 0 && u.ratio(1, 100)? {
let idx = u.choose_index(ptrs.len())?;
let (ptr, size, align) = ptrs.swap_remove(idx);
// Arbitrarily choose whether to make this allocation either
// twice as large or half as small.
let new_size = if u.arbitrary()? {
u.int_in_range(size..=size * 2)?
} else if size > 10 {
u.int_in_range(size / 2..=size)?
} else {
continue;
};
if allocated + new_size - size > MAX_ALLOCATED {
ptrs.push((ptr, size, align));
continue;
}
allocated -= size;
allocated += new_size;
// Perform the `realloc` and assert that all bytes were copied.
let mut tmp = Vec::new();
for i in 0..cmp::min(size, new_size) {
tmp.push(*ptr.offset(i as isize));
}
let ptr = a.realloc(ptr, size, align, new_size);
assert!(!ptr.is_null());
for (i, byte) in tmp.iter().enumerate() {
assert_eq!(*byte, *ptr.offset(i as isize));
}
ptrs.push((ptr, new_size, align));
}
// Aribtrarily choose a size to allocate as well as an alignment.
// Enable small sizes with standard alignment happening a fair bit.
let size = if u.arbitrary()? {
u.int_in_range(1..=128)?
} else {
u.int_in_range(1..=128 * 1024)?
};
let align = if u.ratio(1, 10)? {
1 << u.int_in_range(3..=8)?
} else {
8
};
if size + allocated > MAX_ALLOCATED {
continue;
}
allocated += size;
// Choose arbitrarily between a zero-allocated chunk and a normal
// allocated chunk.
let zero = u.ratio(1, 50)?;
let ptr = if zero {
a.calloc(size, align)
} else {
a.malloc(size, align)
};
for i in 0..size {
if zero {
assert_eq!(*ptr.offset(i as isize), 0);
}
*ptr.offset(i as isize) = 0xce;
}
ptrs.push((ptr, size, align));
}
// Deallocate everythign when we're done.
for (ptr, size, align) in ptrs {
a.free(ptr, size, align);
}
a.destroy();
}
Ok(())
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-42
View File
@@ -1,42 +0,0 @@
use crate::Allocator;
use core::ptr;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
(ptr::null_mut(), 0, 0)
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
false
}
fn page_size(&self) -> usize {
1
}
}
-56
View File
@@ -1,56 +0,0 @@
use crate::Dlmalloc;
use core::alloc::{GlobalAlloc, Layout};
use core::ptr;
pub use crate::sys::enable_alloc_after_fork;
/// An instance of a "global allocator" backed by `Dlmalloc`
///
/// This API requires the `global` feature is activated, and this type
/// implements the `GlobalAlloc` trait in the standard library.
pub struct GlobalDlmalloc;
static mut DLMALLOC: Dlmalloc = Dlmalloc::new();
unsafe impl GlobalAlloc for GlobalDlmalloc {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).malloc(layout.size(), layout.align())
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).free(ptr, layout.size(), layout.align())
}
#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).calloc(layout.size(), layout.align())
}
#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let _guard = lock();
let dlmalloc = ptr::addr_of_mut!(DLMALLOC);
(*dlmalloc).realloc(ptr, layout.size(), layout.align(), new_size)
}
}
unsafe fn lock() -> impl Drop {
crate::sys::acquire_global_lock();
struct Guard;
impl Drop for Guard {
fn drop(&mut self) {
crate::sys::release_global_lock()
}
}
Guard
}
-230
View File
@@ -1,230 +0,0 @@
//! A Rust port of the `dlmalloc` allocator.
//!
//! The `dlmalloc` allocator is described at
//! <https://gee.cs.oswego.edu/dl/html/malloc.html> and this Rust crate is a straight
//! port of the C code for the allocator into Rust. The implementation is
//! wrapped up in a `Dlmalloc` type and has support for Linux, OSX, and Wasm
//! currently.
//!
//! The primary purpose of this crate is that it serves as the default memory
//! allocator for the `wasm32-unknown-unknown` target in the standard library.
//! Support for other platforms is largely untested and unused, but is used when
//! testing this crate.
#![allow(dead_code)]
#![no_std]
#![deny(missing_docs)]
#[cfg(feature = "rust_api")]
use core::{cmp, ptr};
#[cfg(feature = "system")]
use sys::System;
#[cfg(feature = "global")]
pub use self::global::{enable_alloc_after_fork, GlobalDlmalloc};
mod dlmalloc;
#[cfg(feature = "c_api")]
pub use dlmalloc::Dlmalloc as DlmallocCApi;
#[cfg(feature = "global")]
mod global;
/// In order for this crate to efficiently manage memory, it needs a way to communicate with the
/// underlying platform. This `Allocator` trait provides an interface for this communication.
pub unsafe trait Allocator: Send {
/// Allocates system memory region of at least `size` bytes
/// Returns a triple of `(base, size, flags)` where `base` is a pointer to the beginning of the
/// allocated memory region. `size` is the actual size of the region while `flags` specifies
/// properties of the allocated region. If `EXTERN_BIT` (bit 0) set in flags, then we did not
/// allocate this segment and so should not try to deallocate or merge with others.
/// This function can return a `std::ptr::null_mut()` when allocation fails (other values of
/// the triple will be ignored).
fn alloc(&self, size: usize) -> (*mut u8, usize, u32);
/// Remaps system memory region at `ptr` with size `oldsize` to a potential new location with
/// size `newsize`. `can_move` indicates if the location is allowed to move to a completely new
/// location, or that it is only allowed to change in size. Returns a pointer to the new
/// location in memory.
/// This function can return a `std::ptr::null_mut()` to signal an error.
fn remap(&self, ptr: *mut u8, oldsize: usize, newsize: usize, can_move: bool) -> *mut u8;
/// Frees a part of a memory chunk. The original memory chunk starts at `ptr` with size `oldsize`
/// and is turned into a memory region starting at the same address but with `newsize` bytes.
/// Returns `true` iff the access memory region could be freed.
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool;
/// Frees an entire memory region. Returns `true` iff the operation succeeded. When `false` is
/// returned, the `dlmalloc` may re-use the location on future allocation requests
fn free(&self, ptr: *mut u8, size: usize) -> bool;
/// Indicates if the system can release a part of memory. For the `flags` argument, see
/// `Allocator::alloc`
fn can_release_part(&self, flags: u32) -> bool;
/// Indicates whether newly allocated regions contain zeros.
fn allocates_zeros(&self) -> bool;
/// Returns the page size. Must be a power of two
fn page_size(&self) -> usize;
}
/// An allocator instance
///
/// Instances of this type are used to allocate blocks of memory. For best
/// results only use one of these. Currently doesn't implement `Drop` to release
/// lingering memory back to the OS. That may happen eventually though!
#[cfg(feature = "rust_api")]
pub struct Dlmalloc<
#[cfg(feature = "system")]
A = System,
#[cfg(not(feature = "system"))]
A,
>(dlmalloc::Dlmalloc<A>);
cfg_if::cfg_if! {
if #[cfg(all(feature = "system", target_family = "wasm"))] {
#[path = "wasm.rs"]
mod sys;
} else if #[cfg(all(feature = "system", target_os = "windows"))] {
#[path = "windows.rs"]
mod sys;
} else if #[cfg(all(feature = "system", target_os = "xous"))] {
#[path = "xous.rs"]
mod sys;
} else if #[cfg(all(feature = "system", any(target_os = "linux", target_os = "macos", target_os = "redox")))] {
#[path = "unix.rs"]
mod sys;
} else {
#[path = "dummy.rs"]
mod sys;
}
}
#[cfg(feature = "system")]
#[cfg(feature = "rust_api")]
impl Dlmalloc<System> {
/// Creates a new instance of an allocator
pub const fn new() -> Dlmalloc<System> {
Dlmalloc(dlmalloc::Dlmalloc::new(System::new()))
}
}
#[cfg(feature = "rust_api")]
impl<A> Dlmalloc<A> {
/// Creates a new instance of an allocator
pub const fn new_with_allocator(sys_allocator: A) -> Dlmalloc<A> {
Dlmalloc(dlmalloc::Dlmalloc::new(sys_allocator))
}
}
#[cfg(feature = "rust_api")]
impl<A: Allocator> Dlmalloc<A> {
/// Allocates `size` bytes with `align` align.
///
/// Returns a null pointer if allocation fails. Returns a valid pointer
/// otherwise.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::alloc`
/// method contracts.
#[inline]
pub unsafe fn malloc(&mut self, size: usize, align: usize) -> *mut u8 {
if align <= self.0.malloc_alignment() {
self.0.malloc(size)
} else {
self.0.memalign(align, size)
}
}
/// Same as `malloc`, except if the allocation succeeds it's guaranteed to
/// point to `size` bytes of zeros.
#[inline]
pub unsafe fn calloc(&mut self, size: usize, align: usize) -> *mut u8 {
let ptr = self.malloc(size, align);
if !ptr.is_null() && self.0.calloc_must_clear(ptr) {
ptr::write_bytes(ptr, 0, size);
}
ptr
}
/// Deallocates a `ptr` with `size` and `align` as the previous request used
/// to allocate it.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::dealloc`
/// method contracts.
#[inline]
pub unsafe fn free(&mut self, ptr: *mut u8, size: usize, align: usize) {
let _ = align;
self.0.validate_size(ptr, size);
self.0.free(ptr)
}
/// Reallocates `ptr`, a previous allocation with `old_size` and
/// `old_align`, to have `new_size` and the same alignment as before.
///
/// Returns a null pointer if the memory couldn't be reallocated, but `ptr`
/// is still valid. Returns a valid pointer and frees `ptr` if the request
/// is satisfied.
///
/// Safety and contracts are largely governed by the `GlobalAlloc::realloc`
/// method contracts.
#[inline]
pub unsafe fn realloc(
&mut self,
ptr: *mut u8,
old_size: usize,
old_align: usize,
new_size: usize,
) -> *mut u8 {
self.0.validate_size(ptr, old_size);
if old_align <= self.0.malloc_alignment() {
self.0.realloc(ptr, new_size)
} else {
let res = self.malloc(new_size, old_align);
if !res.is_null() {
let size = cmp::min(old_size, new_size);
ptr::copy_nonoverlapping(ptr, res, size);
self.free(ptr, old_size, old_align);
}
res
}
}
/// If possible, gives memory back to the system if there is unused memory
/// at the high end of the malloc pool or in unused segments.
///
/// You can call this after freeing large blocks of memory to potentially
/// reduce the system-level memory requirements of a program. However, it
/// cannot guarantee to reduce memory. Under some allocation patterns, some
/// large free blocks of memory will be locked between two used chunks, so
/// they cannot be given back to the system.
///
/// The `pad` argument represents the amount of free trailing space to
/// leave untrimmed. If this argument is zero, only the minimum amount of
/// memory to maintain internal data structures will be left. Non-zero
/// arguments can be supplied to maintain enough trailing space to service
/// future expected allocations without having to re-obtain memory from the
/// system.
///
/// Returns `true` if it actually released any memory, else `false`.
pub unsafe fn trim(&mut self, pad: usize) -> bool {
self.0.trim(pad)
}
/// Releases all allocations in this allocator back to the system,
/// consuming self and preventing further use.
///
/// Returns the number of bytes released to the system.
pub unsafe fn destroy(self) -> usize {
self.0.destroy()
}
/// Get a reference the underlying [`Allocator`] that this `Dlmalloc` was
/// constructed with.
pub fn allocator(&self) -> &A {
self.0.allocator()
}
}
-131
View File
@@ -1,131 +0,0 @@
use crate::Allocator;
use core::ptr;
/// System setting for Linux
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
#[cfg(feature = "global")]
static mut LOCK: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let addr = unsafe {
libc::mmap(
ptr::null_mut(),
size,
libc::PROT_WRITE | libc::PROT_READ,
libc::MAP_ANON | libc::MAP_PRIVATE,
-1,
0,
)
};
if addr == libc::MAP_FAILED {
(ptr::null_mut(), 0, 0)
} else {
(addr.cast(), size, 0)
}
}
#[cfg(target_os = "linux")]
fn remap(&self, ptr: *mut u8, oldsize: usize, newsize: usize, can_move: bool) -> *mut u8 {
let flags = if can_move { libc::MREMAP_MAYMOVE } else { 0 };
let ptr = unsafe { libc::mremap(ptr.cast(), oldsize, newsize, flags) };
if ptr == libc::MAP_FAILED {
ptr::null_mut()
} else {
ptr.cast()
}
}
#[cfg(any(target_os = "redox", target_os = "macos"))]
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
#[cfg(target_os = "linux")]
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe {
let rc = libc::mremap(ptr.cast(), oldsize, newsize, 0);
if rc != libc::MAP_FAILED {
return true;
}
libc::munmap(ptr.add(newsize).cast(), oldsize - newsize) == 0
}
}
#[cfg(any(target_os = "redox", target_os = "macos"))]
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe { libc::munmap(ptr.add(newsize).cast(), oldsize - newsize) == 0 }
}
fn free(&self, ptr: *mut u8, size: usize) -> bool {
unsafe { libc::munmap(ptr.cast(), size) == 0 }
}
fn can_release_part(&self, _flags: u32) -> bool {
true
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
4096
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_lock(ptr::addr_of_mut!(LOCK)), 0) }
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
unsafe { assert_eq!(libc::pthread_mutex_unlock(ptr::addr_of_mut!(LOCK)), 0) }
}
#[cfg(feature = "global")]
/// allows the allocator to remain unsable in the child process,
/// after a call to `fork(2)`
///
/// #Safety
///
/// if used, this function must be called,
/// before any allocations are made with the global allocator.
pub unsafe fn enable_alloc_after_fork() {
// atfork must only be called once, to avoid a deadlock,
// where the handler attempts to acquire the global lock twice
static mut FORK_PROTECTED: bool = false;
unsafe extern "C" fn _acquire_global_lock() {
acquire_global_lock()
}
unsafe extern "C" fn _release_global_lock() {
release_global_lock()
}
acquire_global_lock();
// if a process forks,
// it will acquire the lock before any other thread,
// protecting it from deadlock,
// due to the child being created with only the calling thread.
if !FORK_PROTECTED {
libc::pthread_atfork(
Some(_acquire_global_lock),
Some(_release_global_lock),
Some(_release_global_lock),
);
FORK_PROTECTED = true;
}
release_global_lock();
}
-76
View File
@@ -1,76 +0,0 @@
use crate::Allocator;
#[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
use core::ptr;
/// System setting for Wasm
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let pages = size / self.page_size();
let prev = wasm::memory_grow(0, pages);
if prev == usize::max_value() {
return (ptr::null_mut(), 0, 0);
}
(
(prev * self.page_size()) as *mut u8,
pages * self.page_size(),
0,
)
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
// TODO: I think this can be implemented near the end?
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
64 * 1024
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
#[allow(missing_docs)]
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {
// single threaded, no need!
assert!(!cfg!(target_feature = "atomics"));
}
-88
View File
@@ -1,88 +0,0 @@
use crate::Allocator;
use core::mem::MaybeUninit;
use core::ptr;
use windows_sys::Win32::System::Memory::*;
use windows_sys::Win32::System::SystemInformation::*;
#[cfg(feature = "global")]
use windows_sys::Win32::System::Threading::*;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let addr = unsafe {
VirtualAlloc(
ptr::null_mut(),
size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE,
)
};
if addr.is_null() {
(ptr::null_mut(), 0, 0)
} else {
(addr.cast(), size, 0)
}
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}
fn free_part(&self, ptr: *mut u8, oldsize: usize, newsize: usize) -> bool {
unsafe { VirtualFree(ptr.add(newsize).cast(), oldsize - newsize, MEM_DECOMMIT) != 0 }
}
fn free(&self, ptr: *mut u8, _size: usize) -> bool {
unsafe { VirtualFree(ptr.cast(), 0, MEM_DECOMMIT) != 0 }
}
fn can_release_part(&self, _flags: u32) -> bool {
true
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
unsafe {
let mut info = MaybeUninit::uninit();
GetSystemInfo(info.as_mut_ptr());
info.assume_init_ref().dwPageSize as usize
}
}
}
// NB: `SRWLOCK_INIT` doesn't appear to be in `windows-sys`
#[cfg(feature = "global")]
static mut LOCK: SRWLOCK = SRWLOCK {
Ptr: ptr::null_mut(),
};
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
unsafe {
AcquireSRWLockExclusive(ptr::addr_of_mut!(LOCK));
}
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
unsafe {
ReleaseSRWLockExclusive(ptr::addr_of_mut!(LOCK));
}
}
/// Not needed on Windows
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {}
-117
View File
@@ -1,117 +0,0 @@
use crate::Allocator;
use core::ptr;
pub struct System {
_priv: (),
}
impl System {
pub const fn new() -> System {
System { _priv: () }
}
}
#[cfg(target_arch = "riscv32")]
mod sys {
use core::arch::asm;
pub fn increase_heap(length: usize) -> Result<(usize, usize), ()> {
let syscall_no_increase_heap = 10usize;
let memory_flags_read_write = 2usize | 4usize;
let mut a0 = syscall_no_increase_heap;
let mut a1 = length;
let mut a2 = memory_flags_read_write;
unsafe {
asm!(
"ecall",
inlateout("a0") a0,
inlateout("a1") a1,
inlateout("a2") a2,
out("a3") _,
out("a4") _,
out("a5") _,
out("a6") _,
out("a7") _,
)
};
let result = a0;
let address = a1;
let length = a2;
// 3 is the "MemoryRange" type, and the result is only valid
// if we get nonzero address and length.
if result == 3 && address != 0 && length != 0 {
Ok((address, length))
} else {
Err(())
}
}
}
unsafe impl Allocator for System {
/// Allocate an additional `size` bytes on the heap, and return a new
/// chunk of memory, as well as the size of the allocation and some
/// flags. Since flags are unused on this platform, they will always
/// be `0`.
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let size = if size == 0 {
4096
} else if size & 4095 == 0 {
size
} else {
size + (4096 - (size & 4095))
};
if let Ok((address, length)) = sys::increase_heap(size) {
let start = address - size + length;
(start as *mut u8, size, 0)
} else {
(ptr::null_mut(), 0, 0)
}
}
fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
// TODO
ptr::null_mut()
}
fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}
fn can_release_part(&self, _flags: u32) -> bool {
false
}
fn allocates_zeros(&self) -> bool {
true
}
fn page_size(&self) -> usize {
4 * 1024
}
}
#[cfg(feature = "global")]
pub fn acquire_global_lock() {
// global feature should not be enabled
unimplemented!()
}
#[cfg(feature = "global")]
pub fn release_global_lock() {
// global feature should not be enabled
unimplemented!()
}
#[cfg(feature = "global")]
pub unsafe fn enable_alloc_after_fork() {
// platform does not support `fork()` call
}
-32
View File
@@ -1,32 +0,0 @@
extern crate dlmalloc;
use std::collections::HashMap;
use std::thread;
#[global_allocator]
#[cfg(feature = "global")]
static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
#[test]
fn foo() {
println!("hello");
}
#[test]
fn map() {
let mut m = HashMap::new();
m.insert(1, 2);
m.insert(5, 3);
drop(m);
}
#[test]
fn strings() {
format!("foo, bar, {}", "baz");
}
#[test]
#[cfg(not(target_family = "wasm"))]
fn threads() {
assert!(thread::spawn(|| panic!()).join().is_err());
}
-36
View File
@@ -1,36 +0,0 @@
use arbitrary::Unstructured;
use dlmalloc::Dlmalloc;
use rand::{rngs::SmallRng, RngCore, SeedableRng};
#[test]
fn smoke() {
let mut a = Dlmalloc::new();
unsafe {
let ptr = a.malloc(1, 1);
assert!(!ptr.is_null());
*ptr = 9;
assert_eq!(*ptr, 9);
a.free(ptr, 1, 1);
let ptr = a.malloc(1, 1);
assert!(!ptr.is_null());
*ptr = 10;
assert_eq!(*ptr, 10);
a.free(ptr, 1, 1);
}
}
#[path = "../fuzz/src/lib.rs"]
mod fuzz;
#[test]
fn stress() {
let mut rng = SmallRng::seed_from_u64(0);
let mut buf = vec![0; 4096];
let iters = if cfg!(miri) { 5 } else { 2000 };
for _ in 0..iters {
rng.fill_bytes(&mut buf);
let mut u = Unstructured::new(&buf);
let _ = fuzz::run(&mut u);
}
}
-3
View File
@@ -1,3 +0,0 @@
#!/usr/bin/env bash
cargo fmt --package relibc --package crt0 --package redox-rt "$@"
-7
View File
@@ -1,7 +0,0 @@
[package]
name = "generic-rt"
version = "0.1.0"
edition = "2024"
[lints]
workspace = true
-133
View File
@@ -1,133 +0,0 @@
#![no_std]
#![allow(internal_features)]
#![feature(core_intrinsics)]
#![deny(unsafe_op_in_unsafe_fn)]
use core::{
arch::asm,
mem::{self, offset_of},
};
#[derive(Debug)]
#[repr(C)]
pub struct GenericTcb<Os> {
/// Pointer to the end of static TLS. Must be the first member
pub tls_end: *mut u8,
/// Size of the memory allocated for the static TLS in bytes (multiple of page size)
pub tls_len: usize,
/// Pointer to this structure
pub tcb_ptr: *mut Self,
/// Size of the memory allocated for this structure in bytes (should be same as page size)
pub tcb_len: usize,
pub os_specific: Os,
}
impl<Os> GenericTcb<Os> {
/// Architecture specific code to read a usize from the TCB - aarch64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "aarch64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let abi_ptr: usize;
asm!(
"mrs {}, tpidr_el0",
out(reg) abi_ptr,
);
let tcb_ptr = *(abi_ptr as *const usize);
*((tcb_ptr + offset) as *const usize)
}
/// Architecture specific code to read a usize from the TCB - x86
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "x86")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, gs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - x86_64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "x86_64")]
pub unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"
mov {}, fs:[{}]
",
out(reg) value,
in(reg) offset,
);
value
}
/// Architecture specific code to read a usize from the TCB - riscv64
#[allow(unsafe_op_in_unsafe_fn)]
#[inline(always)]
#[cfg(target_arch = "riscv64")]
unsafe fn arch_read(offset: usize) -> usize {
let value;
asm!(
"ld {value}, -8(tp)", // TCB
"add {value}, {value}, {offset}",
"ld {value}, 0({value})",
value = out(reg) value,
offset = in(reg) offset,
);
value
}
pub unsafe fn current_ptr() -> Option<*mut Self> {
let tcb_ptr = unsafe { Self::arch_read(offset_of!(Self, tcb_ptr)) as *mut Self };
let tcb_len = unsafe { Self::arch_read(offset_of!(Self, tcb_len)) };
if tcb_ptr.is_null() || tcb_len < mem::size_of::<Self>() {
None
} else {
Some(tcb_ptr)
}
}
pub unsafe fn current() -> Option<&'static mut Self> {
unsafe { Some(&mut *Self::current_ptr()?) }
}
}
pub fn panic_notls(_msg: impl core::fmt::Display) -> ! {
// TODO: actually print _msg, perhaps by having panic_notls take a `T: DebugBackend` that can
// propagate until called by e.g. relibc start
core::intrinsics::abort();
}
pub trait ExpectTlsFree {
type Unwrapped;
fn expect_notls(self, msg: &str) -> Self::Unwrapped;
}
impl<T, E: core::fmt::Debug> ExpectTlsFree for Result<T, E> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Ok(t) => t,
Err(err) => panic_notls(format_args!(
"{msg}: expect failed for Result with err: {err:?}",
)),
}
}
}
impl<T> ExpectTlsFree for Option<T> {
type Unwrapped = T;
fn expect_notls(self, msg: &str) -> T {
match self {
Some(t) => t,
None => panic_notls(format_args!("{msg}: expect failed for Option")),
}
}
}
-6
View File
@@ -1,6 +0,0 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H
#define alloca(size) __builtin_alloca (size)
#endif /* _ALLOCA_H */
-1
View File
@@ -1 +0,0 @@
#include <openlibm_complex.h>
-95
View File
@@ -1,95 +0,0 @@
/*
* MIT License
* Copyright (c) 2020 Rich Felker musl-libc
*/
#ifndef _FEATURES_H__RELIBC
#define _FEATURES_H__RELIBC
// Version metadata for feature gating
// This is useful for divergent implementation specific behavior
// glibc, ulibc, and likely others define a similar macro
// musl does not define an equivalent macro
#define __RELIBC__ 1
#define __RELIBC__MAJOR 0
#define __RELIBC__MINOR 2
/*
* Sources:
* https://en.cppreference.com/w/c/language/attributes
* https://clang.llvm.org/docs/LanguageExtensions.html
* https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fc_005fattribute.html
* https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
*/
// Clang doesn't define __has_cpp_attribute if compiling C code
#if !defined(__has_cpp_attribute)
#define __has_cpp_attribute(x) 0
#endif
// Clang doesn't define __has_c_attribute if compiling C++ code
#if !defined(__has_c_attribute)
#define __has_c_attribute(x) 0
#endif
// Check if C23+ attributes are available
#if defined(__cplusplus)
// HACK: GCC backports C++ attributes to C++98 but doesn't accept attributes
// placed before the function like cbindgen emits.
// Let's just disable attributes for C++98 by checking if a random C++11
// feature is available.
#define __HAS_ATTRIBUTE(x) __cpp_variable_templates &&__has_cpp_attribute(x)
#else
#define __HAS_ATTRIBUTE(x) \
(__has_c_attribute(x) || __STDC_VERSION__ >= 202311L || \
__has_cpp_attribute(x))
#endif
// TODO: Not emitted with cbindgen
#if __STDC_VERSION__ >= 199901L
#define __restrict restrict
#elif !defined(__GNUC__)
#define __restrict
#endif
// TODO: Not emitted with cbindgen
#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
#define __inline inline
#elif !defined(__GNUC__)
#define __inline
#endif
// Analogous to Rust's Never type
//TODO: clang fails to compile C with [[noreturn]]
#if defined(__cplusplus) && __HAS_ATTRIBUTE(noreturn) && !(__clang__)
#define __noreturn [[noreturn]]
// #elif __STDC_VERSION__ >= 201112L
// FIXME: cbindgen incorrectly places _Noreturn
// #define __noreturn _Noreturn
#elif defined(__GNUC__)
#define __noreturn __attribute__((__noreturn__))
#else
#define __noreturn
#endif
// Analogous to Rust's #[must_use]
// C23 only
#if __HAS_ATTRIBUTE(nodiscard)
#define __nodiscard [[nodiscard]]
#define __nodiscardNote(x) [[nodiscard(x)]]
#else
#define __nodiscard
#define __nodiscardNote(x)
#endif
// Analogous to Rust's #[deprecated]
// C23 only
#if __HAS_ATTRIBUTE(deprecated)
#define __deprecated [[deprecated]]
#define __deprecatedNote(x) [[deprecated(x)]]
#else
#define __deprecated
#define __deprecatedNote(x)
#endif
#endif
-3
View File
@@ -1,3 +0,0 @@
#include <openlibm_fenv.h>
#undef complex
#undef I
-22
View File
@@ -1,22 +0,0 @@
// Copied from musl
#ifndef _ISO646_H
#define _ISO646_H
#ifndef __cplusplus
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif
#endif
-17
View File
@@ -1,17 +0,0 @@
#ifndef __MACHINE_ENDIAN_H__
/* TODO: Forcing little endian, if you need a big endian system, fix this { */
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
/* } */
#endif /* __MACHINE_ENDIAN_H__ */
-113
View File
@@ -1,113 +0,0 @@
#include <openlibm_math.h>
// Missing typedefs
typedef float float_t;
typedef double double_t;
/* double */
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#ifndef M_PI_4
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#endif
#ifndef M_2_PI
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#endif
#ifndef M_E
#define M_E 2.7182818284590452354 /* e */
#endif
#ifndef M_LOG2E
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
#endif
#ifndef M_LOG10E
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
#endif
#ifndef M_LN2
#define M_LN2 0.69314718055994530942 /* log_e 2 */
#endif
#ifndef M_LN10
#define M_LN10 2.30258509299404568402 /* log_e 10 */
#endif
#ifndef M_1_PI
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#endif
#ifndef M_2_SQRTPI
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#endif
#ifndef M_SQRT2
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#endif
#ifndef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif
/* long double */
#ifndef M_El
#define M_El 2.718281828459045235360287471352662498L /* e */
#endif
#ifndef M_LOG2El
#define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
#endif
#ifndef M_LOG10El
#define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
#endif
#ifndef M_LN2l
#define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
#endif
#ifndef M_LN10l
#define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
#endif
#ifndef M_PIl
#define M_PIl 3.141592653589793238462643383279502884L /* pi */
#endif
#ifndef M_PI_2l
#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
#endif
#ifndef M_PI_4l
#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
#endif
#ifndef M_1_PIl
#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
#endif
#ifndef M_2_PIl
#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
#endif
#ifndef M_2_SQRTPIl
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
#endif
#ifndef M_SQRT2l
#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
#endif
#ifndef M_SQRT1_2l
#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif
-1
View File
@@ -1 +0,0 @@
#include <string.h>
-10
View File
@@ -1,10 +0,0 @@
#ifndef _NETINET_IN_SYSTM_H
#define _NETINET_IN_SYSTM_H
#include <stdint.h>
typedef uint16_t n_short;
typedef uint32_t n_long;
typedef uint32_t n_time;
#endif
-6
View File
@@ -1,6 +0,0 @@
#ifndef _RELIBC_PATHS_H
#define _RELIBC_PATHS_H
#define _PATH_BSHELL "/bin/sh"
#endif
-81
View File
@@ -1,81 +0,0 @@
#ifndef _SETJMP_H
#define _SETJMP_H
#ifdef __aarch64__
typedef unsigned long jmp_buf[22];
#endif
#ifdef __arm__
typedef unsigned long long jmp_buf[32];
#endif
#ifdef __i386__
typedef unsigned long jmp_buf[6];
#endif
#ifdef __m68k__
typedef unsigned long jmp_buf[39];
#endif
#ifdef __microblaze__
typedef unsigned long jmp_buf[18];
#endif
#ifdef __mips__
typedef unsigned long long jmp_buf[13];
#endif
#ifdef __mips64__
typedef unsigned long long jmp_buf[23];
#endif
#ifdef __mipsn32__
typedef unsigned long long jmp_buf[23];
#endif
#ifdef __or1k__
typedef unsigned long jmp_buf[13];
#endif
#ifdef __powerpc__
typedef unsigned long long jmp_buf[56];
#endif
#ifdef __powerpc64__
typedef uint128_t jmp_buf[32];
#endif
#ifdef __s390x__
typedef unsigned long jmp_buf[18];
#endif
#ifdef __sh__
typedef unsigned long jmp_buf[15];
#endif
#ifdef __x32__
typedef unsigned long long jmp_buf[8];
#endif
#ifdef __x86_64__
typedef unsigned long jmp_buf[16];
#endif
#ifdef __riscv
typedef unsigned long jmp_buf[26];
#endif
typedef jmp_buf sigjmp_buf;
#ifdef __cplusplus
extern "C" {
#endif
int setjmp(jmp_buf buf);
void longjmp(jmp_buf buf, int value);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _SETJMP_H */
-10
View File
@@ -1,10 +0,0 @@
#ifndef _STDARG_H
#define _STDARG_H
typedef __builtin_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#define va_copy(d,s) __builtin_va_copy(d,s)
#endif /* _STDARG_H */
-243
View File
@@ -1,243 +0,0 @@
/* Copyright (C) 2013-2022 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/* ISO C11 Standard: 7.17 Atomics <stdatomic.h>. */
#ifndef _STDATOMIC_H
#define _STDATOMIC_H
typedef enum
{
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
memory_order_release = __ATOMIC_RELEASE,
memory_order_acq_rel = __ATOMIC_ACQ_REL,
memory_order_seq_cst = __ATOMIC_SEQ_CST
} memory_order;
typedef _Atomic _Bool atomic_bool;
typedef _Atomic char atomic_char;
typedef _Atomic signed char atomic_schar;
typedef _Atomic unsigned char atomic_uchar;
typedef _Atomic short atomic_short;
typedef _Atomic unsigned short atomic_ushort;
typedef _Atomic int atomic_int;
typedef _Atomic unsigned int atomic_uint;
typedef _Atomic long atomic_long;
typedef _Atomic unsigned long atomic_ulong;
typedef _Atomic long long atomic_llong;
typedef _Atomic unsigned long long atomic_ullong;
typedef _Atomic __CHAR16_TYPE__ atomic_char16_t;
typedef _Atomic __CHAR32_TYPE__ atomic_char32_t;
typedef _Atomic __WCHAR_TYPE__ atomic_wchar_t;
typedef _Atomic __INT_LEAST8_TYPE__ atomic_int_least8_t;
typedef _Atomic __UINT_LEAST8_TYPE__ atomic_uint_least8_t;
typedef _Atomic __INT_LEAST16_TYPE__ atomic_int_least16_t;
typedef _Atomic __UINT_LEAST16_TYPE__ atomic_uint_least16_t;
typedef _Atomic __INT_LEAST32_TYPE__ atomic_int_least32_t;
typedef _Atomic __UINT_LEAST32_TYPE__ atomic_uint_least32_t;
typedef _Atomic __INT_LEAST64_TYPE__ atomic_int_least64_t;
typedef _Atomic __UINT_LEAST64_TYPE__ atomic_uint_least64_t;
typedef _Atomic __INT_FAST8_TYPE__ atomic_int_fast8_t;
typedef _Atomic __UINT_FAST8_TYPE__ atomic_uint_fast8_t;
typedef _Atomic __INT_FAST16_TYPE__ atomic_int_fast16_t;
typedef _Atomic __UINT_FAST16_TYPE__ atomic_uint_fast16_t;
typedef _Atomic __INT_FAST32_TYPE__ atomic_int_fast32_t;
typedef _Atomic __UINT_FAST32_TYPE__ atomic_uint_fast32_t;
typedef _Atomic __INT_FAST64_TYPE__ atomic_int_fast64_t;
typedef _Atomic __UINT_FAST64_TYPE__ atomic_uint_fast64_t;
typedef _Atomic __INTPTR_TYPE__ atomic_intptr_t;
typedef _Atomic __UINTPTR_TYPE__ atomic_uintptr_t;
typedef _Atomic __SIZE_TYPE__ atomic_size_t;
typedef _Atomic __PTRDIFF_TYPE__ atomic_ptrdiff_t;
typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
#define ATOMIC_VAR_INIT(VALUE) (VALUE)
/* Initialize an atomic object pointed to by PTR with VAL. */
#define atomic_init(PTR, VAL) \
atomic_store_explicit (PTR, VAL, __ATOMIC_RELAXED)
#define kill_dependency(Y) \
__extension__ \
({ \
__auto_type __kill_dependency_tmp = (Y); \
__kill_dependency_tmp; \
})
extern void atomic_thread_fence (memory_order);
#define atomic_thread_fence(MO) __atomic_thread_fence (MO)
extern void atomic_signal_fence (memory_order);
#define atomic_signal_fence(MO) __atomic_signal_fence (MO)
#define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
/* Note that these macros require __auto_type to remove
_Atomic qualifiers (and const qualifiers, if those are valid on
macro operands).
Also note that the header file uses the generic form of __atomic
builtins, which requires the address to be taken of the value
parameter, and then we pass that value on. This allows the macros
to work for any type, and the compiler is smart enough to convert
these to lock-free _N variants if possible, and throw away the
temps. */
#define atomic_store_explicit(PTR, VAL, MO) \
__extension__ \
({ \
__auto_type __atomic_store_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_store_ptr) __atomic_store_tmp = (VAL); \
__atomic_store (__atomic_store_ptr, &__atomic_store_tmp, (MO)); \
})
#define atomic_store(PTR, VAL) \
atomic_store_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
#define atomic_load_explicit(PTR, MO) \
__extension__ \
({ \
__auto_type __atomic_load_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_load_ptr) __atomic_load_tmp; \
__atomic_load (__atomic_load_ptr, &__atomic_load_tmp, (MO)); \
__atomic_load_tmp; \
})
#define atomic_load(PTR) atomic_load_explicit (PTR, __ATOMIC_SEQ_CST)
#define atomic_exchange_explicit(PTR, VAL, MO) \
__extension__ \
({ \
__auto_type __atomic_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_exchange_ptr) __atomic_exchange_val = (VAL); \
__typeof__ ((void)0, *__atomic_exchange_ptr) __atomic_exchange_tmp; \
__atomic_exchange (__atomic_exchange_ptr, &__atomic_exchange_val, \
&__atomic_exchange_tmp, (MO)); \
__atomic_exchange_tmp; \
})
#define atomic_exchange(PTR, VAL) \
atomic_exchange_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
#define atomic_compare_exchange_strong_explicit(PTR, VAL, DES, SUC, FAIL) \
__extension__ \
({ \
__auto_type __atomic_compare_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
= (DES); \
__atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
&__atomic_compare_exchange_tmp, 0, \
(SUC), (FAIL)); \
})
#define atomic_compare_exchange_strong(PTR, VAL, DES) \
atomic_compare_exchange_strong_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#define atomic_compare_exchange_weak_explicit(PTR, VAL, DES, SUC, FAIL) \
__extension__ \
({ \
__auto_type __atomic_compare_exchange_ptr = (PTR); \
__typeof__ ((void)0, *__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
= (DES); \
__atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
&__atomic_compare_exchange_tmp, 1, \
(SUC), (FAIL)); \
})
#define atomic_compare_exchange_weak(PTR, VAL, DES) \
atomic_compare_exchange_weak_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#define atomic_fetch_add(PTR, VAL) __atomic_fetch_add ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_add_explicit(PTR, VAL, MO) \
__atomic_fetch_add ((PTR), (VAL), (MO))
#define atomic_fetch_sub(PTR, VAL) __atomic_fetch_sub ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_sub_explicit(PTR, VAL, MO) \
__atomic_fetch_sub ((PTR), (VAL), (MO))
#define atomic_fetch_or(PTR, VAL) __atomic_fetch_or ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_or_explicit(PTR, VAL, MO) \
__atomic_fetch_or ((PTR), (VAL), (MO))
#define atomic_fetch_xor(PTR, VAL) __atomic_fetch_xor ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_xor_explicit(PTR, VAL, MO) \
__atomic_fetch_xor ((PTR), (VAL), (MO))
#define atomic_fetch_and(PTR, VAL) __atomic_fetch_and ((PTR), (VAL), \
__ATOMIC_SEQ_CST)
#define atomic_fetch_and_explicit(PTR, VAL, MO) \
__atomic_fetch_and ((PTR), (VAL), (MO))
typedef _Atomic struct
{
#if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
_Bool __val;
#else
unsigned char __val;
#endif
} atomic_flag;
#define ATOMIC_FLAG_INIT { 0 }
extern _Bool atomic_flag_test_and_set (volatile atomic_flag *);
#define atomic_flag_test_and_set(PTR) \
__atomic_test_and_set ((PTR), __ATOMIC_SEQ_CST)
extern _Bool atomic_flag_test_and_set_explicit (volatile atomic_flag *,
memory_order);
#define atomic_flag_test_and_set_explicit(PTR, MO) \
__atomic_test_and_set ((PTR), (MO))
extern void atomic_flag_clear (volatile atomic_flag *);
#define atomic_flag_clear(PTR) __atomic_clear ((PTR), __ATOMIC_SEQ_CST)
extern void atomic_flag_clear_explicit (volatile atomic_flag *, memory_order);
#define atomic_flag_clear_explicit(PTR, MO) __atomic_clear ((PTR), (MO))
#endif /* _STDATOMIC_H */
-19
View File
@@ -1,19 +0,0 @@
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#else /* __cplusplus */
#if __cplusplus < 201103L
#define bool bool
#define false false
#define true true
#endif /*__cplusplus < 201103L*/
#endif /* __cplusplus */
#define __bool_true_false_are_defined 1
#endif /* _STDBOOL_H */
-377
View File
@@ -1,377 +0,0 @@
/* Copyright (C) 2008-2018 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/*
* ISO C Standard: 7.18 Integer types <stdint.h>
*/
#ifndef _STDINT_H
#define _STDINT_H
/* 7.8.1.1 Exact-width integer types */
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ int8_t;
#endif
#ifdef __INT16_TYPE__
typedef __INT16_TYPE__ int16_t;
#endif
#ifdef __INT32_TYPE__
typedef __INT32_TYPE__ int32_t;
#endif
#ifdef __INT64_TYPE__
typedef __INT64_TYPE__ int64_t;
#endif
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ uint8_t;
typedef __UINT8_TYPE__ u_int8_t;
#endif
#ifdef __UINT16_TYPE__
typedef __UINT16_TYPE__ uint16_t;
typedef __UINT16_TYPE__ u_int16_t;
#endif
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT32_TYPE__ u_int32_t;
// Required by openlibm
typedef __UINT32_TYPE__ __uint32_t;
#endif
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ uint64_t;
typedef __UINT64_TYPE__ u_int64_t;
// Required by openlibm
typedef __UINT64_TYPE__ __uint64_t;
#endif
/* 7.8.1.2 Minimum-width integer types */
typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;
/* 7.8.1.3 Fastest minimum-width integer types */
typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;
/* 7.8.1.4 Integer types capable of holding object pointers */
#ifdef __INTPTR_TYPE__
typedef __INTPTR_TYPE__ intptr_t;
#endif
#ifdef __UINTPTR_TYPE__
typedef __UINTPTR_TYPE__ uintptr_t;
#endif
/* 7.8.1.5 Greatest-width integer types */
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_LIMIT_MACROS)
/* 7.18.2 Limits of specified-width integer types */
#ifdef __INT8_MAX__
# undef INT8_MAX
# define INT8_MAX __INT8_MAX__
# undef INT8_MIN
# define INT8_MIN (-INT8_MAX - 1)
#endif
#ifdef __UINT8_MAX__
# undef UINT8_MAX
# define UINT8_MAX __UINT8_MAX__
#endif
#ifdef __INT16_MAX__
# undef INT16_MAX
# define INT16_MAX __INT16_MAX__
# undef INT16_MIN
# define INT16_MIN (-INT16_MAX - 1)
#endif
#ifdef __UINT16_MAX__
# undef UINT16_MAX
# define UINT16_MAX __UINT16_MAX__
#endif
#ifdef __INT32_MAX__
# undef INT32_MAX
# define INT32_MAX __INT32_MAX__
# undef INT32_MIN
# define INT32_MIN (-INT32_MAX - 1)
#endif
#ifdef __UINT32_MAX__
# undef UINT32_MAX
# define UINT32_MAX __UINT32_MAX__
#endif
#ifdef __INT64_MAX__
# undef INT64_MAX
# define INT64_MAX __INT64_MAX__
# undef INT64_MIN
# define INT64_MIN (-INT64_MAX - 1)
#endif
#ifdef __UINT64_MAX__
# undef UINT64_MAX
# define UINT64_MAX __UINT64_MAX__
#endif
#undef INT_LEAST8_MAX
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
#undef INT_LEAST8_MIN
#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1)
#undef UINT_LEAST8_MAX
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
#undef INT_LEAST16_MAX
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
#undef INT_LEAST16_MIN
#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1)
#undef UINT_LEAST16_MAX
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#undef INT_LEAST32_MAX
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
#undef INT_LEAST32_MIN
#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1)
#undef UINT_LEAST32_MAX
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#undef INT_LEAST64_MAX
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
#undef INT_LEAST64_MIN
#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1)
#undef UINT_LEAST64_MAX
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
#undef INT_FAST8_MAX
#define INT_FAST8_MAX __INT_FAST8_MAX__
#undef INT_FAST8_MIN
#define INT_FAST8_MIN (-INT_FAST8_MAX - 1)
#undef UINT_FAST8_MAX
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
#undef INT_FAST16_MAX
#define INT_FAST16_MAX __INT_FAST16_MAX__
#undef INT_FAST16_MIN
#define INT_FAST16_MIN (-INT_FAST16_MAX - 1)
#undef UINT_FAST16_MAX
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
#undef INT_FAST32_MAX
#define INT_FAST32_MAX __INT_FAST32_MAX__
#undef INT_FAST32_MIN
#define INT_FAST32_MIN (-INT_FAST32_MAX - 1)
#undef UINT_FAST32_MAX
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
#undef INT_FAST64_MAX
#define INT_FAST64_MAX __INT_FAST64_MAX__
#undef INT_FAST64_MIN
#define INT_FAST64_MIN (-INT_FAST64_MAX - 1)
#undef UINT_FAST64_MAX
#define UINT_FAST64_MAX __UINT_FAST64_MAX__
#ifdef __INTPTR_MAX__
# undef INTPTR_MAX
# define INTPTR_MAX __INTPTR_MAX__
# undef INTPTR_MIN
# define INTPTR_MIN (-INTPTR_MAX - 1)
#endif
#ifdef __UINTPTR_MAX__
# undef UINTPTR_MAX
# define UINTPTR_MAX __UINTPTR_MAX__
#endif
#undef INTMAX_MAX
#define INTMAX_MAX __INTMAX_MAX__
#undef INTMAX_MIN
#define INTMAX_MIN (-INTMAX_MAX - 1)
#undef UINTMAX_MAX
#define UINTMAX_MAX __UINTMAX_MAX__
/* 7.18.3 Limits of other integer types */
#undef PTRDIFF_MAX
#define PTRDIFF_MAX __PTRDIFF_MAX__
#undef PTRDIFF_MIN
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
#undef SIG_ATOMIC_MAX
#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
#undef SIG_ATOMIC_MIN
#define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__
#undef SIZE_MAX
#define SIZE_MAX __SIZE_MAX__
#undef WCHAR_MAX
#define WCHAR_MAX __WCHAR_MAX__
#undef WCHAR_MIN
#define WCHAR_MIN __WCHAR_MIN__
#undef WINT_MAX
#define WINT_MAX __WINT_MAX__
#undef WINT_MIN
#define WINT_MIN __WINT_MIN__
#endif /* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_LIMIT_MACROS) */
#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_CONSTANT_MACROS)
#undef INT8_C
#define INT8_C(c) __INT8_C(c)
#undef INT16_C
#define INT16_C(c) __INT16_C(c)
#undef INT32_C
#define INT32_C(c) __INT32_C(c)
#undef INT64_C
#define INT64_C(c) __INT64_C(c)
#undef UINT8_C
#define UINT8_C(c) __UINT8_C(c)
#undef UINT16_C
#define UINT16_C(c) __UINT16_C(c)
#undef UINT32_C
#define UINT32_C(c) __UINT32_C(c)
#undef UINT64_C
#define UINT64_C(c) __UINT64_C(c)
#undef INTMAX_C
#define INTMAX_C(c) __INTMAX_C(c)
#undef UINTMAX_C
#define UINTMAX_C(c) __UINTMAX_C(c)
#endif /* (!defined __cplusplus || __cplusplus >= 201103L
|| defined __STDC_CONSTANT_MACROS) */
#ifdef __STDC_WANT_IEC_60559_BFP_EXT__
/* TS 18661-1 widths of integer types. */
#ifdef __INT8_TYPE__
# undef INT8_WIDTH
# define INT8_WIDTH 8
#endif
#ifdef __UINT8_TYPE__
# undef UINT8_WIDTH
# define UINT8_WIDTH 8
#endif
#ifdef __INT16_TYPE__
# undef INT16_WIDTH
# define INT16_WIDTH 16
#endif
#ifdef __UINT16_TYPE__
# undef UINT16_WIDTH
# define UINT16_WIDTH 16
#endif
#ifdef __INT32_TYPE__
# undef INT32_WIDTH
# define INT32_WIDTH 32
#endif
#ifdef __UINT32_TYPE__
# undef UINT32_WIDTH
# define UINT32_WIDTH 32
#endif
#ifdef __INT64_TYPE__
# undef INT64_WIDTH
# define INT64_WIDTH 64
#endif
#ifdef __UINT64_TYPE__
# undef UINT64_WIDTH
# define UINT64_WIDTH 64
#endif
#undef INT_LEAST8_WIDTH
#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
#undef UINT_LEAST8_WIDTH
#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
#undef INT_LEAST16_WIDTH
#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
#undef UINT_LEAST16_WIDTH
#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
#undef INT_LEAST32_WIDTH
#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
#undef UINT_LEAST32_WIDTH
#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
#undef INT_LEAST64_WIDTH
#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
#undef UINT_LEAST64_WIDTH
#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
#undef INT_FAST8_WIDTH
#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
#undef UINT_FAST8_WIDTH
#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
#undef INT_FAST16_WIDTH
#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
#undef UINT_FAST16_WIDTH
#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
#undef INT_FAST32_WIDTH
#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
#undef UINT_FAST32_WIDTH
#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
#undef INT_FAST64_WIDTH
#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
#undef UINT_FAST64_WIDTH
#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
#ifdef __INTPTR_TYPE__
# undef INTPTR_WIDTH
# define INTPTR_WIDTH __INTPTR_WIDTH__
#endif
#ifdef __UINTPTR_TYPE__
# undef UINTPTR_WIDTH
# define UINTPTR_WIDTH __INTPTR_WIDTH__
#endif
#undef INTMAX_WIDTH
#define INTMAX_WIDTH __INTMAX_WIDTH__
#undef UINTMAX_WIDTH
#define UINTMAX_WIDTH __INTMAX_WIDTH__
#undef PTRDIFF_WIDTH
#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
#undef SIG_ATOMIC_WIDTH
#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
#undef SIZE_WIDTH
#define SIZE_WIDTH __SIZE_WIDTH__
#undef WCHAR_WIDTH
#define WCHAR_WIDTH __WCHAR_WIDTH__
#undef WINT_WIDTH
#define WINT_WIDTH __WINT_WIDTH__
#ifdef __ILP32__
#define SIZE_MAX UINT32_MAX
#else
#define SIZE_MAX UINT64_MAX
#endif
#endif
#endif /* _GCC_STDINT_H */
-22
View File
@@ -1,22 +0,0 @@
#ifndef _STDIO_EXT_H
#define _STDIO_EXT_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
size_t __freadahead(FILE *stream);
size_t __fpending(FILE *stream);
int __freadable(FILE *stream);
int __freading(FILE *stream);
void __fseterr(FILE *stream);
int __fwritable(FILE *stream);
int __fwriting(FILE *stream);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _STDIO_EXT_H */
-19
View File
@@ -1,19 +0,0 @@
/* Spec:
* The <stdnoreturn.h> header shall define the macro noreturn which shall
* expand to _Noreturn */
#ifndef _STDNORETURN_H
#define _STDNORETURN_H
#ifndef __cplusplus
/* Borrowed from musl */
#if __STDC_VERSION__ >= 201112L
#elif defined(__GNUC__)
#define _Noreturn __attribute__((__noreturn__))
#else
#define _Noreturn
#endif
#define noreturn _Noreturn
#endif
#endif
-36
View File
@@ -1,36 +0,0 @@
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define __bitop(array, index, op) ((array)[(index) / 8] op (1 << (index) % 8))
#define setbit(array, index) __bitop(array, index, |=)
#define clrbit(array, index) __bitop(array, index, &= ~)
#define isset(array, index) __bitop(array, index, &)
#define isclr(array, index) !isset(array, index)
#define howmany(bits, size) (((bits) + (size) - 1) / (size))
#define roundup(bits, size) (howmany(bits, size) * (size))
#define powerof2(n) !(((n) - 1) & (n))
// Shamelessly copied from musl.
// Tweak as needed.
#define MAXSYMLINKS 20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN 255
#define MAXPATHLEN 4096
#define NBBY 8
#define NGROUPS 32
#define CANBSIZ 255
#define NOFILE 256
#define NCARGS 131072
#define DEV_BSIZE 512
#define NOGROUP (-1)
#include <sys/resource.h>
#include <limits.h>
#include <machine/endian.h>
#endif
-1
View File
@@ -1 +0,0 @@
#include <poll.h>
-846
View File
@@ -1,846 +0,0 @@
/* $NetBSD: queue.h,v 1.70 2015/11/02 15:21:23 christos Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
* A singly-linked list is headed by a single forward pointer. The
* elements are singly linked for minimum space and pointer manipulation
* overhead at the expense of O(n) removal for arbitrary elements. New
* elements can be added to the list after an existing element or at the
* head of the list. Elements being removed from the head of the list
* should use the explicit macro for this purpose for optimum
* efficiency. A singly-linked list may only be traversed in the forward
* direction. Singly-linked lists are ideal for applications with large
* datasets and few or no removals or for implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
/*
* Include the definition of NULL only on NetBSD because sys/null.h
* is not available elsewhere. This conditional makes the header
* portable and it can simply be dropped verbatim into any system.
* The caveat is that on other systems some other header
* must provide NULL before the macros can be used.
*/
#ifdef __NetBSD__
#include <sys/null.h>
#endif
#if defined(QUEUEDEBUG)
# if defined(_KERNEL)
# define QUEUEDEBUG_ABORT(...) panic(__VA_ARGS__)
# else
# include <err.h>
# define QUEUEDEBUG_ABORT(...) err(1, __VA_ARGS__)
# endif
#endif
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_END(head) NULL
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
for((var) = (head)->slh_first; \
(var) != SLIST_END(head); \
(var) = (var)->field.sle_next)
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST((head)); \
(var) != SLIST_END(head) && \
((tvar) = SLIST_NEXT((var), field), 1); \
(var) = (tvar))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) do { \
(head)->slh_first = SLIST_END(head); \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE_AFTER(slistelm, field) do { \
(slistelm)->field.sle_next = \
SLIST_NEXT(SLIST_NEXT((slistelm), field), field); \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = (head)->slh_first; \
while(curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
} while (/*CONSTCOND*/0)
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List access methods.
*/
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_END(head) NULL
#define LIST_EMPTY(head) ((head)->lh_first == LIST_END(head))
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_FOREACH(var, head, field) \
for ((var) = ((head)->lh_first); \
(var) != LIST_END(head); \
(var) = ((var)->field.le_next))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \
(var) != LIST_END(head) && \
((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#define LIST_MOVE(head1, head2) do { \
LIST_INIT((head2)); \
if (!LIST_EMPTY((head1))) { \
(head2)->lh_first = (head1)->lh_first; \
LIST_INIT((head1)); \
} \
} while (/*CONSTCOND*/0)
/*
* List functions.
*/
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field) \
if ((head)->lh_first && \
(head)->lh_first->field.le_prev != &(head)->lh_first) \
QUEUEDEBUG_ABORT("LIST_INSERT_HEAD %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_LIST_OP(elm, field) \
if ((elm)->field.le_next && \
(elm)->field.le_next->field.le_prev != \
&(elm)->field.le_next) \
QUEUEDEBUG_ABORT("LIST_* forw %p %s:%d", (elm), \
__FILE__, __LINE__); \
if (*(elm)->field.le_prev != (elm)) \
QUEUEDEBUG_ABORT("LIST_* back %p %s:%d", (elm), \
__FILE__, __LINE__);
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field) \
(elm)->field.le_next = (void *)1L; \
(elm)->field.le_prev = (void *)1L;
#else
#define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)
#define QUEUEDEBUG_LIST_OP(elm, field)
#define QUEUEDEBUG_LIST_POSTREMOVE(elm, field)
#endif
#define LIST_INIT(head) do { \
(head)->lh_first = LIST_END(head); \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
QUEUEDEBUG_LIST_OP((listelm), field) \
if (((elm)->field.le_next = (listelm)->field.le_next) != \
LIST_END(head)) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
QUEUEDEBUG_LIST_OP((listelm), field) \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_LIST_INSERT_HEAD((head), (elm), field) \
if (((elm)->field.le_next = (head)->lh_first) != LIST_END(head))\
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (/*CONSTCOND*/0)
#define LIST_REMOVE(elm, field) do { \
QUEUEDEBUG_LIST_OP((elm), field) \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
#define LIST_REPLACE(elm, elm2, field) do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
&(elm2)->field.le_next; \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
QUEUEDEBUG_LIST_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue access methods.
*/
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_END(head) NULL
#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == SIMPLEQ_END(head))
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define SIMPLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->sqh_first); \
(var) != SIMPLEQ_END(head); \
(var) = ((var)->field.sqe_next))
#define SIMPLEQ_FOREACH_SAFE(var, head, field, next) \
for ((var) = ((head)->sqh_first); \
(var) != SIMPLEQ_END(head) && \
((next = ((var)->field.sqe_next)), 1); \
(var) = (next))
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
== NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
if ((head)->sqh_first == (elm)) { \
SIMPLEQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->sqh_first; \
while (curelm->field.sqe_next != (elm)) \
curelm = curelm->field.sqe_next; \
if ((curelm->field.sqe_next = \
curelm->field.sqe_next->field.sqe_next) == NULL) \
(head)->sqh_last = &(curelm)->field.sqe_next; \
} \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_CONCAT(head1, head2) do { \
if (!SIMPLEQ_EMPTY((head2))) { \
*(head1)->sqh_last = (head2)->sqh_first; \
(head1)->sqh_last = (head2)->sqh_last; \
SIMPLEQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_LAST(head, type, field) \
(SIMPLEQ_EMPTY((head)) ? \
NULL : \
((struct type *)(void *) \
((char *)((head)->sqh_last) - offsetof(struct type, field))))
/*
* Tail queue definitions.
*/
#define _TAILQ_HEAD(name, type, qual) \
struct name { \
qual type *tqh_first; /* first element */ \
qual type *qual *tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
#define TAILQ_HEAD_INITIALIZER(head) \
{ TAILQ_END(head), &(head).tqh_first }
#define _TAILQ_ENTRY(type, qual) \
struct { \
qual type *tqe_next; /* next element */ \
qual type *qual *tqe_prev; /* address of previous next element */\
}
#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
/*
* Tail queue access methods.
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) (NULL)
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)(void *)((head)->tqh_last))->tqh_last))
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)(void *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_EMPTY(head) (TAILQ_FIRST(head) == TAILQ_END(head))
#define TAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->tqh_first); \
(var) != TAILQ_END(head); \
(var) = ((var)->field.tqe_next))
#define TAILQ_FOREACH_SAFE(var, head, field, next) \
for ((var) = ((head)->tqh_first); \
(var) != TAILQ_END(head) && \
((next) = TAILQ_NEXT(var, field), 1); (var) = (next))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var) != TAILQ_END(head); \
(var) = TAILQ_PREV((var), headname, field))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, prev) \
for ((var) = TAILQ_LAST((head), headname); \
(var) != TAILQ_END(head) && \
((prev) = TAILQ_PREV((var), headname, field), 1); (var) = (prev))
/*
* Tail queue functions.
*/
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field) \
if ((head)->tqh_first && \
(head)->tqh_first->field.tqe_prev != &(head)->tqh_first) \
QUEUEDEBUG_ABORT("TAILQ_INSERT_HEAD %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field) \
if (*(head)->tqh_last != NULL) \
QUEUEDEBUG_ABORT("TAILQ_INSERT_TAIL %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_OP(elm, field) \
if ((elm)->field.tqe_next && \
(elm)->field.tqe_next->field.tqe_prev != \
&(elm)->field.tqe_next) \
QUEUEDEBUG_ABORT("TAILQ_* forw %p %s:%d", (elm), \
__FILE__, __LINE__); \
if (*(elm)->field.tqe_prev != (elm)) \
QUEUEDEBUG_ABORT("TAILQ_* back %p %s:%d", (elm), \
__FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field) \
if ((elm)->field.tqe_next == NULL && \
(head)->tqh_last != &(elm)->field.tqe_next) \
QUEUEDEBUG_ABORT("TAILQ_PREREMOVE head %p elm %p %s:%d",\
(head), (elm), __FILE__, __LINE__);
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field) \
(elm)->field.tqe_next = (void *)1L; \
(elm)->field.tqe_prev = (void *)1L;
#else
#define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)
#define QUEUEDEBUG_TAILQ_INSERT_TAIL(head, elm, field)
#define QUEUEDEBUG_TAILQ_OP(elm, field)
#define QUEUEDEBUG_TAILQ_PREREMOVE(head, elm, field)
#define QUEUEDEBUG_TAILQ_POSTREMOVE(elm, field)
#endif
#define TAILQ_INIT(head) do { \
(head)->tqh_first = TAILQ_END(head); \
(head)->tqh_last = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_TAILQ_INSERT_HEAD((head), (elm), field) \
if (((elm)->field.tqe_next = (head)->tqh_first) != TAILQ_END(head))\
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
QUEUEDEBUG_TAILQ_INSERT_TAIL((head), (elm), field) \
(elm)->field.tqe_next = TAILQ_END(head); \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
QUEUEDEBUG_TAILQ_OP((listelm), field) \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != \
TAILQ_END(head)) \
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
QUEUEDEBUG_TAILQ_OP((listelm), field) \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_REMOVE(head, elm, field) do { \
QUEUEDEBUG_TAILQ_PREREMOVE((head), (elm), field) \
QUEUEDEBUG_TAILQ_OP((elm), field) \
if (((elm)->field.tqe_next) != TAILQ_END(head)) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \
} while (/*CONSTCOND*/0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != \
TAILQ_END(head)) \
(elm2)->field.tqe_next->field.tqe_prev = \
&(elm2)->field.tqe_next; \
else \
(head)->tqh_last = &(elm2)->field.tqe_next; \
(elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
*(elm2)->field.tqe_prev = (elm2); \
QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field); \
} while (/*CONSTCOND*/0)
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
/*
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first; /* first element */ \
struct type **stqh_last; /* addr of last next element */ \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
/*
* Singly-linked Tail queue access methods.
*/
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_END(head) NULL
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
#define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head))
/*
* Singly-linked Tail queue functions.
*/
#define STAILQ_INIT(head) do { \
(head)->stqh_first = NULL; \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
(head)->stqh_last = &(elm)->field.stqe_next; \
(head)->stqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.stqe_next = NULL; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &(elm)->field.stqe_next; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
(head)->stqh_last = &(elm)->field.stqe_next; \
(listelm)->field.stqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE_HEAD(head, field) do { \
if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE(head, elm, type, field) do { \
if ((head)->stqh_first == (elm)) { \
STAILQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->stqh_first; \
while (curelm->field.stqe_next != (elm)) \
curelm = curelm->field.stqe_next; \
if ((curelm->field.stqe_next = \
curelm->field.stqe_next->field.stqe_next) == NULL) \
(head)->stqh_last = &(curelm)->field.stqe_next; \
} \
} while (/*CONSTCOND*/0)
#define STAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->stqh_first); \
(var); \
(var) = ((var)->field.stqe_next))
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = STAILQ_FIRST((head)); \
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
#define STAILQ_LAST(head, type, field) \
(STAILQ_EMPTY((head)) ? \
NULL : \
((struct type *)(void *) \
((char *)((head)->stqh_last) - offsetof(struct type, field))))
#ifndef _KERNEL
/*
* Circular queue definitions. Do not use. We still keep the macros
* for compatibility but because of pointer aliasing issues their use
* is discouraged!
*/
/*
* __launder_type(): We use this ugly hack to work around the the compiler
* noticing that two types may not alias each other and elide tests in code.
* We hit this in the CIRCLEQ macros when comparing 'struct name *' and
* 'struct type *' (see CIRCLEQ_HEAD()). Modern compilers (such as GCC
* 4.8) declare these comparisons as always false, causing the code to
* not run as designed.
*
* This hack is only to be used for comparisons and thus can be fully const.
* Do not use for assignment.
*
* If we ever choose to change the ABI of the CIRCLEQ macros, we could fix
* this by changing the head/tail sentinal values, but see the note above
* this one.
*/
static __inline const void * __launder_type(const void *);
static __inline const void *
__launder_type(const void *__x)
{
__asm __volatile("" : "+r" (__x));
return __x;
}
#if defined(QUEUEDEBUG)
#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field) \
if ((head)->cqh_first != CIRCLEQ_ENDC(head) && \
(head)->cqh_first->field.cqe_prev != CIRCLEQ_ENDC(head)) \
QUEUEDEBUG_ABORT("CIRCLEQ head forw %p %s:%d", (head), \
__FILE__, __LINE__); \
if ((head)->cqh_last != CIRCLEQ_ENDC(head) && \
(head)->cqh_last->field.cqe_next != CIRCLEQ_ENDC(head)) \
QUEUEDEBUG_ABORT("CIRCLEQ head back %p %s:%d", (head), \
__FILE__, __LINE__);
#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field) \
if ((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) { \
if ((head)->cqh_last != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm last %p %s:%d", \
(elm), __FILE__, __LINE__); \
} else { \
if ((elm)->field.cqe_next->field.cqe_prev != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm forw %p %s:%d", \
(elm), __FILE__, __LINE__); \
} \
if ((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) { \
if ((head)->cqh_first != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm first %p %s:%d", \
(elm), __FILE__, __LINE__); \
} else { \
if ((elm)->field.cqe_prev->field.cqe_next != (elm)) \
QUEUEDEBUG_ABORT("CIRCLEQ elm prev %p %s:%d", \
(elm), __FILE__, __LINE__); \
}
#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field) \
(elm)->field.cqe_next = (void *)1L; \
(elm)->field.cqe_prev = (void *)1L;
#else
#define QUEUEDEBUG_CIRCLEQ_HEAD(head, field)
#define QUEUEDEBUG_CIRCLEQ_ELM(head, elm, field)
#define QUEUEDEBUG_CIRCLEQ_POSTREMOVE(elm, field)
#endif
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = CIRCLEQ_END(head); \
(head)->cqh_last = CIRCLEQ_END(head); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (listelm), field) \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
if ((head)->cqh_last == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
(elm)->field.cqe_next = CIRCLEQ_END(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
QUEUEDEBUG_CIRCLEQ_HEAD((head), field) \
QUEUEDEBUG_CIRCLEQ_ELM((head), (elm), field) \
if ((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
QUEUEDEBUG_CIRCLEQ_POSTREMOVE((elm), field) \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->cqh_first); \
(var) != CIRCLEQ_ENDC(head); \
(var) = ((var)->field.cqe_next))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for ((var) = ((head)->cqh_last); \
(var) != CIRCLEQ_ENDC(head); \
(var) = ((var)->field.cqe_prev))
/*
* Circular queue access methods.
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
/* For comparisons */
#define CIRCLEQ_ENDC(head) (__launder_type(head))
/* For assignments */
#define CIRCLEQ_END(head) ((void *)(head))
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
(CIRCLEQ_FIRST(head) == CIRCLEQ_ENDC(head))
#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
(((elm)->field.cqe_next == CIRCLEQ_ENDC(head)) \
? ((head)->cqh_first) \
: (elm->field.cqe_next))
#define CIRCLEQ_LOOP_PREV(head, elm, field) \
(((elm)->field.cqe_prev == CIRCLEQ_ENDC(head)) \
? ((head)->cqh_last) \
: (elm->field.cqe_prev))
#endif /* !_KERNEL */
#endif /* !_SYS_QUEUE_H_ */
-22
View File
@@ -1,22 +0,0 @@
#ifndef _SYS_REDOX_H
#define _SYS_REDOX_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __redox__
ssize_t redox_fpath(int fd, void * buf, size_t count);
void * redox_physalloc(size_t size);
int redox_physfree(void * physical_address, size_t size);
#endif
#ifdef __cplusplus
} // extern "C"
#endif
#endif
-16
View File
@@ -1,16 +0,0 @@
// From musl, license MIT
#ifndef _SYS_SYSMACROS_H
#define _SYS_SYSMACROS_H
#define major(x) \
((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
#define minor(x) \
((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) ))
#define makedev(x,y) ( \
(((x)&0xfffff000ULL) << 32) | \
(((x)&0x00000fffULL) << 8) | \
(((y)&0xffffff00ULL) << 12) | \
(((y)&0x000000ffULL)) )
#endif
-13
View File
@@ -1,13 +0,0 @@
#ifndef _SYS_USER_H
#define _SYS_USER_H
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
#include <arch/x64/user.h>
#elif defined(__aarch64__)
#include <arch/aarch64/user.h>
#elif defined(__riscv) && __riscv_xlen==64
#include <arch/riscv64/user.h>
#else
#error "Unknown architecture"
#endif
#endif
-21
View File
@@ -1,21 +0,0 @@
#ifndef _SYSEXITS_H
#define _SYSEXITS_H
#define EX_OK 0
#define EX_USAGE 64
#define EX_DATAERR 65
#define EX_NOINPUT 66
#define EX_NOUSER 67
#define EX_NOHOST 68
#define EX_UNAVAILABLE 69
#define EX_SOFTWARE 70
#define EX_OSERR 71
#define EX_OSFILE 72
#define EX_CANTCREAT 73
#define EX_IOERR 74
#define EX_TEMPFAIL 75
#define EX_PROTOCOL 76
#define EX_NOPERM 77
#define EX_CONFIG 78
#endif /* _SYSEXITS_H */
-1
View File
@@ -1 +0,0 @@
#include <sys/syslog.h>
-12
View File
@@ -1,12 +0,0 @@
[package]
name = "ld_so"
version = "0.1.0"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
edition = "2024"
[lib]
name = "ld_so"
crate-type = ["staticlib"]
[lints]
workspace = true
@@ -1,263 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2025 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("=/usr/aarch64-linux-gnu/lib64"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/aarch64-linux-gnu/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000));
. = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
/* Place the build-id as close to the ELF headers as possible. This
maximises the chance the build-id will be present in core files,
which GDB can then use to locate the associated debuginfo file. */
.note.gnu.build-id : { *(.note.gnu.build-id) }
.interp : { *(.interp) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
.relr.dyn : { *(.relr.dyn) }
/* Start of the executable code region. */
.init :
{
KEEP (*(SORT_NONE(.init)))
} =0x1f2003d5
.plt : ALIGN(16) { *(.plt) *(.iplt) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(SORT(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
} =0x1f2003d5
.fini :
{
KEEP (*(SORT_NONE(.fini)))
} =0x1f2003d5
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
/* Start of the Read Only Data region. */
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.sframe : ONLY_IF_RO { *(.sframe) *(.sframe.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Various note sections. Placed here so that they are always included
in the read-only segment and not treated as orphan sections. The
current orphan handling algorithm does place note sections after R/O
data, but this is not guaranteed to always be the case. */
.note.build-id : { *(.note.build-id) }
.note.GNU-stack : { *(.note.GNU-stack) }
.note.gnu-property : { *(.note.gnu-property) }
.note.ABI-tag : { *(.note.ABI-tag) }
.note.package : { *(.note.package) }
.note.dlopen : { *(.note.dlopen) }
.note.netbsd.ident : { *(.note.netbsd.ident) }
.note.openbsd.ident : { *(.note.openbsd.ident) }
/* Start of the Read Write Data region. */
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling. */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.sframe : ONLY_IF_RW { *(.sframe) *(.sframe.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections. */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (24, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
PROVIDE (__data_start = .);
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .;
PROVIDE (edata = .);
. = ALIGN(ALIGNOF(NEXT_SECTION));
__bss_start = .;
__bss_start__ = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that in the common case of there only being one
type of .bss section, the section occupies space up to _end.
Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
_bss_end__ = .; __bss_end__ = .;
. = ALIGN(64 / 8);
/* Start of the Large Data region. */
. = SEGMENT_START("ldata-segment", .);
. = ALIGN(64 / 8);
__end__ = .;
_end = .;
PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Start of the Tiny Data region. */
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 (INFO) : { *(.comment); LINKER_VERSION; }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1. */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions. */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2. */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2. */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions. */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3. */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF 5. */
.debug_addr 0 : { *(.debug_addr) }
.debug_line_str 0 : { *(.debug_line_str) }
.debug_loclists 0 : { *(.debug_loclists) }
.debug_macro 0 : { *(.debug_macro) }
.debug_names 0 : { *(.debug_names) }
.debug_rnglists 0 : { *(.debug_rnglists) }
.debug_str_offsets 0 : { *(.debug_str_offsets) }
.debug_sup 0 : { *(.debug_sup) }
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-255
View File
@@ -1,255 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64",
"elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SEARCH_DIR("/aarch64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array need to be not discarded unlike x86_64 linker variant
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
}
}
-256
View File
@@ -1,256 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
"elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SEARCH_DIR("/i686-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib32");
SEARCH_DIR("/lib32");
SEARCH_DIR("/usr/lib32");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-256
View File
@@ -1,256 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
"elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
SEARCH_DIR("/i686-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib32");
SEARCH_DIR("/lib32");
SEARCH_DIR("/usr/lib32");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-247
View File
@@ -1,247 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv" )
OUTPUT_ARCH(riscv)
ENTRY(_start)
SEARCH_DIR("/riscv64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata :
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-259
View File
@@ -1,259 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib64");
SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.164");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/x86_64-pc-linux-gnu/lib");
SEARCH_DIR("/usr/lib64/binutils/x86_64-pc-linux-gnu/2.33.1");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata : ALIGN(4K)
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-256
View File
@@ -1,256 +0,0 @@
/* Script for -z combreloc */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
"elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
SEARCH_DIR("/x86_64-unknown-redox/lib");
SEARCH_DIR("/usr/local/lib64");
SEARCH_DIR("/lib64");
SEARCH_DIR("/usr/lib64");
SEARCH_DIR("/usr/local/lib");
SEARCH_DIR("/lib");
SEARCH_DIR("/usr/lib");
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x20000000) + SIZEOF_HEADERS;
.interp : { *(.interp) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
*(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
*(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
*(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
*(.rela.ifunc)
}
.rela.plt :
{
*(.rela.plt)
PROVIDE_HIDDEN (__rela_iplt_start = .);
*(.rela.iplt)
PROVIDE_HIDDEN (__rela_iplt_end = .);
}
. = ALIGN(CONSTANT (MAXPAGESIZE));
.init :
{
KEEP (*(SORT_NONE(.init)))
}
.plt : { *(.plt) *(.iplt) }
.plt.got : { *(.plt.got) }
.plt.sec : { *(.plt.sec) }
.text :
{
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf.em. */
*(.gnu.warning)
}
.fini :
{
KEEP (*(SORT_NONE(.fini)))
}
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
. = ALIGN(CONSTANT (MAXPAGESIZE));
/* Adjust the address for the rodata segment. We want to adjust up to
the same address within the page on the next page up. */
. = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)));
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
/* These sections are generated by the Sun/Oracle C++ compiler. */
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
/* Thread Local Storage sections */
/* .tdata : ALIGN(4K)
{
PROVIDE_HIDDEN (__tdata_start = .);
*(.tdata .tdata.* .gnu.linkonce.td.*)
}
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } */
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
/* .init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} */
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
.dynamic : { *(.dynamic) }
.got : { *(.got) *(.igot) }
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .);
.got.plt : { *(.got.plt) *(.igot.plt) }
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
_edata = .; PROVIDE (edata = .);
. = .;
__bss_start = .;
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we do not
pad the .data section. */
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
.lbss :
{
*(.dynlbss)
*(.lbss .lbss.* .gnu.linkonce.lb.*)
*(LARGE_COMMON)
}
. = ALIGN(64 / 8);
. = SEGMENT_START("ldata-segment", .);
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(64 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
/* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
/DISCARD/ : {
*(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*)
/*
* XXX: As of now, ld.so links with relibc which has the main functionality. In the next refactor,
* ld.so will be moved out of relibc. So, till that time, we have to discard any sections
* that may reference use thread local storage.
*
* .init_array also depends on TLS and is discarded as we don't need it.
*/
*(.gnu.linkonce.tb.*) *(.tcommon)
*(.init_array)
}
}
-136
View File
@@ -1,136 +0,0 @@
#![no_std]
#![feature(linkage)]
#![deny(unsafe_op_in_unsafe_fn)]
use core::arch::global_asm;
#[cfg(target_arch = "aarch64")]
global_asm!(
"
.weak _DYNAMIC
.hidden _DYNAMIC
.global _start
_start:
mov x28, sp
// align stack to 16 bytes
and sp, x28, #0xfffffffffffffff0
adr x1, _start
mov x0, x28
adrp x2, _DYNAMIC
add x2, x2, #:lo12:_DYNAMIC
// ld_so_start(stack=x0, ld_entry=x1, dynamic=x2)
bl relibc_ld_so_start
// restore original stack, clear registers, and jump to the new start function
mov sp, x28
mov x1, xzr
mov x2, xzr
mov x3, xzr
mov x4, xzr
mov x5, xzr
mov x6, xzr
mov x7, xzr
mov x8, xzr
mov x9, xzr
mov x10, xzr
mov x11, xzr
mov x12, xzr
mov x13, xzr
mov x14, xzr
mov x15, xzr
mov x16, xzr
mov x17, xzr
mov x18, xzr
mov x19, xzr
mov x20, xzr
mov x21, xzr
mov x22, xzr
mov x23, xzr
mov x24, xzr
mov x25, xzr
mov x26, xzr
mov x27, xzr
mov x28, xzr
mov x29, xzr
mov x30, xzr
br x0
udf #0
"
);
#[cfg(target_arch = "x86")]
global_asm!(
"
.globl _start
_start:
push esp
call relibc_ld_so_start
pop esp
# TODO: x86
ud2
"
);
#[cfg(target_arch = "x86_64")]
global_asm!(
"
.weak _DYNAMIC
.hidden _DYNAMIC
.globl _start
_start:
lea rsi, [rip + _start]
# Save original stack and align stack to 16 bytes
mov rbp, rsp
and rsp, 0xfffffffffffffff0
# Call ld_so_start(stack=rdi, ld_entry=rsi, dynamic=rdx)
mov rdi, rbp
lea rdx, [rip + _DYNAMIC]
call relibc_ld_so_start
# Restore original stack, clear registers, and jump to new start function
mov rsp, rbp
xor rcx, rcx
xor rdx, rdx
xor rdi, rdi
xor rsi, rsi
xor r8, r8
xor r9, r9
xor r10, r10
xor r11, r11
fninit
jmp rax
ud2
"
);
#[cfg(target_arch = "riscv64")]
global_asm!(
"
.globl _start
_start:
mv a0, sp
jal relibc_ld_so_start
unimp
"
);
#[unsafe(no_mangle)]
pub unsafe extern "C" fn main(_argc: isize, _argv: *const *const i8) -> usize {
// LD
0x1D
}
#[linkage = "weak"]
#[unsafe(no_mangle)]
extern "C" fn relibc_panic(_pi: &::core::panic::PanicInfo) -> ! {
loop {}
}
#[panic_handler]
#[linkage = "weak"]
pub unsafe fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
relibc_panic(pi)
}
+55
View File
@@ -0,0 +1,55 @@
ENTRY(kstart)
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
KERNEL_OFFSET = 0xFFFFFF0000000000;
SECTIONS {
. = KERNEL_OFFSET;
. += SIZEOF_HEADERS;
/* Force the zero page to be part of a segment by creating a
* dummy section in the zero page.
* Limine will map the segment with the lowest vaddr value at
* 0xFFFFFFFF80000000 even if the segment has a higher vaddr.
* As such without the zero page being part of a segment, the
* kernel would be loaded at an offset from the expected
* location. As the redox kernel is not currently relocatable,
* this would result in a crash. A similar issue likely exists
* with multiboot/multiboot2 and the paddr of the segment.
*/
.dummy ALIGN(8) : AT(ADDR(.dummy) - KERNEL_OFFSET) {}
. = ALIGN(4096);
.text : AT(ADDR(.text) - KERNEL_OFFSET) {
__text_start = .;
*(.text*)
. = ALIGN(4096);
__text_end = .;
}
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__rodata_start = .;
*(.rodata*)
. = ALIGN(4096);
__rodata_end = .;
}
.data : AT(ADDR(.data) - KERNEL_OFFSET) {
*(.data*)
. = ALIGN(4096);
*(.bss*)
. = ALIGN(4096);
}
__end = .;
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note*)
*(.rel.eh_frame*)
}
}
+51
View File
@@ -0,0 +1,51 @@
ENTRY(kstart)
OUTPUT_FORMAT(elf32-i386)
KERNEL_OFFSET = 0xC0000000;
SECTIONS {
. = KERNEL_OFFSET;
. += SIZEOF_HEADERS;
/* Force the zero page to be part of a segment by creating a
* dummy section in the zero page.
* Limine will map the segment with the lowest vaddr value at
* 0xFFFFFFFF80000000 even if the segment has a higher vaddr.
* As such without the zero page being part of a segment, the
* kernel would be loaded at an offset from the expected
* location. As the redox kernel is not currently relocatable,
* this would result in a crash. A similar issue likely exists
* with multiboot/multiboot2 and the paddr of the segment.
*/
.dummy : AT(ADDR(.dummy) - KERNEL_OFFSET) {}
.text ALIGN(4K) : AT(ADDR(.text) - KERNEL_OFFSET) {
__text_start = .;
*(.text*)
}
.rodata ALIGN(4K) : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__text_end = .;
__rodata_start = .;
*(.rodata*)
}
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) {
__rodata_end = .;
*(.data*)
. = ALIGN(4K);
*(.bss*)
. = ALIGN(4K);
}
__end = .;
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note*)
*(.rel.eh_frame*)
}
}
+61
View File
@@ -0,0 +1,61 @@
ENTRY(kstart)
OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv" )
KERNEL_OFFSET = 0xFFFFFFFF80000000;
SECTIONS {
. = KERNEL_OFFSET;
. += SIZEOF_HEADERS;
/* Force the zero page to be part of a segment by creating a
* dummy section in the zero page.
* Linker will map the segment with the lowest vaddr value at
* 0xFFFFFFFF80000000 even if the segment has a higher vaddr.
* As such without the zero page being part of a segment, the
* kernel would be loaded at an offset from the expected
* location. As the redox kernel is not currently relocatable,
* this would result in a crash. A similar issue likely exists
* with multiboot/multiboot2 and the paddr of the segment.
*/
.dummy ALIGN(8) : AT(ADDR(.dummy) - KERNEL_OFFSET) {}
. = ALIGN(4096);
.text : AT(ADDR(.text) - KERNEL_OFFSET) {
__text_start = .;
*(.early_init.text*)
. = ALIGN(4096);
*(.text*)
. = ALIGN(4096);
__text_end = .;
}
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__rodata_start = .;
*(.rodata*)
. = ALIGN(4096);
__rodata_end = .;
}
.data : AT(ADDR(.data) - KERNEL_OFFSET) {
*(.data*)
*(.sdata*)
. = ALIGN(4096);
*(.got*)
. = ALIGN(4096);
*(.bss*)
*(.sbss*)
. = ALIGN(4096);
}
__end = .;
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note*)
*(.rel.eh_frame*)
}
}
+60
View File
@@ -0,0 +1,60 @@
ENTRY(kstart)
OUTPUT_FORMAT(elf64-x86-64)
KERNEL_OFFSET = 0xFFFFFFFF80000000;
SECTIONS {
. = KERNEL_OFFSET;
. += SIZEOF_HEADERS;
/* Force the zero page to be part of a segment by creating a
* dummy section in the zero page.
* Limine will map the segment with the lowest vaddr value at
* 0xFFFFFFFF80000000 even if the segment has a higher vaddr.
* As such without the zero page being part of a segment, the
* kernel would be loaded at an offset from the expected
* location. As the redox kernel is not currently relocatable,
* this would result in a crash. A similar issue likely exists
* with multiboot/multiboot2 and the paddr of the segment.
*/
.dummy : AT(ADDR(.dummy) - KERNEL_OFFSET) {}
.text ALIGN(4K) : AT(ADDR(.text) - KERNEL_OFFSET) {
__text_start = .;
*(.text*)
}
.rodata ALIGN(4K) : AT(ADDR(.rodata) - KERNEL_OFFSET) {
__text_end = .;
__rodata_start = .;
*(.rodata*)
__altcode_start = .;
KEEP(*(.altcode*))
__altcode_end = .;
. = ALIGN(8);
__altrelocs_start = .;
KEEP(*(.altrelocs*))
__altrelocs_end = .;
__altfeatures_start = .;
KEEP(*(.altfeatures*))
__altfeatures_end = .;
}
.data ALIGN(4K) : AT(ADDR(.data) - KERNEL_OFFSET) {
__rodata_end = .;
*(.data*)
. = ALIGN(4K);
*(.bss*)
}
__end = .;
/DISCARD/ : {
*(.comment*)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note*)
*(.rel.eh_frame*)
}
}
Submodule openlibm deleted from e2da0dafd3
-13
View File
@@ -1,13 +0,0 @@
[package]
name = "redox-ioctl"
authors = ["bjorn3 <bjorn3_gh@protonmail.com>"]
version = "0.1.0"
edition = "2024"
license = "MIT"
description = "Ioctl definitions and (de)serialization for Redox"
[dependencies]
drm-sys = "0.8.0"
redox_syscall = { path = "../../syscall" }
[features]
-319
View File
@@ -1,319 +0,0 @@
use alloc::vec::Vec;
use core::{
cmp,
ffi::{c_char, c_int, c_uint},
iter, mem, slice,
};
use drm_sys::drm_clip_rect;
pub use drm_sys::{
__kernel_size_t, DRM_PROP_NAME_LEN, drm_get_cap, drm_mode_card_res,
drm_mode_connector_set_property, drm_mode_create_dumb, drm_mode_crtc,
drm_mode_crtc_page_flip_target, drm_mode_cursor, drm_mode_cursor2, drm_mode_destroy_dumb,
drm_mode_fb_cmd, drm_mode_fb_cmd2, drm_mode_fb_dirty_cmd, drm_mode_get_blob,
drm_mode_get_connector, drm_mode_get_encoder, drm_mode_get_plane, drm_mode_get_plane_res,
drm_mode_get_property, drm_mode_map_dumb, drm_mode_modeinfo, drm_mode_obj_get_properties,
drm_mode_property_enum, drm_mode_set_plane, drm_set_client_cap, drm_version,
};
pub const VERSION: u64 = 0;
define_ioctl_data! {
struct drm_version, DrmVersion {
version_major: c_int,
version_minor: c_int,
version_patchlevel: c_int,
name_len: __kernel_size_t,
name: *mut c_char [array<c_char, name_len>],
date_len: __kernel_size_t,
date: *mut c_char [array<c_char, date_len>],
desc_len: __kernel_size_t,
desc: *mut c_char [array<c_char, desc_len>],
}
}
pub const GET_CAP: u64 = 0x0C;
pub use drm_sys::DRM_CAP_DUMB_BUFFER;
define_ioctl_data! {
struct drm_get_cap, DrmGetCap {
capability: u64,
value: u64,
}
}
pub const SET_CLIENT_CAP: u64 = 0x0D;
pub use drm_sys::DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT;
define_ioctl_data! {
struct drm_set_client_cap, DrmSetClientCap {
capability: u64,
value: u64,
}
}
pub const MODE_CARD_RES: u64 = 0xA0;
define_ioctl_data! {
struct drm_mode_card_res, DrmModeCardRes {
fb_id_ptr: u64 [array<u32, count_fbs>],
crtc_id_ptr: u64 [array<u32, count_crtcs>],
connector_id_ptr: u64 [array<u32, count_connectors>],
encoder_id_ptr: u64 [array<u32, count_encoders>],
count_fbs: u32,
count_crtcs: u32,
count_connectors: u32,
count_encoders: u32,
min_width: u32,
max_width: u32,
min_height: u32,
max_height: u32,
}
}
pub const MODE_GET_CRTC: u64 = 0xA1;
pub const MODE_SET_CRTC: u64 = 0xA2;
define_ioctl_data! {
struct drm_mode_crtc, DrmModeCrtc {
set_connectors_ptr: u64 [array<u32, count_connectors>],
count_connectors: u32,
crtc_id: u32,
fb_id: u32,
x: u32,
y: u32,
gamma_size: u32,
mode_valid: u32,
mode: drm_mode_modeinfo,
}
}
pub const MODE_CURSOR: u64 = 0xA3;
define_ioctl_data! {
struct drm_mode_cursor, DrmModeCursor {
flags: u32,
crtc_id: u32,
x: i32,
y:i32,
width:u32,
height:u32,
handle:u32,
}
}
pub const MODE_GET_ENCODER: u64 = 0xA6;
define_ioctl_data! {
struct drm_mode_get_encoder, DrmModeGetEncoder {
encoder_id: u32,
encoder_type: u32,
crtc_id: u32,
possible_crtcs: u32,
possible_clones: u32,
}
}
pub const MODE_GET_CONNECTOR: u64 = 0xA7;
define_ioctl_data! {
struct drm_mode_get_connector, DrmModeGetConnector {
encoders_ptr: u64 [array<u32, count_encoders>],
modes_ptr: u64 [array<drm_mode_modeinfo, count_modes>],
props_ptr: u64 [array<u32, count_props>],
prop_values_ptr: u64 [array<u64, count_props>],
count_modes: u32,
count_props: u32,
count_encoders: u32,
encoder_id: u32,
connector_id: u32,
connector_type: u32,
connector_type_id: u32,
connection: u32,
mm_width: u32,
mm_height: u32,
subpixel: u32,
pad: u32,
}
}
pub const MODE_GET_PROPERTY: u64 = 0xAA;
define_ioctl_data! {
struct drm_mode_get_property, DrmModeGetProperty {
values_ptr: u64 [array<u64, count_values>],
enum_blob_ptr: u64 [array<drm_mode_property_enum, count_enum_blobs>],
prop_id: u32,
flags: u32,
name: [c_char; DRM_PROP_NAME_LEN as usize],
count_values: u32,
count_enum_blobs: u32,
}
}
pub const MODE_SET_PROPERTY: u64 = 0xAB;
define_ioctl_data! {
struct drm_mode_connector_set_property, DrmModeConnectorSetProperty {
value: u64,
prop_id: u32,
connector_id: u32,
}
}
pub const MODE_GET_PROP_BLOB: u64 = 0xAC;
define_ioctl_data! {
struct drm_mode_get_blob, DrmModeGetBlob {
blob_id: u32,
length: u32,
data: u64 [array<u8, length>],
}
}
pub const MODE_GET_FB: u64 = 0xAD;
pub const MODE_ADD_FB: u64 = 0xAE;
define_ioctl_data! {
struct drm_mode_fb_cmd, DrmModeFbCmd {
fb_id: u32,
width: u32,
height: u32,
pitch: u32,
bpp: u32,
depth: u32,
handle: u32,
}
}
pub const MODE_RM_FB: u64 = 0xAF;
define_ioctl_data! {
struct standin_for_uint, StandinForUint {
inner: c_uint,
}
}
#[repr(transparent)]
#[allow(non_camel_case_types)]
pub struct standin_for_uint {
pub inner: c_uint,
}
pub const MODE_PAGE_FLIP: u64 = 0xB0;
define_ioctl_data! {
struct drm_mode_crtc_page_flip_target, DrmModeCrtcPageFlipTarget {
crtc_id: u32,
fb_id: u32,
flags: u32,
sequence: u32,
user_data: u64,
}
}
pub const MODE_DIRTYFB: u64 = 0xB1;
define_ioctl_data! {
struct drm_mode_fb_dirty_cmd, DrmModeFbDirtyCmd {
fb_id: u32,
flags: u32,
color: u32,
num_clips: u32,
clips_ptr: u64 [array<drm_clip_rect, num_clips>],
}
}
pub const MODE_CREATE_DUMB: u64 = 0xB2;
define_ioctl_data! {
struct drm_mode_create_dumb, DrmModeCreateDumb {
height: u32,
width: u32,
bpp: u32,
flags: u32,
handle: u32,
pitch: u32,
size: u64,
}
}
pub const MODE_MAP_DUMB: u64 = 0xB3;
define_ioctl_data! {
struct drm_mode_map_dumb, DrmModeMapDumb {
handle: u32,
pad: u32,
offset: u64,
}
}
pub const MODE_DESTROY_DUMB: u64 = 0xB4;
define_ioctl_data! {
struct drm_mode_destroy_dumb, DrmModeDestroyDumb {
handle: u32,
}
}
pub const MODE_GET_PLANE_RES: u64 = 0xB5;
define_ioctl_data! {
struct drm_mode_get_plane_res, DrmModeGetPlaneRes {
plane_id_ptr: u64 [array<u32, count_planes>],
count_planes: u32,
}
}
pub const MODE_GET_PLANE: u64 = 0xB6;
define_ioctl_data! {
struct drm_mode_get_plane, DrmModeGetPlane {
plane_id: u32,
crtc_id: u32,
fb_id: u32,
possible_crtcs: u32,
gamma_size: u32,
count_format_types: u32,
format_type_ptr: u64 [array<u32, count_format_types>],
}
}
pub const MODE_SET_PLANE: u64 = 0xB7;
define_ioctl_data! {
struct drm_mode_set_plane, DrmModeSetPlane {
plane_id: u32,
crtc_id: u32,
fb_id: u32,
flags: u32,
crtc_x: i32,
crtc_y: i32,
crtc_w: u32,
crtc_h: u32,
src_x: u32,
src_y: u32,
src_h: u32,
src_w: u32,
}
}
pub const MODE_OBJ_GET_PROPERTIES: u64 = 0xB9;
define_ioctl_data! {
struct drm_mode_obj_get_properties, DrmModeObjGetProperties {
props_ptr: u64 [array<u32, count_props>],
prop_values_ptr: u64 [array<u64, count_props>],
count_props: u32,
obj_id: u32,
obj_type: u32,
}
}
pub const MODE_CURSOR2: u64 = 0xBB;
define_ioctl_data! {
struct drm_mode_cursor2, DrmModeCursor2 {
flags: u32,
crtc_id: u32,
x: i32,
y: i32,
width: u32,
height: u32,
handle: u32,
hot_x: i32,
hot_y: i32,
}
}
pub const MODE_GET_FB2: u64 = 0xCE;
define_ioctl_data! {
struct drm_mode_fb_cmd2, DrmModeFbCmd2 {
fb_id: u32,
width: u32,
height: u32,
pixel_format: u32,
flags: u32,
handles: [u32; 4],
pitches: [u32; 4],
offsets: [u32; 4],
modifier: [u64; 4],
}
}
-169
View File
@@ -1,169 +0,0 @@
use alloc::vec::Vec;
pub trait IoctlData {
unsafe fn write(&self) -> Vec<u8>;
unsafe fn read_from(&mut self, buf: &[u8]);
}
macro_rules! define_ioctl_data {
(struct $ioctl_ty:ident, $mem_ty:ident {
$($rest:tt)*
}) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } => (), (), ()
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {
$field:ident: $ty:ty,
$($rest:tt)*
} =>
($($ioctl_fields:tt)*),
($($counted_fields:tt)*),
($($noncounted_fields:tt)*)
) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } =>
($($ioctl_fields)* $field: $ty,),
($($counted_fields)*),
($($noncounted_fields)* $field: $ty,)
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {
$field:ident: $ty:ty [array<$el:ty, $counted_by:ident>],
$($rest:tt)*
} =>
($($ioctl_fields:tt)*),
($($counted_fields:tt)*),
($($noncounted_fields:tt)*)
) => {
define_ioctl_data!(
struct $ioctl_ty, $mem_ty { $($rest)* } =>
($($ioctl_fields)* $field: $ty,),
($($counted_fields)* $field: $ty [array<$el, $counted_by>],),
($($noncounted_fields)*)
);
};
(struct $ioctl_ty:ident, $mem_ty:ident {} =>
($($ioctl_field:ident: $ioctl_field_ty:ty,)*),
($($counted_field:ident: $counted_ty:ty [array<$el:ty, $counted_by:ident>],)*),
($($noncounted_field:ident: $noncounted_ty:ty,)*)
) => {
// FIXME check ioctl_ty doesn't have padding
const _: $ioctl_ty = $ioctl_ty {
$($ioctl_field: unsafe { mem::zeroed::<$ioctl_field_ty>() },)*
};
#[repr(C)]
pub struct ${concat(__, $mem_ty, Noncounted)} {
$($noncounted_field: $noncounted_ty,)*
}
pub struct $mem_ty<'a> {
noncounted_fields: &'a mut ${concat(__, $mem_ty, Noncounted)},
$($counted_field: &'a mut [$el],)*
}
impl $crate::ioctl_data::IoctlData for $ioctl_ty {
unsafe fn write(&self) -> Vec<u8> {
let noncounted_fields = ${concat(__, $mem_ty, Noncounted)} {
$($noncounted_field: self.$noncounted_field,)*
};
// FIXME use Vec::with_capacity
let mut data = Vec::<u8>::new();
data.extend_from_slice(&unsafe {
mem::transmute::<
${concat(__, $mem_ty, Noncounted)},
[u8; size_of::<${concat(__, $mem_ty, Noncounted)}>()],
>(noncounted_fields)
});
$(
let size = self.$counted_by as usize * size_of::<$el>();
if self.$counted_field as usize != 0 {
let $counted_field = unsafe {
slice::from_raw_parts(self.$counted_field as *const u8, size)
};
data.extend_from_slice(&$counted_field);
} else {
data.extend(iter::repeat(0u8).take(size));
};
)*
data
}
unsafe fn read_from(&mut self, mut buf: &[u8]) {
// FIXME be robust against malicious scheme implementations by returning an error
// when the buf is the wrong size
let noncounted_fields = buf.split_off(..size_of::<${concat(__, $mem_ty, Noncounted)}>()).unwrap();
$(
let size = self.$counted_by as usize * size_of::<$el>();
let $counted_field = buf.split_off(..size).unwrap();
if self.$counted_field as usize != 0 {
unsafe {
slice::from_raw_parts_mut(self.$counted_field as *mut u8, size).copy_from_slice($counted_field);
}
}
)*
assert!(buf.is_empty());
let noncounted_fields = unsafe { &*(noncounted_fields as *const _ as *const ${concat(__, $mem_ty, Noncounted)}) };
$(self.$noncounted_field = noncounted_fields.$noncounted_field;)*
}
}
impl<'a> $mem_ty<'a> {
pub fn with(
mut buf: &'a mut [u8],
f: impl FnOnce($mem_ty<'a>) -> syscall::Result<usize>,
) -> syscall::Result<usize> {
let noncounted_fields = buf.split_off_mut(..size_of::<${concat(__, $mem_ty, Noncounted)}>())
.ok_or(syscall::Error::new(syscall::EINVAL))?;
let noncounted_fields = unsafe { &mut *(noncounted_fields as *mut _ as *mut ${concat(__, $mem_ty, Noncounted)}) };
$(
let $counted_field = buf.split_off_mut(..noncounted_fields.$counted_by as usize * size_of::<$el>())
.ok_or(syscall::Error::new(syscall::EINVAL))?;
let $counted_field = unsafe {
slice::from_raw_parts_mut($counted_field as *mut _ as *mut $el, noncounted_fields.$counted_by as usize)
};
)*
if !buf.is_empty() {
return Err(syscall::Error::new(syscall::EINVAL));
}
Ok( f($mem_ty {
noncounted_fields,
$($counted_field,)*
})?)
}
$(
pub fn $noncounted_field(&self) -> $noncounted_ty {
self.noncounted_fields.$noncounted_field
}
/// Should not be called for fields used as array length
pub fn ${concat(set_, $noncounted_field)}(&mut self, data: $noncounted_ty) {
self.noncounted_fields.$noncounted_field = data;
}
)*
$(
pub fn $counted_field(&self) -> &[$el] {
self.$counted_field
}
pub fn ${concat(set_, $counted_field)}(&mut self, data: &[$el]) {
let copied_count = cmp::min(data.len(), self.$counted_field.len());
self.$counted_field[..copied_count].copy_from_slice(&data[..copied_count]);
self.noncounted_fields.$counted_by = data.len() as _;
}
)*
}
};
}
-11
View File
@@ -1,11 +0,0 @@
#![feature(macro_metavar_expr_concat)]
#![deny(unsafe_op_in_unsafe_fn)]
#![no_std]
extern crate alloc;
#[macro_use]
mod ioctl_data;
pub use ioctl_data::IoctlData;
pub mod drm;
-27
View File
@@ -1,27 +0,0 @@
[package]
name = "redox-rt"
authors = ["4lDO2 <4lDO2@protonmail.com>"]
version = "0.1.0"
edition = "2024"
license = "MIT"
description = "Libc-independent runtime for Redox"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bitflags.workspace = true
goblin = { version = "0.10", default-features = false, features = ["elf32", "elf64", "endian_fd"] }
plain.workspace = true
ioslice.workspace = true
redox_syscall.workspace = true
redox-path.workspace = true
redox_protocols.workspace = true
generic-rt = { path = "../generic-rt" }
[features]
proc = []
default = ["proc"]
[lints]
workspace = true
-485
View File
@@ -1,485 +0,0 @@
use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull};
use syscall::{data::*, error::*};
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PosixStackt, RtSigarea, SigStack, inner_c},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 47;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub altstack_top: usize,
pub altstack_bottom: usize,
pub tmp_x1_x2: [usize; 2],
pub tmp_x3_x4: [usize; 2],
pub tmp_x5_x6: [usize; 2],
pub tmp_x7_x8: [usize; 2],
pub tmp_sp: usize,
pub onstack: u64,
pub disable_signals_depth: u64,
pub pctl: usize, // TODO: remove
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub x30: usize,
pub x29: usize,
pub x28: usize,
pub x27: usize,
pub x26: usize,
pub x25: usize,
pub x24: usize,
pub x23: usize,
pub x22: usize,
pub x21: usize,
pub x20: usize,
pub x19: usize,
pub x18: usize,
pub x17: usize,
pub x16: usize,
pub x15: usize,
pub x14: usize,
pub x13: usize,
pub x12: usize,
pub x11: usize,
pub x10: usize,
pub x9: usize,
pub x8: usize,
pub x7: usize,
pub x6: usize,
pub x5: usize,
pub x4: usize,
pub x3: usize,
pub x2: usize,
pub x1: usize,
pub sp: usize,
pub nzcv: usize, // user-accessible PSTATE bits
pub pc: usize,
pub x0: usize,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.tpidr_el0 = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "C" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
unsafe extern "C" fn child_hook(scratchpad: &ForkScratchpad) {
//let _ = syscall::write(1, alloc::format!("CUR{cur_filetable_fd}PROC{new_proc_fd}THR{new_thr_fd}\n").as_bytes());
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
stp x29, x30, [sp, #-16]!
stp x27, x28, [sp, #-16]!
stp x25, x26, [sp, #-16]!
stp x23, x24, [sp, #-16]!
stp x21, x22, [sp, #-16]!
stp x19, x20, [sp, #-16]!
//TODO: store floating point regs
// x0: &ForkArgs
mov x1, sp
bl {fork_impl}
ldp x19, x20, [sp], #16
ldp x21, x22, [sp], #16
ldp x23, x24, [sp], #16
ldp x25, x26, [sp], #16
ldp x27, x28, [sp], #16
ldp x29, x30, [sp], #16
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
# scratchpad is in x1, move to x0 for child_hook
mov x0, x1
bl {child_hook}
//TODO: load floating point regs
mov x0, xzr
ldp x19, x20, [sp], #16
ldp x21, x22, [sp], #16
ldp x23, x24, [sp], #16
ldp x25, x26, [sp], #16
ldp x27, x28, [sp], #16
ldp x29, x30, [sp], #16
ret
"] <= [child_hook = sym child_hook]);
// https://devblogs.microsoft.com/oldnewthing/20220811-00/?p=106963
asmfunction!(__relibc_internal_sigentry: ["
// Clear any active reservation.
clrex
// The old pc and x0 are saved in the sigcontrol struct.
mrs x0, tpidr_el0 // ABI ptr
ldr x0, [x0] // TCB ptr
// Save x1-x6 and sp
stp x1, x2, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
stp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
stp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
stp x7, x8, [x0, #{tcb_sa_off} + {sa_tmp_x7_x8}]
mov x1, sp
str x1, [x0, #{tcb_sa_off} + {sa_tmp_sp}]
ldr x6, [x0, #{tcb_sa_off} + {sa_pctl}]
1:
// Load x1 with the thread's bits
add x5, x0, #{tcb_sc_off} + {sc_word}
ldaxr x1, [x5]
// First check if there are standard thread signals,
and x4, x1, x1, lsr #32 // x4 := x1 & (x1 >> 32)
cbnz x4, 3f // jump if x4 != 0
clrex
// and if not, load process pending bitset.
add x5, x6, #{pctl_pending}
ldaxr x2, [x5]
// Check if there are standard proc signals:
lsr x3, x1, #32 // mask
and w3, w2, w3 // pending unblocked proc
cbz w3, 4f // skip 'fetch_andn' step if zero
// If there was one, find which one, and try clearing the bit (last value in x3, addr in x6)
// this picks the MSB rather than the LSB, unlike x86. POSIX does not require any specific
// ordering though.
clz w3, w3
mov w4, #31
sub w3, w4, w3
// x3 now contains the sig_idx
mov x4, #1
lsl x4, x4, x3 // bit to remove
sub x4, x2, x4 // bit was certainly set, so sub is allowed
// x4 is now the new mask to be set
add x5, x6, #{pctl_pending}
add x2, x5, #{pctl_sender_infos}
add x2, x2, w3, uxtb 3
ldar x2, [x2]
// Try clearing the bit, retrying on failure.
stxr w1, x4, [x5] // try setting pending set to x4, set w1 := 0 on success
cbnz w1, 1b // retry everything if this fails
mov x1, x3
b 2f
4:
// Check for realtime signals, thread/proc.
clrex
// Load the pending set again. TODO: optimize this?
// Process pending - realtime
add x1, x6, #{pctl_pending}
ldaxr x2, [x1]
lsr x2, x2, #32
// Thread pending - realtime and allowset
add x5, x0, #{tcb_sc_off} + {sc_word} + 8
ldar x1, [x5]
orr x2, x1, x2 // combine proc and thread pending
and x2, x2, x2, lsr #32 // AND pending with allowset
cbz x2, 7f // spurious signal if realtime is clear
rbit x2, x2
clz x2, x2
// x2 now contains sig_idx - 32
// If realtime signal was directed at thread, handle it as an idempotent signal.
lsr x3, x1, x2 // x3 := x1 >> x2; x1 is thread pending
tbnz x3, #0, 5f // jump if bit is nonzero
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base | (flags << 8))
// x8 x0 x1 x2 x3 x4
mov x5, x0 // save TCB pointer
mov x6, x2
ldr x8, ={SYS_CALL}
adrp x0, {proc_fd}
ldr x0, [x0, #:lo12:{proc_fd}]
add x1, x5, #{tcb_sa_off} + {sa_tmp_rt_inf}
str x6, [x1]
mov x2, #{RTINF_SIZE}
adrp x4, {proc_call}
add x4, x4, :lo12:{proc_call}
mov x3, #1
svc 0
mov x3, x0
mov x0, x5 // restore TCB pointer
mov x2, x6 // restore signal number - 32
add x1, x2, #32 // signal number
cbnz x3, 1b
b 2f
5:
// A realtime signal was sent to this thread, try clearing its bit.
// x3 contains last rt signal word, x2 contains rt_idx
clrex
// Calculate the absolute sig_idx
add x1, x3, 32
// Load si_pid and si_uid
add x2, x0, #{tcb_sc_off} + {sc_sender_infos}
add x2, x2, w1, uxtb #3
ldar x2, [x2]
add x3, x0, #{tcb_sc_off} + {sc_word} + 8
ldxr x2, [x3]
// Calculate new mask
mov x4, #1
lsl x4, x4, x2
sub x2, x2, x4 // remove bit
stxr w5, x2, [x3]
cbnz w5, 1b
str x2, [x0, #{tcb_sa_off} + {sa_tmp_id_inf}]
b 2f
3:
// A standard signal was sent to this thread, try clearing its bit.
clz w1, w1
mov x2, #31
sub x1, x2, x1
// Load si_pid and si_uid
add x2, x0, #{tcb_sc_off} + {sc_sender_infos}
add x2, x2, w1, uxtb #3
ldar x2, [x2]
// Clear bit from mask
mov x3, #1
lsl x3, x3, x1
sub x4, x4, x3
// Try updating the mask
stxr w3, x1, [x5]
cbnz w3, 1b
str x2, [x0, #{tcb_sa_off} + {sa_tmp_id_inf}]
2:
ldr x3, [x0, #{tcb_sa_off} + {sa_pctl}]
add x3, x3, {pctl_actions}
add x2, x3, w1, uxtb #4 // actions_base + sig_idx * sizeof Action
// TODO: NOT ATOMIC (tearing allowed between regs)!
ldxp x2, x3, [x2]
clrex
// Calculate new sp wrt redzone and alignment
mov x4, sp
sub x4, x4, {REDZONE_SIZE}
and x4, x4, -{STACK_ALIGN}
mov sp, x4
// skip sigaltstack step if SA_ONSTACK is clear
// tbz x2, #{SA_ONSTACK_BIT}, 2f
ldr x2, [x0, #{tcb_sc_off} + {sc_saved_pc}]
ldr x3, [x0, #{tcb_sc_off} + {sc_saved_x0}]
stp x2, x3, [sp, #-16]!
ldr x2, [x0, #{tcb_sa_off} + {sa_tmp_sp}]
mrs x3, nzcv
stp x2, x3, [sp, #-16]!
ldp x2, x3, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
stp x2, x3, [sp, #-16]!
ldp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
stp x4, x3, [sp, #-16]!
ldp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
stp x6, x5, [sp, #-16]!
ldp x7, x8, [x0, #{tcb_sa_off} + {sa_tmp_x7_x8}]
stp x8, x7, [sp, #-16]!
stp x10, x9, [sp, #-16]!
stp x12, x11, [sp, #-16]!
stp x14, x13, [sp, #-16]!
stp x16, x15, [sp, #-16]!
stp x18, x17, [sp, #-16]!
stp x20, x19, [sp, #-16]!
stp x22, x21, [sp, #-16]!
stp x24, x23, [sp, #-16]!
stp x26, x25, [sp, #-16]!
stp x28, x27, [sp, #-16]!
stp x30, x29, [sp, #-16]!
str w1, [sp, #-4]
sub sp, sp, #64
mov x0, sp
bl {inner}
add sp, sp, #64
ldp x30, x29, [sp], #16
ldp x28, x27, [sp], #16
ldp x26, x25, [sp], #16
ldp x24, x23, [sp], #16
ldp x22, x21, [sp], #16
ldp x20, x19, [sp], #16
ldp x18, x17, [sp], #16
ldp x16, x15, [sp], #16
ldp x14, x13, [sp], #16
ldp x12, x11, [sp], #16
ldp x10, x9, [sp], #16
ldp x8, x7, [sp], #16
ldp x6, x5, [sp], #16
ldp x4, x3, [sp], #16
ldp x2, x1, [sp], #16
ldr x0, [sp, #8]
msr nzcv, x0
8:
// x18 is reserved by ABI as 'platform register', so clobbering it should be safe.
mov x18, sp
ldr x0, [x18]
mov sp, x0
ldp x18, x0, [x18, #16]
br x18
7:
// Spurious signal, i.e. all bitsets were 0 at the time they were checked
clrex
ldr x1, [x0, #{tcb_sc_off} + {sc_flags}]
and x1, x1, ~1
str x1, [x0, #{tcb_sc_off} + {sc_flags}]
ldp x1, x2, [x0, #{tcb_sa_off} + {sa_tmp_x1_x2}]
ldp x3, x4, [x0, #{tcb_sa_off} + {sa_tmp_x3_x4}]
ldp x5, x6, [x0, #{tcb_sa_off} + {sa_tmp_x5_x6}]
ldr x18, [x0, #{tcb_sc_off} + {sc_saved_pc}]
ldr x0, [x0, #{tcb_sc_off} + {sc_saved_x0}]
br x18
"] <= [
pctl_pending = const (offset_of!(SigProcControl, pending)),
pctl_actions = const (offset_of!(SigProcControl, actions)),
pctl_sender_infos = const (offset_of!(SigProcControl, sender_infos)),
tcb_sc_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control)),
tcb_sa_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch)),
sa_tmp_x1_x2 = const offset_of!(SigArea, tmp_x1_x2),
sa_tmp_x3_x4 = const offset_of!(SigArea, tmp_x3_x4),
sa_tmp_x5_x6 = const offset_of!(SigArea, tmp_x5_x6),
sa_tmp_x7_x8 = const offset_of!(SigArea, tmp_x7_x8),
sa_tmp_sp = const offset_of!(SigArea, tmp_sp),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_pctl = const offset_of!(SigArea, pctl),
sc_saved_pc = const offset_of!(Sigcontrol, saved_ip),
sc_saved_x0 = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_word = const offset_of!(Sigcontrol, word),
sc_flags = const offset_of!(Sigcontrol, control_flags),
proc_fd = sym PROC_FD,
inner = sym inner_c,
proc_call = sym PROC_CALL,
SA_ONSTACK_BIT = const 58, // (1 << 58) >> 32 = 0x0400_0000
SYS_CALL = const syscall::SYS_CALL,
STACK_ALIGN = const 16,
REDZONE_SIZE = const 128,
RTINF_SIZE = const size_of::<RtSigInfo>(),
]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
# Load registers
ldp x8, x0, [sp], #16
ldp x1, x2, [sp], #16
ldp x3, x4, [sp], #16
# Call entry point
blr x8
ret
"] <= []);
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, sp", out(reg) sp);
}
sp
}
pub unsafe fn manually_enter_trampoline() {
let ctl = unsafe { &Tcb::current().unwrap().os_specific.control };
ctl.saved_archdep_reg.set(0);
let ip_location = &ctl.saved_ip as *const _ as usize;
unsafe {
core::arch::asm!("
bl 2f
b 3f
2:
str lr, [x0]
b __relibc_internal_sigentry
3:
",
inout("x0") ip_location => _, out("lr") _);
}
}
pub unsafe fn arch_pre(stack: &mut SigStack, os: &mut SigArea) -> PosixStackt {
PosixStackt {
sp: core::ptr::null_mut(), // TODO
size: 0, // TODO
flags: 0, // TODO
}
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_pc = core::mem::replace(&mut stack.regs.pc, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_pc);
control.saved_archdep_reg.set(stack.regs.x0);
}
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
-411
View File
@@ -1,411 +0,0 @@
use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use syscall::*;
use crate::{
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, inner_fastcall},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 31;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub altstack_top: usize,
pub altstack_bottom: usize,
pub tmp_eip: usize,
pub tmp_esp: usize,
pub tmp_eax: usize,
pub tmp_ebx: usize,
pub tmp_ecx: usize,
pub tmp_edx: usize,
pub tmp_edi: usize,
pub tmp_esi: usize,
pub tmp_rt_inf: RtSigInfo,
pub tmp_signo: usize,
pub tmp_id_inf: u64,
pub tmp_mm0: u64,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[derive(Debug, Default)]
#[repr(C, align(16))]
pub struct ArchIntRegs {
pub fxsave: [u16; 29],
// ensure fxsave region is 16 byte aligned
pub _pad: [usize; 2], // fxsave "available" +0
pub ebp: usize, // fxsave "available" +8
pub esi: usize, // avail +12
pub edi: usize, // avail +16
pub ebx: usize, // avail +20
pub eax: usize, // avail +24
pub ecx: usize, // avail +28
pub edx: usize, // avail +32
pub eflags: usize, // avail +36
pub eip: usize, // avail +40
pub esp: usize, // avail +44
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.fsbase = 0;
env.gsbase = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "fastcall" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
// TODO: duplicate code with x86_64
unsafe extern "cdecl" fn child_hook(scratchpad: ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
mov ecx, [esp+4]
push ebp
mov ebp, esp
// Push preserved registers
push ebx
push edi
push esi
push ebp
sub esp, 32
//TODO stmxcsr [esp+16]
fnstcw [esp+24]
mov edx, esp
call {fork_impl}
jmp 2f
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
// Arguments already on the stack
call {child_hook}
//TODO ldmxcsr [esp+16]
fldcw [esp+24]
xor eax, eax
.p2align 4
2:
add esp, 32
// Pop preserved registers
pop ebp
pop esi
pop edi
pop ebx
pop ebp
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_sigentry: ["
// Save some registers
mov gs:[{tcb_sa_off} + {sa_tmp_esp}], esp
mov gs:[{tcb_sa_off} + {sa_tmp_eax}], eax
mov gs:[{tcb_sa_off} + {sa_tmp_edx}], edx
mov gs:[{tcb_sa_off} + {sa_tmp_ecx}], ecx
mov gs:[{tcb_sa_off} + {sa_tmp_ebx}], ebx
mov gs:[{tcb_sa_off} + {sa_tmp_edi}], edi
mov gs:[{tcb_sa_off} + {sa_tmp_esi}], esi
1:
// Read standard signal word - first for this thread
mov edx, gs:[{tcb_sc_off} + {sc_word} + 4]
mov eax, gs:[{tcb_sc_off} + {sc_word}]
and eax, edx
bsf eax, eax
jnz 9f
// Read standard signal word - for the process
lea ecx, [{pctl}]
mov eax, [ecx + {pctl_pending}]
and eax, edx
bsf eax, eax
jz 3f
// Read si_pid and si_uid, atomically.
movq gs:[{tcb_sa_off} + {sa_tmp_mm0}], mm0
movq mm0, [ecx + {pctl_sender_infos} + eax * 8]
movq gs:[{tcb_sa_off} + {sa_tmp_id_inf}], mm0
movq mm0, gs:[{tcb_sa_off} + {sa_tmp_mm0}]
// Try clearing the pending bit, otherwise retry if another thread did that first
lock btr [ecx + {pctl_pending}], eax
jnc 1b
jmp 2f
3:
// Read realtime thread and process signal word together
mov edx, [ecx + {pctl_pending} + 4]
mov eax, gs:[{tcb_sc_off} + {sc_word} + 8]
or eax, edx
and eax, gs:[{tcb_sc_off} + {sc_word} + 12]
bsf eax, eax
jz 7f // spurious signal
// If thread rather than process was specifically targeted, send the signal to it first.
bt edx, eax
jnc 8f
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base)
// eax ebx ecx edx esi edi
mov ebx, [{proc_fd}]
mov ecx, gs:[0]
add ecx, {tcb_sa_off} + {sa_tmp_rt_inf}
mov [ecx], eax
mov gs:[{tcb_sa_off} + {sa_tmp_signo}], eax
mov edx, {RTINF_SIZE}
mov esi, 1
lea edi, [{proc_call}]
mov eax, {SYS_CALL}
int 0x80
test eax, eax
jnz 1b
mov eax, gs:[{tcb_sa_off} + {sa_tmp_signo}]
add eax, 32
jmp 2f
8:
add eax, 32
9:
// Read si_pid and si_uid, atomically.
movq gs:[{tcb_sa_off} + {sa_tmp_mm0}], mm0
movq mm0, gs:[{tcb_sc_off} + {sc_sender_infos} + eax * 8]
movq gs:[{tcb_sa_off} + {sa_tmp_id_inf}], mm0
movq mm0, gs:[{tcb_sa_off} + {sa_tmp_mm0}]
mov edx, eax
shr edx, 5
mov ecx, eax
and ecx, 31
lock btr gs:[{tcb_sc_off} + {sc_word} + edx * 8], ecx
add eax, 64
2:
and esp, -{STACK_ALIGN}
mov edx, eax
add edx, edx
bt dword ptr [{pctl} + {pctl_actions} + edx * 8 + 4], 28
jnc 4f
mov edx, gs:[{tcb_sa_off} + {sa_altstack_top}]
cmp esp, edx
ja 3f
cmp esp, gs:[{tcb_sa_off} + {sa_altstack_bottom}]
jnbe 4f
3:
mov esp, edx
4:
// Now that we have a stack, we can finally start populating the signal stack.
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_esp}]
push dword ptr gs:[{tcb_sc_off} + {sc_saved_eip}]
push dword ptr gs:[{tcb_sc_off} + {sc_saved_eflags}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_edx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_ecx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_eax}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_ebx}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_edi}]
push dword ptr gs:[{tcb_sa_off} + {sa_tmp_esi}]
push ebp
sub esp, 2 * 4 + 29 * 16
fxsave [esp]
mov [esp - 4], eax
sub esp, 48
mov ecx, esp
call {inner}
fxrstor [esp + 48]
add esp, 48 + 29 * 16 + 2 * 4
pop ebp
pop esi
pop edi
pop ebx
pop eax
pop ecx
pop edx
popfd
pop dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
.globl __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
pop esp
.globl __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jmp dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
7:
mov eax, gs:[0]
lea esp, [eax + {tcb_sc_off} + {sc_saved_eflags}]
popfd
mov esp, gs:[{tcb_sa_off} + {sa_tmp_esp}]
mov eax, gs:[{tcb_sc_off} + {sc_saved_eip}]
mov gs:[{tcb_sa_off} + {sa_tmp_eip}], eax
mov eax, gs:[{tcb_sa_off} + {sa_tmp_eax}]
mov ebx, gs:[{tcb_sa_off} + {sa_tmp_ebx}]
mov ecx, gs:[{tcb_sa_off} + {sa_tmp_ecx}]
mov edx, gs:[{tcb_sa_off} + {sa_tmp_edx}]
mov edi, gs:[{tcb_sa_off} + {sa_tmp_edi}]
mov esi, gs:[{tcb_sa_off} + {sa_tmp_esi}]
and dword ptr gs:[{tcb_sc_off} + {sc_control}], ~1
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
jmp dword ptr gs:[{tcb_sa_off} + {sa_tmp_eip}]
"] <= [
inner = sym inner_fastcall,
sa_tmp_eip = const offset_of!(SigArea, tmp_eip),
sa_tmp_esp = const offset_of!(SigArea, tmp_esp),
sa_tmp_eax = const offset_of!(SigArea, tmp_eax),
sa_tmp_ebx = const offset_of!(SigArea, tmp_ebx),
sa_tmp_ecx = const offset_of!(SigArea, tmp_ecx),
sa_tmp_edx = const offset_of!(SigArea, tmp_edx),
sa_tmp_edi = const offset_of!(SigArea, tmp_edi),
sa_tmp_esi = const offset_of!(SigArea, tmp_esi),
sa_tmp_mm0 = const offset_of!(SigArea, tmp_mm0),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_tmp_signo = const offset_of!(SigArea, tmp_signo),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
sc_control = const offset_of!(Sigcontrol, control_flags),
sc_saved_eflags = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_eip = const offset_of!(Sigcontrol, saved_ip),
sc_word = const offset_of!(Sigcontrol, word),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
tcb_sa_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch),
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
pctl_actions = const offset_of!(SigProcControl, actions),
pctl_sender_infos = const offset_of!(SigProcControl, sender_infos),
pctl_pending = const offset_of!(SigProcControl, pending),
pctl = sym PROC_CONTROL_STRUCT,
proc_fd = sym PROC_FD,
proc_call = sym PROC_CALL,
STACK_ALIGN = const 16,
SYS_CALL = const syscall::SYS_CALL,
RTINF_SIZE = const size_of::<RtSigInfo>(),
]);
asmfunction!(__relibc_internal_rlct_clone_ret -> usize: ["
# Load registers
pop eax
sub esp, 8
mov DWORD PTR [esp], 0x00001F80
# TODO: ldmxcsr [esp]
mov WORD PTR [esp], 0x037F
fldcw [esp]
add esp, 8
# Call entry point
call eax
ret
"] <= []);
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
}
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
if stack.regs.eip == __relibc_internal_sigentry_crit_first as usize {
let stack_ptr = stack.regs.esp as *const usize;
stack.regs.esp = unsafe { stack_ptr.read() };
stack.regs.eip = unsafe { stack_ptr.sub(1).read() };
} else if stack.regs.eip == __relibc_internal_sigentry_crit_second as usize
|| stack.regs.eip == __relibc_internal_sigentry_crit_third as usize
{
stack.regs.eip = area.tmp_eip;
}
PosixStackt {
sp: stack.regs.esp as *mut (),
size: 0, // TODO
flags: 0, // TODO
}
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_eip = core::mem::replace(&mut stack.regs.eip, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_eip);
control.saved_archdep_reg.set(stack.regs.eflags);
}
#[unsafe(no_mangle)]
pub unsafe fn manually_enter_trampoline() {
let c = unsafe { &crate::Tcb::current().unwrap().os_specific.control };
c.control_flags.store(
c.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
c.saved_archdep_reg.set(0); // TODO: Just reset DF on x86?
unsafe {
core::arch::asm!("
call 2f
jmp 3f
2:
pop dword ptr gs:[{tcb_sc_off} + {sc_saved_eip}]
jmp __relibc_internal_sigentry
3:
",
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
sc_saved_eip = const offset_of!(Sigcontrol, saved_ip),
);
}
}
/// Get current stack pointer, weak granularity guarantees.
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, esp", out(reg) sp);
}
sp
}
pub static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: u64 = ProcCall::Sigdeq as u64;
-654
View File
@@ -1,654 +0,0 @@
use core::cell::SyncUnsafeCell;
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
};
use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use syscall::{data::*, error::*};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 38;
pub const STACK_SIZE: usize = 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub tmp_sp: u64,
pub tmp_t1: u64,
pub tmp_t2: u64,
pub tmp_t3: u64,
pub tmp_t4: u64,
pub tmp_a0: u64,
pub tmp_a1: u64,
pub tmp_a2: u64,
pub tmp_a3: u64,
pub tmp_a4: u64,
pub tmp_a7: u64,
pub pctl: usize, // TODO: remove
pub tmp_ip: u64,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
pub altstack_top: usize,
pub altstack_bottom: usize,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub int_regs: [u64; 31],
pub pc: u64,
pub fp_regs: [u64; 32],
pub fcsr: u32,
_pad: u32,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.tp = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "C" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
unsafe extern "C" fn child_hook(scratchpad: &ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
unsafe {
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
})
};
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
.attribute arch, \"rv64gc\" # rust bug 80608
addi sp, sp, -200
sd s0, 0(sp)
sd s1, 8(sp)
sd s2, 16(sp)
sd s3, 24(sp)
sd s4, 32(sp)
sd s5, 40(sp)
sd s6, 48(sp)
sd s7, 56(sp)
sd s8, 64(sp)
sd s9, 72(sp)
sd s10, 80(sp)
sd s11, 88(sp)
sd ra, 96(sp)
fsd fs0, 104(sp)
fsd fs1, 112(sp)
fsd fs2, 120(sp)
fsd fs3, 128(sp)
fsd fs4, 136(sp)
fsd fs5, 144(sp)
fsd fs6, 152(sp)
fsd fs7, 160(sp)
fsd fs8, 168(sp)
fsd fs9, 176(sp)
fsd fs10, 184(sp)
fsd fs11, 192(sp)
// a0 is forwarded from this function
mv a1, sp
jal {fork_impl}
ld s0, 0(sp)
ld s1, 8(sp)
ld s2, 16(sp)
ld s3, 24(sp)
ld s4, 32(sp)
ld s5, 40(sp)
ld s6, 48(sp)
ld s7, 56(sp)
ld s8, 64(sp)
ld s9, 72(sp)
ld s10, 80(sp)
ld s11, 88(sp)
ld ra, 96(sp)
fld fs0, 104(sp)
fld fs1, 112(sp)
fld fs2, 120(sp)
fld fs3, 128(sp)
fld fs4, 136(sp)
fld fs5, 144(sp)
fld fs6, 152(sp)
fld fs7, 160(sp)
fld fs8, 168(sp)
fld fs9, 176(sp)
fld fs10, 184(sp)
fld fs11, 192(sp)
addi sp, sp, 200
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
.attribute arch, \"rv64gc\" # rust bug 80608
# scratchpad is in a1, move to a0 for child_hook
mv a0, a1
jal {child_hook}
mv a0, zero
ld s0, 0(sp)
ld s1, 8(sp)
ld s2, 16(sp)
ld s3, 24(sp)
ld s4, 32(sp)
ld s5, 40(sp)
ld s6, 48(sp)
ld s7, 56(sp)
ld s8, 64(sp)
ld s9, 72(sp)
ld s10, 80(sp)
ld s11, 88(sp)
ld ra, 96(sp)
fld fs0, 104(sp)
fld fs1, 112(sp)
fld fs2, 120(sp)
fld fs3, 128(sp)
fld fs4, 136(sp)
fld fs5, 144(sp)
fld fs6, 152(sp)
fld fs7, 160(sp)
fld fs8, 168(sp)
fld fs9, 176(sp)
fld fs10, 184(sp)
fld fs11, 192(sp)
addi sp, sp, 200
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_sigentry: ["
.attribute arch, \"rv64gc\" # rust bug 80608
// Save some registers
ld t0, -8(tp) // Tcb
sd sp, ({tcb_sa_off} + {sa_tmp_sp})(t0)
sd t1, ({tcb_sa_off} + {sa_tmp_t1})(t0)
sd t2, ({tcb_sa_off} + {sa_tmp_t2})(t0)
sd t3, ({tcb_sa_off} + {sa_tmp_t3})(t0)
sd t4, ({tcb_sa_off} + {sa_tmp_t4})(t0)
ld t4, ({tcb_sa_off} + {sa_off_pctl})(t0)
// First, select signal, always pick first available bit
99:
// Read first signal word
ld t1, ({tcb_sc_off} + {sc_word})(t0)
srli t2, t1, 32 // bitset to low word
and t1, t1, t2 // masked bitset in low word
beqz t1, 3f
// Found in first thread signal word
mv t3, x0
2: andi t2, t1, 1
bnez t2, 10f
addi t3, t3, 1
srli t1, t1, 1
j 2b
// If no unblocked thread signal was found, check for process.
// This is competitive; we need to atomically check if *we* cleared the process-wide pending
// bit, otherwise restart.
3: lw t1, {pctl_off_pending}(t4)
and t1, t1, t2
beqz t1, 3f
// Found in first process signal word
li t3, -1
2: andi t2, t1, 1
addi t3, t3, 1
srli t1, t1, 1
beqz t2, 2b
slli t1, t3, 3 // * 8 == size_of SenderInfo
add t1, t1, t4
ld t1, {pctl_off_sender_infos}(t1)
sd t1, ({tcb_sa_off} + {sa_tmp_id_inf})(t0)
li t1, 1
sll t1, t1, t3
not t1, t1
addi t2, t4, {pctl_off_pending}
amoand.w.aq t2, t1, (t2)
and t1, t1, t2
bne t1, t2, 9f
3:
// Read second signal word - both process and thread simultaneously.
// This must be done since POSIX requires low realtime signals to be picked first.
ld t1, ({tcb_sc_off} + {sc_word} + 8)(t0)
lw t2, ({pctl_off_pending} + 4)(t4)
or t4, t1, t2
srli t2, t1, 32
and t4, t2, t4
beqz t4, 7f
li t3, -1
2: andi t2, t4, 1
addi t3, t3, 1
srli t4, t4, 1
beqz t2, 2b
li t2, 1
sll t2, t2, t3
and t1, t1, t2
addi t3, t3, 32
bnez t1, 10f // thread signal
// otherwise, try (competitively) dequeueing realtime signal
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base)
// a7 a0 a1 a2 a3 a4
// TODO: This SYS_CALL invocation has not yet been tested due to toolchain issues.
sd a0, ({tcb_sa_off} + {sa_tmp_a0})(t0)
sd a1, ({tcb_sa_off} + {sa_tmp_a1})(t0)
sd a2, ({tcb_sa_off} + {sa_tmp_a2})(t0)
sd a3, ({tcb_sa_off} + {sa_tmp_a3})(t0)
sd a4, ({tcb_sa_off} + {sa_tmp_a4})(t0)
sd a7, ({tcb_sa_off} + {sa_tmp_a7})(t0)
li a7, {SYS_CALL}
addi a2, t3, -32
add a1, t0, {tcb_sa_off} + {sa_tmp_rt_inf} // out pointer of dequeued realtime sig
sd a2, (a1)
li a2, {RTINF_SIZE}
li a3, 1
1337:
auipc a4, %pcrel_hi({proc_fd})
addi a4, a4, %pcrel_lo(1337b)
ecall
ld a3, ({tcb_sa_off} + {sa_tmp_a3})(t0)
ld a4, ({tcb_sa_off} + {sa_tmp_a4})(t0)
bnez a0, 99b // assumes error can only be EAGAIN
j 9f
10: // thread signal. t3 holds signal number
srli t1, t3, 5
bnez t1, 2f // FIXME senderinfo?
sll t2, t3, 3 // * 8 == size_of SenderInfo
add t2, t2, t0
ld t2, ({tcb_sc_off} + {sc_sender_infos})(t2)
sd t2, ({tcb_sa_off} + {sa_tmp_id_inf})(t0)
2: andi t4, t3, 31
li t2, 1
sll t2, t2, t4
not t2, t2
sll t1, t1, 3
add t1, t1, t0
addi t1, t1, {tcb_sc_off} + {sc_word}
amoand.w.aq x0, t2, (t1)
addi t3, t3, 64 // indicate signal was targeted at thread
9: // process signal t3 holds signal number
// By now we have selected a signal, stored in eax (6-bit). We now need to choose whether or
// not to switch to the alternate signal stack. If SA_ONSTACK is clear for this signal, then
// skip the sigaltstack logic.
ld t4, ({tcb_sa_off} + {sa_off_pctl})(t0)
andi t1, t3, 63
slli t1, t1, 4 // * 16 == size_of RawAction
add t1, t1, t4
ld t1, {pctl_off_actions}(t1)
slli t1, t1, 63-58 // SA_ONSTACK in sign bit
bgez t1, 3f
// If current RSP is above altstack region, switch to altstack
ld t1, ({tcb_sa_off} + {sa_altstack_top})(t0)
bgtu sp, t1, 2f
ld t2, ({tcb_sa_off} + {sa_altstack_bottom})(t0)
bgtu sp, t3, 3f
2: mv sp, t1
3:
// form mcontext on stack
addi sp, sp, -33 * 8
fsd f0, (0 * 8)(sp)
fsd f1, (1 * 8)(sp)
fsd f2, (2 * 8)(sp)
fsd f3, (3 * 8)(sp)
fsd f4, (4 * 8)(sp)
fsd f5, (5 * 8)(sp)
fsd f6, (6 * 8)(sp)
fsd f7, (7 * 8)(sp)
fsd f8, (8 * 8)(sp)
fsd f9, (9 * 8)(sp)
fsd f10, (10 * 8)(sp)
fsd f11, (11 * 8)(sp)
fsd f12, (12 * 8)(sp)
fsd f13, (13 * 8)(sp)
fsd f14, (14 * 8)(sp)
fsd f15, (15 * 8)(sp)
fsd f16, (16 * 8)(sp)
fsd f17, (17 * 8)(sp)
fsd f18, (18 * 8)(sp)
fsd f19, (19 * 8)(sp)
fsd f20, (20 * 8)(sp)
fsd f21, (21 * 8)(sp)
fsd f22, (22 * 8)(sp)
fsd f23, (23 * 8)(sp)
fsd f24, (24 * 8)(sp)
fsd f25, (25 * 8)(sp)
fsd f26, (26 * 8)(sp)
fsd f27, (27 * 8)(sp)
fsd f28, (28 * 8)(sp)
fsd f29, (29 * 8)(sp)
fsd f30, (30 * 8)(sp)
fsd f31, (31 * 8)(sp)
csrr t1, fcsr
sw t1, (32 * 8)(sp)
addi sp, sp, -32 * 8
sd x1, 0(sp)
ld t1, ({tcb_sa_off} + {sa_tmp_sp})(t0)
sd t1, (1 * 8)(sp) // x2 is sp
sd x3, (2 * 8)(sp)
sd x4, (3 * 8)(sp)
ld t1, ({tcb_sc_off} + {sc_saved_t0})(t0)
sd t1, (4 * 8)(sp) // x5 is t0
ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t0)
sd t1, (5 * 8)(sp) // x6 is t1
ld t1, ({tcb_sa_off} + {sa_tmp_t2})(t0)
sd t1, (6 * 8)(sp) // x7 is t2
sd x8, (7 * 8)(sp)
sd x9, (8 * 8)(sp)
sd x10, (9 * 8)(sp)
sd x11, (10 * 8)(sp)
sd x12, (11 * 8)(sp)
sd x13, (12 * 8)(sp)
sd x14, (13 * 8)(sp)
sd x15, (14 * 8)(sp)
sd x16, (15 * 8)(sp)
sd x17, (16 * 8)(sp)
sd x18, (17 * 8)(sp)
sd x19, (18 * 8)(sp)
sd x20, (19 * 8)(sp)
sd x21, (20 * 8)(sp)
sd x22, (21 * 8)(sp)
sd x23, (22 * 8)(sp)
sd x24, (23 * 8)(sp)
sd x25, (24 * 8)(sp)
sd x26, (25 * 8)(sp)
sd x27, (26 * 8)(sp)
ld t1, ({tcb_sa_off} + {sa_tmp_t3})(t0)
sd t1, (27 * 8)(sp) // t3 is x28
ld t1, ({tcb_sa_off} + {sa_tmp_t4})(t0)
sd t1, (28 * 8)(sp) // t4 is x29
sd x30, (29 * 8)(sp)
sd x31, (30 * 8)(sp)
ld t1, ({tcb_sc_off} + {sc_saved_ip})(t0)
sd t1, (31 * 8)(sp)
// form ucontext
addi sp, sp, -64
sw t3, 60(sp)
mv t0, sp
jal {inner}
addi sp, sp, 64
addi t0, sp, 32 * 8
fld f0, (0 * 8)(t0)
fld f1, (1 * 8)(t0)
fld f2, (2 * 8)(t0)
fld f3, (3 * 8)(t0)
fld f4, (4 * 8)(t0)
fld f5, (5 * 8)(t0)
fld f6, (6 * 8)(t0)
fld f7, (7 * 8)(t0)
fld f8, (8 * 8)(t0)
fld f9, (9 * 8)(t0)
fld f10, (10 * 8)(t0)
fld f11, (11 * 8)(t0)
fld f12, (12 * 8)(t0)
fld f13, (13 * 8)(t0)
fld f14, (14 * 8)(t0)
fld f15, (15 * 8)(t0)
fld f16, (16 * 8)(t0)
fld f17, (17 * 8)(t0)
fld f18, (18 * 8)(t0)
fld f19, (19 * 8)(t0)
fld f20, (20 * 8)(t0)
fld f21, (21 * 8)(t0)
fld f22, (22 * 8)(t0)
fld f23, (23 * 8)(t0)
fld f24, (24 * 8)(t0)
fld f25, (25 * 8)(t0)
fld f26, (26 * 8)(t0)
fld f27, (27 * 8)(t0)
fld f28, (28 * 8)(t0)
fld f29, (29 * 8)(t0)
fld f30, (30 * 8)(t0)
fld f31, (31 * 8)(t0)
lw t1, (32 * 8)(t0)
csrw fcsr, t1
ld x1, 0(sp)
// skip sp
// skip gp
ld x4, (3 * 8)(sp)
ld x5, (4 * 8)(sp)
ld x6, (5 * 8)(sp)
ld x7, (6 * 8)(sp)
ld x8, (7 * 8)(sp)
ld x9, (8 * 8)(sp)
ld x10, (9 * 8)(sp)
ld x11, (10 * 8)(sp)
ld x12, (11 * 8)(sp)
ld x13, (12 * 8)(sp)
ld x14, (13 * 8)(sp)
ld x15, (14 * 8)(sp)
ld x16, (15 * 8)(sp)
ld x17, (16 * 8)(sp)
ld x18, (17 * 8)(sp)
ld x19, (18 * 8)(sp)
ld x20, (19 * 8)(sp)
ld x21, (20 * 8)(sp)
ld x22, (21 * 8)(sp)
ld x23, (22 * 8)(sp)
ld x24, (23 * 8)(sp)
ld x25, (24 * 8)(sp)
ld x26, (25 * 8)(sp)
ld x27, (26 * 8)(sp)
ld x28, (27 * 8)(sp)
ld x29, (28 * 8)(sp)
ld x30, (29 * 8)(sp)
ld x31, (30 * 8)(sp)
ld gp, (31 * 8)(sp) // new IP; this clobbers register x3/gp which is ABI reserved
.global __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
ld sp, (1 * 8)(sp)
.global __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jr gp
7:
// A spurious signal occurred. Signals are still disabled here, but will need to be re-enabled.
// restore stack
ld sp, ({tcb_sa_off} + {sa_tmp_sp})(t0)
// move saved IP away from control, allowing arch_pre to save us if interrupted.
ld t1, ({tcb_sc_off} + {sc_saved_ip})(t0)
sd t1, ({tcb_sa_off} + {sa_tmp_ip})(t0)
// restore regs
ld t2, ({tcb_sa_off} + {sa_tmp_t2})(t0)
ld t3, ({tcb_sa_off} + {sa_tmp_t3})(t0)
ld t4, ({tcb_sa_off} + {sa_tmp_t4})(t0)
// move saved t0 away from control as well
mv t1, t0
ld t0, ({tcb_sc_off} + {sc_saved_t0})(t0)
// Re-enable signals. This code can be interrupted after this signal, so we need to define
// 'crit_third'.
ld gp, ({tcb_sc_off} + {sc_control})(t1)
andi gp, gp, ~1
sd gp, ({tcb_sc_off} + {sc_control})(t1)
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
ld gp, ({tcb_sa_off} + {sa_tmp_ip})(t1)
.globl __relibc_internal_sigentry_crit_fourth
__relibc_internal_sigentry_crit_fourth:
ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
.globl __relibc_internal_sigentry_crit_fifth
__relibc_internal_sigentry_crit_fifth:
jr gp
"] <= [
tcb_sc_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control)),
sc_word = const offset_of!(Sigcontrol, word),
sc_saved_t0 = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_ip = const offset_of!(Sigcontrol, saved_ip),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_control = const offset_of!(Sigcontrol, control_flags),
tcb_sa_off = const (offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch)),
sa_off_pctl = const offset_of!(SigArea, pctl),
sa_tmp_sp = const offset_of!(SigArea, tmp_sp),
sa_tmp_t1 = const offset_of!(SigArea, tmp_t1),
sa_tmp_t2 = const offset_of!(SigArea, tmp_t2),
sa_tmp_t3 = const offset_of!(SigArea, tmp_t3),
sa_tmp_t4 = const offset_of!(SigArea, tmp_t4),
sa_tmp_a0 = const offset_of!(SigArea, tmp_a0),
sa_tmp_a1 = const offset_of!(SigArea, tmp_a1),
sa_tmp_a2 = const offset_of!(SigArea, tmp_a2),
sa_tmp_a3 = const offset_of!(SigArea, tmp_a3),
sa_tmp_a4 = const offset_of!(SigArea, tmp_a4),
sa_tmp_a7 = const offset_of!(SigArea, tmp_a7),
sa_tmp_ip = const offset_of!(SigArea, tmp_ip),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
pctl_off_actions = const offset_of!(SigProcControl, actions),
inner = sym inner_c,
pctl_off_pending = const offset_of!(SigProcControl, pending),
pctl_off_sender_infos = const offset_of!(SigProcControl, sender_infos),
SYS_CALL = const syscall::SYS_CALL,
RTINF_SIZE = const size_of::<RtSigInfo>(),
proc_fd = sym PROC_FD,
]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
ld t0, 0(sp)
ld a0, 8(sp)
ld a1, 16(sp)
ld a2, 24(sp)
ld a3, 32(sp)
ld a4, 40(sp)
ld a5, 48(sp)
addi sp, sp, 56
jalr t0
ret
"] <= []);
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!(
"mv {}, sp",
out(reg) sp,
options(nomem));
}
sp
}
pub unsafe fn manually_enter_trampoline() {
let ctl = unsafe { &Tcb::current().unwrap().os_specific.control };
ctl.control_flags.store(
ctl.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
ctl.saved_archdep_reg.set(0);
let ip_location = &ctl.saved_ip as *const _ as usize;
unsafe {
core::arch::asm!("
jal 2f
j 3f
2:
sd ra, 0(t0)
la t0, __relibc_internal_sigentry
jalr x0, t0
3:
",
inout("t0") ip_location => _, out("ra") _);
}
}
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
fn __relibc_internal_sigentry_crit_fourth();
fn __relibc_internal_sigentry_crit_fifth();
}
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
// It is impossible to update SP and PC atomically. Instead, we abuse the fact that
// signals are disabled in the prologue of the signal trampoline, which allows us to emulate
// atomicity inside the critical section, consisting of one instruction at 'crit_first', and
// one at 'crit_second', see asm.
if stack.regs.pc == __relibc_internal_sigentry_crit_first as u64 {
// Reexecute 'ld sp, (1 * 8)(sp)'
let stack_ptr = stack.regs.int_regs[1] as *const u64; // x2
stack.regs.int_regs[1] = unsafe { stack_ptr.add(1).read() };
// and 'jr gp' steps.
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_second as u64
|| stack.regs.pc == __relibc_internal_sigentry_crit_fifth as u64
{
// just reexecute the jump
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_third as u64 {
// ld gp, ({tcb_sa_off} + {sa_tmp_ip})(t1)
stack.regs.int_regs[2] = area.tmp_ip;
// ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
stack.regs.int_regs[5] = area.tmp_t1;
// j gp
stack.regs.pc = stack.regs.int_regs[2];
} else if stack.regs.pc == __relibc_internal_sigentry_crit_fourth as u64 {
// ld t1, ({tcb_sa_off} + {sa_tmp_t1})(t1)
stack.regs.int_regs[5] = area.tmp_t1;
// jr gp
stack.regs.pc = stack.regs.int_regs[2];
}
get_sigaltstack(area, stack.regs.int_regs[1] as usize).into()
}
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_pc = core::mem::replace(&mut stack.regs.pc, __relibc_internal_sigentry as u64);
control.saved_ip.set(orig_pc as usize);
control
.saved_archdep_reg
.set(stack.regs.int_regs[4] as usize); // t0
}
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
-528
View File
@@ -1,528 +0,0 @@
use core::{
cell::SyncUnsafeCell,
mem::offset_of,
ptr::NonNull,
sync::atomic::{AtomicU8, Ordering},
};
use syscall::{
data::{SigProcControl, Sigcontrol},
error::*,
};
use crate::{
Tcb,
proc::{FdGuard, FdGuardUpper, ForkArgs, fork_inner},
signal::{PROC_CONTROL_STRUCT, PosixStackt, RtSigarea, SigStack, get_sigaltstack, inner_c},
};
use redox_protocols::protocol::{ProcCall, RtSigInfo};
use super::ForkScratchpad;
// Setup a stack starting from the very end of the address space, and then growing downwards.
pub const STACK_TOP: usize = 1 << 47;
pub const STACK_SIZE: usize = 8 * 1024 * 1024;
#[derive(Debug, Default)]
#[repr(C)]
pub struct SigArea {
pub tmp_rip: usize,
pub tmp_rsp: usize,
pub tmp_rax: usize,
pub tmp_rdx: usize,
pub tmp_rdi: usize,
pub tmp_rsi: usize,
pub tmp_r8: usize,
pub tmp_r10: usize,
pub tmp_r12: usize,
pub tmp_rt_inf: RtSigInfo,
pub tmp_id_inf: u64,
pub altstack_top: usize,
pub altstack_bottom: usize,
pub disable_signals_depth: u64,
pub last_sig_was_restart: bool,
pub last_sigstack: Option<NonNull<SigStack>>,
}
#[repr(C, align(16))]
#[derive(Debug, Default)]
pub struct ArchIntRegs {
pub ymm_upper: [u128; 16],
pub fxsave: [u128; 29],
pub r15: usize, // fxsave "available" +0
pub r14: usize, // available +8
pub r13: usize, // available +16
pub r12: usize, // available +24
pub rbp: usize, // available +32
pub rbx: usize, // available +40
pub r11: usize, // outside fxsave, and so on
pub r10: usize,
pub r9: usize,
pub r8: usize,
pub rax: usize,
pub rcx: usize,
pub rdx: usize,
pub rsi: usize,
pub rdi: usize,
pub rflags: usize,
pub rip: usize,
pub rsp: usize,
}
/// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS
/// is already initialized as if it was a thread.
pub unsafe fn deactivate_tcb(open_via_dup: &FdGuardUpper) -> Result<()> {
let mut env = syscall::EnvRegisters::default();
let file = open_via_dup.dup(b"regs/env")?;
env.fsbase = 0;
env.gsbase = 0;
file.write(&mut env)?;
Ok(())
}
unsafe extern "sysv64" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
#[allow(unsafe_op_in_unsafe_fn)]
unsafe extern "sysv64" fn child_hook(scratchpad: &ForkScratchpad) {
let _ = syscall::close(scratchpad.cur_filetable_fd);
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(scratchpad.new_thr_fd),
new_proc_fd: if scratchpad.new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(scratchpad.new_proc_fd))
},
});
}
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
push rbp
mov rbp, rsp
push rbx
push rbp
push r12
push r13
push r14
push r15
sub rsp, 16
stmxcsr [rsp+16]
fnstcw [rsp+8]
// rdi: &ForkArgs
// rsi: initial_rsp
mov rsi, rsp
call {fork_impl}
add rsp, 64
pop rbp
ret
"] <= [fork_impl = sym fork_impl]);
asmfunction!(__relibc_internal_fork_ret: ["
# scratchpad is in rsi, move to rdi for child_hook
mov rdi, rsi
call {child_hook}
ldmxcsr [rsp + 16]
mov rcx, [rsp + 8]
xor rax, rax
add rsp, 16
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rbp
ret
"] <= [child_hook = sym child_hook]);
asmfunction!(__relibc_internal_rlct_clone_ret: ["
# Load registers
pop rax
pop rdi
pop rsi
pop rdx
pop rcx
pop r8
pop r9
mov DWORD PTR [rsp - 8], 0x00001F80
ldmxcsr [rsp - 8]
mov WORD PTR [rsp - 8], 0x037F
fldcw [rsp - 8]
# Call entry point
call rax
ret
"] <= []);
asmfunction!(__relibc_internal_sigentry: ["
// Save some registers
mov fs:[{tcb_sa_off} + {sa_tmp_rsp}], rsp
mov fs:[{tcb_sa_off} + {sa_tmp_rax}], rax
mov fs:[{tcb_sa_off} + {sa_tmp_rdx}], rdx
mov fs:[{tcb_sa_off} + {sa_tmp_rdi}], rdi
mov fs:[{tcb_sa_off} + {sa_tmp_rsi}], rsi
mov fs:[{tcb_sa_off} + {sa_tmp_r8}], r8
mov fs:[{tcb_sa_off} + {sa_tmp_r10}], r10
mov fs:[{tcb_sa_off} + {sa_tmp_r12}], r12
// First, select signal, always pick first available bit
1:
// Read standard signal word - first targeting this thread
mov rax, fs:[{tcb_sc_off} + {sc_word}]
mov rdx, rax
shr rdx, 32
and eax, edx
bsf eax, eax
jnz 2f
// If no unblocked thread signal was found, check for process.
// This is competitive; we need to atomically check if *we* cleared the process-wide pending
// bit, otherwise restart.
mov eax, [rip + {pctl} + {pctl_off_pending}]
and eax, edx
bsf eax, eax
jz 8f
lea rdi, [rip + {pctl} + {pctl_off_sender_infos}]
mov rdi, [rdi + rax * 8]
lock btr [rip + {pctl} + {pctl_off_pending}], eax
mov fs:[{tcb_sa_off} + {sa_tmp_id_inf}], rdi
jc 9f
8:
// Read second signal word - both process and thread simultaneously.
// This must be done since POSIX requires low realtime signals to be picked first.
mov edx, fs:[{tcb_sc_off} + {sc_word} + 8]
mov eax, [rip + {pctl} + {pctl_off_pending} + 4]
or eax, edx
and eax, fs:[{tcb_sc_off} + {sc_word} + 12]
bsf eax, eax
jz 7f
bt edx, eax // check if signal was sent to thread specifically
jnc 81f
// if so, continue as usual
add eax, 32
jmp 2f
81:
// otherwise, try (competitively) dequeueing realtime signal
// SYS_CALL(fd, payload_base, payload_len, metadata_len | (flags << 8), metadata_base)
// rax rdi rsi rdx r10 r8
mov r12d, eax
mov rsi, fs:[0]
mov rdi, [rip+{proc_fd}]
add rsi, {tcb_sa_off} + {sa_tmp_rt_inf} // out pointer of dequeued realtime sig
mov rdx, {RTINF_SIZE}
mov [rsi], eax
lea r8, [rip + {proc_call_sigdeq}]
mov r10, 1
mov eax, {SYS_CALL}
syscall
test eax, eax
jnz 1b // assumes error can only be EAGAIN
lea eax, [r12d + 32]
jmp 9f
2:
mov edx, eax
shr edx, 5
mov rdi, fs:[{tcb_sc_off} + {sc_sender_infos} + eax * 8]
lock btr fs:[{tcb_sc_off} + {sc_word} + edx * 4], eax
mov fs:[{tcb_sa_off} + {sa_tmp_id_inf}], rdi
add eax, 64 // indicate signal was targeted at thread
9:
sub rsp, {REDZONE_SIZE}
and rsp, -{STACK_ALIGN}
// By now we have selected a signal, stored in eax (6-bit). We now need to choose whether or
// not to switch to the alternate signal stack. If SA_ONSTACK is clear for this signal, then
// skip the sigaltstack logic.
lea rdx, [rip + {pctl} + {pctl_off_actions}]
mov ecx, eax
and ecx, 63
// LEA doesn't support 16x, so just do two x8s.
lea rdx, [rdx + 8 * rcx]
lea rdx, [rdx + 8 * rcx]
bt qword ptr [rdx], {SA_ONSTACK_BIT}
jnc 4f
// Otherwise, the altstack is already active. The sigaltstack being disabled, is equivalent
// to setting 'top' to usize::MAX and 'bottom' to 0.
// If current RSP is above altstack region, switch to altstack
mov rdx, fs:[{tcb_sa_off} + {sa_altstack_top}]
cmp rsp, rdx
cmova rsp, rdx
// If current RSP is below altstack region, also switch to altstack
cmp rsp, fs:[{tcb_sa_off} + {sa_altstack_bottom}]
cmovbe rsp, rdx
.p2align 4
4:
// Now that we have a stack, we can finally start initializing the signal stack!
push fs:[{tcb_sa_off} + {sa_tmp_rsp}]
push fs:[{tcb_sc_off} + {sc_saved_rip}]
push fs:[{tcb_sc_off} + {sc_saved_rflags}]
push fs:[{tcb_sa_off} + {sa_tmp_rdi}]
push fs:[{tcb_sa_off} + {sa_tmp_rsi}]
push fs:[{tcb_sa_off} + {sa_tmp_rdx}]
push rcx
push fs:[{tcb_sa_off} + {sa_tmp_rax}]
push fs:[{tcb_sa_off} + {sa_tmp_r8}]
push r9
push fs:[{tcb_sa_off} + {sa_tmp_r10}]
push r11
push rbx
push rbp
push fs:[{tcb_sa_off} + {sa_tmp_r12}]
push r13
push r14
push r15
sub rsp, (29 + 16) * 16 // fxsave region minus available bytes
fxsave64 [rsp + 16 * 16]
// TODO: self-modifying?
cmp byte ptr [rip + {supports_avx}], 0
je 5f
// Prefer vextractf128 over vextracti128 since the former only requires AVX version 1.
vextractf128 [rsp + 15 * 16], ymm0, 1
vextractf128 [rsp + 14 * 16], ymm1, 1
vextractf128 [rsp + 13 * 16], ymm2, 1
vextractf128 [rsp + 12 * 16], ymm3, 1
vextractf128 [rsp + 11 * 16], ymm4, 1
vextractf128 [rsp + 10 * 16], ymm5, 1
vextractf128 [rsp + 9 * 16], ymm6, 1
vextractf128 [rsp + 8 * 16], ymm7, 1
vextractf128 [rsp + 7 * 16], ymm8, 1
vextractf128 [rsp + 6 * 16], ymm9, 1
vextractf128 [rsp + 5 * 16], ymm10, 1
vextractf128 [rsp + 4 * 16], ymm11, 1
vextractf128 [rsp + 3 * 16], ymm12, 1
vextractf128 [rsp + 2 * 16], ymm13, 1
vextractf128 [rsp + 16], ymm14, 1
vextractf128 [rsp], ymm15, 1
5:
mov [rsp - 4], eax
sub rsp, 64 // alloc space for ucontext fields
mov rdi, rsp
call {inner}
add rsp, 64
fxrstor64 [rsp + 16 * 16]
cmp byte ptr [rip + {supports_avx}], 0
je 6f
vinsertf128 ymm0, ymm0, [rsp + 15 * 16], 1
vinsertf128 ymm1, ymm1, [rsp + 14 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 13 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 12 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 11 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 10 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 9 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 8 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 7 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 6 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 5 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 4 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 3 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 2 * 16], 1
vinsertf128 ymm2, ymm2, [rsp + 16], 1
vinsertf128 ymm2, ymm2, [rsp], 1
6:
add rsp, (29 + 16) * 16
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop r11
pop r10
pop r9
pop r8
pop rax
pop rcx
pop rdx
pop rsi
pop rdi
popfq
pop qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
// x86 lacks atomic instructions for setting both the stack and instruction pointer
// simultaneously, except the slow microcoded IRETQ instruction. Thus, we let the arch_pre
// function emulate atomicity between the pop rsp and indirect jump.
.globl __relibc_internal_sigentry_crit_first
__relibc_internal_sigentry_crit_first:
pop rsp
.globl __relibc_internal_sigentry_crit_second
__relibc_internal_sigentry_crit_second:
jmp qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
7:
// A spurious signal occurred. Signals are still disabled here, but will need to be re-enabled.
// restore flags
mov rax, fs:[0] // load FS base
// TODO: Use lahf/sahf rather than pushfq/popfq?
lea rsp, [rax + {tcb_sc_off} + {sc_saved_rflags}]
popfq
// restore stack
mov rsp, fs:[{tcb_sa_off} + {sa_tmp_rsp}]
// move saved RIP away from control, allowing arch_pre to save us if interrupted.
mov rax, fs:[{tcb_sc_off} + {sc_saved_rip}]
mov fs:[{tcb_sa_off} + {sa_tmp_rip}], rax
// restore regs
mov rax, fs:[{tcb_sa_off} + {sa_tmp_rax}]
mov rdx, fs:[{tcb_sa_off} + {sa_tmp_rdx}]
// Re-enable signals. This code can be interrupted after this signal, so we need to define
// 'crit_third'.
and qword ptr fs:[{tcb_sc_off} + {sc_control}], ~1
.globl __relibc_internal_sigentry_crit_third
__relibc_internal_sigentry_crit_third:
jmp qword ptr fs:[{tcb_sa_off} + {sa_tmp_rip}]
"] <= [
inner = sym inner_c,
sa_tmp_rip = const offset_of!(SigArea, tmp_rip),
sa_tmp_rsp = const offset_of!(SigArea, tmp_rsp),
sa_tmp_rax = const offset_of!(SigArea, tmp_rax),
sa_tmp_rdx = const offset_of!(SigArea, tmp_rdx),
sa_tmp_rdi = const offset_of!(SigArea, tmp_rdi),
sa_tmp_rsi = const offset_of!(SigArea, tmp_rsi),
sa_tmp_r8 = const offset_of!(SigArea, tmp_r8),
sa_tmp_r10 = const offset_of!(SigArea, tmp_r10),
sa_tmp_r12 = const offset_of!(SigArea, tmp_r12),
sa_tmp_rt_inf = const offset_of!(SigArea, tmp_rt_inf),
sa_tmp_id_inf = const offset_of!(SigArea, tmp_id_inf),
sa_altstack_top = const offset_of!(SigArea, altstack_top),
sa_altstack_bottom = const offset_of!(SigArea, altstack_bottom),
sc_saved_rflags = const offset_of!(Sigcontrol, saved_archdep_reg),
sc_saved_rip = const offset_of!(Sigcontrol, saved_ip),
sc_word = const offset_of!(Sigcontrol, word),
sc_sender_infos = const offset_of!(Sigcontrol, sender_infos),
sc_control = const offset_of!(Sigcontrol, control_flags),
tcb_sa_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, arch),
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
pctl_off_actions = const offset_of!(SigProcControl, actions),
pctl_off_pending = const offset_of!(SigProcControl, pending),
pctl_off_sender_infos = const offset_of!(SigProcControl, sender_infos),
pctl = sym PROC_CONTROL_STRUCT,
supports_avx = sym SUPPORTS_AVX,
REDZONE_SIZE = const 128,
STACK_ALIGN = const 16,
SA_ONSTACK_BIT = const 58, // (1 << 58) >> 32 = 0x0400_0000
SYS_CALL = const syscall::SYS_CALL,
proc_call_sigdeq = sym PROC_CALL_SIGDEQ,
RTINF_SIZE = const size_of::<RtSigInfo>(),
proc_fd = sym PROC_FD,
]);
unsafe extern "C" {
fn __relibc_internal_sigentry_crit_first();
fn __relibc_internal_sigentry_crit_second();
fn __relibc_internal_sigentry_crit_third();
}
/// Fixes some edge cases, and calculates the value for uc_stack.
pub unsafe fn arch_pre(stack: &mut SigStack, area: &mut SigArea) -> PosixStackt {
// It is impossible to update RSP and RIP atomically on x86_64, without using IRETQ, which is
// almost as slow as calling a SIGRETURN syscall would be. Instead, we abuse the fact that
// signals are disabled in the prologue of the signal trampoline, which allows us to emulate
// atomicity inside the critical section, consisting of one instruction at 'crit_first', one at
// 'crit_second', and one at 'crit_third', see asm.
if stack.regs.rip == __relibc_internal_sigentry_crit_first as usize {
// Reexecute pop rsp and jump steps. This case needs to be different from the one below,
// since rsp has not been overwritten with the previous context's stack, just yet. At this
// point, we know [rsp+0] contains the saved RSP, and [rsp-8] contains the saved RIP.
let stack_ptr = stack.regs.rsp as *const usize;
stack.regs.rsp = unsafe { stack_ptr.read() };
stack.regs.rip = unsafe { stack_ptr.sub(1).read() };
} else if stack.regs.rip == __relibc_internal_sigentry_crit_second as usize
|| stack.regs.rip == __relibc_internal_sigentry_crit_third as usize
{
// Almost finished, just reexecute the jump before tmp_rip is overwritten by this
// deeper-level signal.
stack.regs.rip = area.tmp_rip;
}
get_sigaltstack(area, stack.regs.rsp).into()
}
/// Rearrange the restore-stack and sigarea in a way that makes it look like a new signal was
/// immediately delivered after restoring the allowset to what it was prior to the original signal delivery.
pub fn arch_ret_to_sig(stack: &mut SigStack, control: &Sigcontrol) {
let orig_rip = core::mem::replace(&mut stack.regs.rip, __relibc_internal_sigentry as usize);
control.saved_ip.set(orig_rip);
control.saved_archdep_reg.set(stack.regs.rflags);
}
pub(crate) static SUPPORTS_AVX: AtomicU8 = AtomicU8::new(0);
// __relibc will be prepended to the name, so no_mangle is fine
#[allow(unsafe_op_in_unsafe_fn)]
#[unsafe(no_mangle)]
pub unsafe fn manually_enter_trampoline() {
let c = &Tcb::current().unwrap().os_specific.control;
c.control_flags.store(
c.control_flags.load(Ordering::Relaxed) | syscall::flag::INHIBIT_DELIVERY.bits(),
Ordering::Release,
);
c.saved_archdep_reg.set(0); // TODO: Just reset DF on x86?
core::arch::asm!("
lea rax, [rip + 2f]
mov fs:[{tcb_sc_off} + {sc_saved_rip}], rax
jmp __relibc_internal_sigentry
2:
",
out("rax") _,
tcb_sc_off = const offset_of!(crate::Tcb, os_specific) + offset_of!(RtSigarea, control),
sc_saved_rip = const offset_of!(Sigcontrol, saved_ip),
);
}
/// Get current stack pointer, weak granularity guarantees.
pub fn current_sp() -> usize {
let sp: usize;
unsafe {
core::arch::asm!("mov {}, rsp", out(reg) sp);
}
sp
}
static PROC_CALL_SIGDEQ: u64 = ProcCall::Sigdeq as u64;
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
-313
View File
@@ -1,313 +0,0 @@
#![no_std]
#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]
#![feature(core_intrinsics, int_roundings, slice_ptr_get, sync_unsafe_cell)]
#![forbid(unreachable_patterns)]
use core::cell::UnsafeCell;
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
use generic_rt::ExpectTlsFree; // not used on aarch64 or riscv64
use generic_rt::GenericTcb;
use redox_protocols::protocol::ProcMeta;
use syscall::Sigcontrol;
use self::{
proc::{FdGuard, FdGuardUpper, STATIC_PROC_INFO},
sync::Mutex,
};
extern crate alloc;
#[macro_export]
macro_rules! asmfunction(
($name:ident $(($($arg:ty),*))? $(-> $ret:ty)? : [$($asmstmt:expr),*$(,)?] <= [$($decl:ident = $(sym $symname:ident)?$(const $constval:expr)?),*$(,)?]$(,)? ) => {
::core::arch::global_asm!(concat!("
.p2align 4
.section .text.", stringify!($name), ", \"ax\", @progbits
.globl ", stringify!($name), "
.type ", stringify!($name), ", @function
", stringify!($name), ":
", $($asmstmt, "\n",)* "
.size ", stringify!($name), ", . - ", stringify!($name), "
"), $($decl = $(sym $symname)?$(const $constval)?),*);
unsafe extern "C" {
pub fn $name($($(_: $arg),*)?) $(-> $ret)?;
}
}
);
pub mod arch;
pub mod proc;
// TODO: Replace auxvs with a non-stack-based interface, but keep getauxval for compatibility
#[path = "../../src/platform/auxv_defs.rs"]
pub mod auxv_defs;
pub mod signal;
pub mod sync;
pub mod sys;
pub mod thread;
#[derive(Debug, Default)]
pub struct RtTcb {
pub control: Sigcontrol,
pub arch: UnsafeCell<crate::arch::SigArea>,
pub thr_fd: UnsafeCell<Option<FdGuardUpper>>,
}
impl RtTcb {
pub fn current() -> &'static Self {
unsafe { &Tcb::current().unwrap().os_specific }
}
pub fn thread_fd(&self) -> &FdGuardUpper {
unsafe { (&*self.thr_fd.get()).as_ref().unwrap() }
}
}
pub type Tcb = GenericTcb<RtTcb>;
/// OS and architecture specific code to activate TLS - Redox aarch64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "aarch64")]
pub unsafe fn tcb_activate(_tcb: &RtTcb, tls_end: usize, tls_len: usize) {
// Uses ABI page
let abi_ptr = tls_end - tls_len - 16;
core::ptr::write(abi_ptr as *mut usize, tls_end);
core::arch::asm!(
"msr tpidr_el0, {}",
in(reg) abi_ptr,
);
}
/// OS and architecture specific code to activate TLS - Redox x86
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "x86")]
pub unsafe fn tcb_activate(tcb: &RtTcb, tls_end: usize, _tls_len: usize) {
let mut env = syscall::EnvRegisters::default();
let file = tcb
.thread_fd()
.dup(b"regs/env")
.expect_notls("failed to open handle for process registers");
file.read(&mut env).expect_notls("failed to read gsbase");
env.gsbase = tls_end as u32;
file.write(&env).expect_notls("failed to write gsbase");
}
/// OS and architecture specific code to activate TLS - Redox x86_64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "x86_64")]
pub unsafe fn tcb_activate(tcb: &RtTcb, tls_end_and_tcb_start: usize, _tls_len: usize) {
let mut env = syscall::EnvRegisters::default();
let file = tcb
.thread_fd()
.dup(b"regs/env")
.expect_notls("failed to open handle for process registers");
file.read(&mut env).expect_notls("failed to read fsbase");
env.fsbase = tls_end_and_tcb_start as u64;
file.write(&env).expect_notls("failed to write fsbase");
}
/// OS and architecture specific code to activate TLS - Redox riscv64
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(target_arch = "riscv64")]
pub unsafe fn tcb_activate(_tcb: &RtTcb, tls_end: usize, tls_len: usize) {
// tp points to static tls block
// FIXME limited to a single initial master
let tls_start = tls_end - tls_len;
let abi_ptr = tls_start - 8;
core::ptr::write(abi_ptr as *mut usize, tls_end);
core::arch::asm!(
"mv tp, {}",
in(reg) tls_start
);
}
/// Initialize redox-rt in situations where relibc is not used
#[allow(unsafe_op_in_unsafe_fn)]
#[cfg(not(feature = "proc"))]
pub unsafe fn initialize_freestanding(this_thr_fd: FdGuardUpper) -> &'static FdGuardUpper {
// TODO: This code is a hack! Integrate the ld_so TCB code into generic-rt, and then use that
// (this function will need pointers to the ELF structs normally passed in auxvs), so the TCB
// is initialized properly.
// TODO: TLS
let page = {
&mut *(syscall::fmap(
!0,
&syscall::Map {
offset: 0,
size: syscall::PAGE_SIZE,
flags: syscall::MapFlags::PROT_READ
| syscall::MapFlags::PROT_WRITE
| syscall::MapFlags::MAP_PRIVATE,
address: 0,
},
)
.unwrap() as *mut Tcb)
};
page.tcb_ptr = page;
page.tcb_len = syscall::PAGE_SIZE;
page.tls_end = (page as *mut Tcb).cast();
// Make sure to use ptr::write to prevent dropping the existing FdGuard
page.os_specific.thr_fd.get().write(Some(this_thr_fd));
#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
unsafe {
let tcb_addr = page as *mut Tcb as usize;
tcb_activate(&page.os_specific, tcb_addr, 0)
}
#[cfg(target_arch = "aarch64")]
unsafe {
let abi_ptr = core::ptr::addr_of_mut!(page.tcb_ptr);
core::arch::asm!("msr tpidr_el0, {}", in(reg) abi_ptr);
}
#[cfg(target_arch = "riscv64")]
unsafe {
let abi_ptr = core::ptr::addr_of_mut!(page.tcb_ptr) as usize;
core::arch::asm!("mv tp, {}", in(reg) (abi_ptr + 8));
}
initialize();
(*page.os_specific.thr_fd.get()).as_ref().unwrap()
}
pub(crate) fn read_proc_meta(proc: &FdGuardUpper) -> syscall::Result<ProcMeta> {
let mut bytes = [0_u8; size_of::<ProcMeta>()];
proc.read(&mut bytes)?;
Ok(*plain::from_bytes::<ProcMeta>(&bytes).unwrap())
}
pub unsafe fn initialize(
#[cfg(feature = "proc")] proc_fd: FdGuardUpper,
#[cfg(feature = "proc")] ns_fd: Option<FdGuardUpper>,
) {
#[cfg(feature = "proc")]
let metadata = read_proc_meta(&proc_fd).unwrap();
#[cfg(not(feature = "proc"))]
// Bootstrap mode, don't associate proc fds with PIDs
let metadata = ProcMeta::default();
#[cfg(feature = "proc")]
{
unsafe { crate::arch::PROC_FD.get().write(proc_fd.as_raw_fd()) };
}
unsafe {
STATIC_PROC_INFO.get().write(StaticProcInfo {
pid: metadata.pid,
#[cfg(feature = "proc")]
proc_fd: Some(proc_fd),
#[cfg(not(feature = "proc"))]
proc_fd: None,
})
};
#[cfg(feature = "proc")]
{
*DYNAMIC_PROC_INFO.lock() = DynamicProcInfo {
pgid: metadata.pgid,
ruid: metadata.ruid,
euid: metadata.euid,
suid: metadata.suid,
egid: metadata.egid,
rgid: metadata.rgid,
sgid: metadata.sgid,
ns_fd,
};
}
}
pub(crate) struct StaticProcInfo {
pid: u32,
proc_fd: Option<FdGuardUpper>,
}
pub struct DynamicProcInfo {
pub pgid: u32,
pub euid: u32,
pub suid: u32,
pub ruid: u32,
pub egid: u32,
pub rgid: u32,
pub sgid: u32,
pub ns_fd: Option<FdGuardUpper>,
}
static DYNAMIC_PROC_INFO: Mutex<DynamicProcInfo> = Mutex::new(DynamicProcInfo {
pgid: u32::MAX,
ruid: u32::MAX,
euid: u32::MAX,
suid: u32::MAX,
rgid: u32::MAX,
egid: u32::MAX,
sgid: u32::MAX,
ns_fd: None,
});
#[inline]
pub(crate) fn static_proc_info() -> &'static StaticProcInfo {
unsafe { &*STATIC_PROC_INFO.get() }
}
#[inline]
pub fn current_proc_fd() -> &'static FdGuardUpper {
let info = static_proc_info();
info.proc_fd.as_ref().unwrap()
}
#[inline]
pub fn current_namespace_fd() -> syscall::Result<usize> {
DYNAMIC_PROC_INFO
.lock()
.ns_fd
.as_ref()
.map(|g| g.as_raw_fd())
.ok_or(syscall::Error::new(syscall::ENOENT))
}
struct ChildHookCommonArgs {
new_thr_fd: FdGuard,
new_proc_fd: Option<FdGuard>,
}
unsafe fn child_hook_common(args: ChildHookCommonArgs) {
let new_thr_fd = args.new_thr_fd.to_upper().unwrap();
let new_proc_fd = args.new_proc_fd.map(|x| x.to_upper().unwrap());
// TODO: just pass PID to child rather than obtaining it via IPC?
#[cfg(feature = "proc")]
let metadata = read_proc_meta(
new_proc_fd
.as_ref()
.expect("must be present with proc feature"),
)
.unwrap();
#[cfg(not(feature = "proc"))]
let metadata = ProcMeta::default();
if let Some(proc_fd) = &new_proc_fd {
unsafe { crate::arch::PROC_FD.get().write(proc_fd.as_raw_fd()) };
}
let old_proc_fd = unsafe {
STATIC_PROC_INFO
.get()
.replace(StaticProcInfo {
pid: metadata.pid,
proc_fd: new_proc_fd,
})
.proc_fd
};
drop(old_proc_fd);
let old_thr_fd = unsafe { RtTcb::current().thr_fd.get().replace(Some(new_thr_fd)) };
drop(old_thr_fd);
}
-1190
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-68
View File
@@ -1,68 +0,0 @@
// TODO: Share code for simple futex-based mutex between relibc's Mutex<()> and this.
use core::{
cell::UnsafeCell,
ops::{Deref, DerefMut},
sync::atomic::{AtomicU32, Ordering},
};
pub struct Mutex<T> {
pub lockword: AtomicU32,
pub inner: UnsafeCell<T>,
}
unsafe impl<T: Send> Send for Mutex<T> {}
unsafe impl<T: Send> Sync for Mutex<T> {}
impl<T> Mutex<T> {
/// Represents an unlocked [Mutex].
pub const UNLOCKED: u32 = 0;
/// Represents a locked [Mutex].
pub const LOCKED: u32 = 1;
/// Represents a waiting [Mutex].
pub const WAITING: u32 = 2;
pub const fn new(t: T) -> Self {
Self {
lockword: AtomicU32::new(0),
inner: UnsafeCell::new(t),
}
}
pub fn lock(&self) -> MutexGuard<'_, T> {
while self
.lockword
.compare_exchange(
Self::UNLOCKED,
Self::LOCKED,
Ordering::Acquire,
Ordering::Relaxed,
)
.is_err()
{
core::hint::spin_loop();
}
MutexGuard { lock: self }
}
}
pub struct MutexGuard<'l, T> {
lock: &'l Mutex<T>,
}
impl<T> Deref for MutexGuard<'_, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.lock.inner.get() }
}
}
impl<T> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.lock.inner.get() }
}
}
impl<T> Drop for MutexGuard<'_, T> {
fn drop(&mut self) {
self.lock
.lockword
.store(Mutex::<T>::UNLOCKED, Ordering::Release);
}
}
-569
View File
@@ -1,569 +0,0 @@
use core::{
mem::{replace, size_of},
ptr::addr_of,
sync::atomic::{AtomicU32, Ordering},
};
use ioslice::IoSlice;
use syscall::{
CallFlags, EINVAL, ERESTART, StdFsCallKind, TimeSpec,
data::StdFsCallMeta,
error::{self, EINTR, ENODEV, ESRCH, Error, Result},
};
use crate::{
DYNAMIC_PROC_INFO, DynamicProcInfo, RtTcb, Tcb,
arch::manually_enter_trampoline,
proc::{FdGuard, FdGuardUpper},
read_proc_meta,
signal::tmp_disable_signals,
};
use alloc::vec::Vec;
use redox_protocols::protocol::{
NsDup, ProcCall, ProcKillTarget, RtSigInfo, ThreadCall, WaitFlags,
};
#[inline]
fn wrapper<T>(restart: bool, erestart: bool, mut f: impl FnMut() -> Result<T>) -> Result<T> {
loop {
let _guard = tmp_disable_signals();
let rt_sigarea = unsafe { &Tcb::current().unwrap().os_specific };
let res = f();
let code = if erestart { ERESTART } else { EINTR };
if let Err(err) = res
&& err == Error::new(code)
{
unsafe {
manually_enter_trampoline();
}
if restart && unsafe { (*rt_sigarea.arch.get()).last_sig_was_restart } {
continue;
}
}
return res;
}
}
// TODO: uninitialized memory?
#[inline]
pub fn posix_read(fd: usize, buf: &mut [u8]) -> Result<usize> {
wrapper(true, false, || syscall::read(fd, buf))
}
#[inline]
pub fn posix_write(fd: usize, buf: &[u8]) -> Result<usize> {
wrapper(true, false, || syscall::write(fd, buf))
}
#[inline]
pub fn posix_kill(target: ProcKillTarget, sig: usize) -> Result<()> {
if sig > 64 {
return Err(Error::new(EINVAL));
}
match wrapper(false, true, || {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Kill as u64, target.raw() as u64, sig as u64],
)
}) {
Ok(_) | Err(Error { errno: ERESTART }) => Ok(()),
Err(error) => Err(error),
}
}
#[inline]
pub fn posix_sigqueue(pid: usize, sig: usize, arg: usize) -> Result<()> {
let target = ProcKillTarget::from_raw(pid);
if !matches!(target, ProcKillTarget::SingleProc(_)) {
return Err(Error::new(ESRCH));
}
if sig <= 32 {
return posix_kill(target, sig);
}
let mut siginf = RtSigInfo {
arg,
code: -1, // TODO: SI_QUEUE constant
uid: 0, // TODO
pid: posix_getpid(),
};
match wrapper(false, true, || {
this_proc_call(
unsafe { plain::as_mut_bytes(&mut siginf) },
CallFlags::empty(),
&[ProcCall::Sigq as u64, pid as u64, sig as u64],
)
}) {
Ok(_)
| Err(Error {
errno: error::ERESTART,
}) => Ok(()),
Err(error) => Err(error),
}
}
#[inline]
pub fn posix_getpid() -> u32 {
// SAFETY: read-only except during program/fork child initialization
unsafe { addr_of!((*crate::STATIC_PROC_INFO.get()).pid).read() }
}
#[inline]
pub fn posix_getppid() -> u32 {
this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Getppid as u64]).expect("cannot fail")
as u32
}
#[inline]
pub fn posix_setpriority(which: i32, who: u32, prio: u32) -> Result<(), syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL)); // TODO: Add support for PRIO_PGRP and PRIO_PROCESS
}
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::SetProcPriority as u64, who as u64, prio as u64],
)?;
Ok(())
}
#[inline]
pub fn posix_getpriority(which: i32, who: u32) -> Result<u32, syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL));
}
let res = this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::GetProcPriority as u64, who as u64],
)?;
Ok(res as u32)
}
#[inline]
pub unsafe fn sys_futex_wait(addr: *mut u32, val: u32, deadline: Option<&TimeSpec>) -> Result<()> {
wrapper(true, false, || {
unsafe {
syscall::syscall5(
syscall::SYS_FUTEX,
addr as usize,
syscall::FUTEX_WAIT,
val as usize,
deadline.map_or(0, |d| d as *const _ as usize),
0,
)
}
.map(|_| ())
})
}
#[inline]
pub unsafe fn sys_futex_wake(addr: *mut u32, num: u32) -> Result<u32> {
unsafe {
syscall::syscall5(
syscall::SYS_FUTEX,
addr as usize,
syscall::FUTEX_WAKE,
num as usize,
0,
0,
)
}
.map(|awoken| awoken as u32)
}
unsafe fn raw_sys_call(
fd: usize,
payload_ptr: *const u8,
len: usize,
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
syscall::syscall5(
syscall::SYS_CALL,
fd,
payload_ptr as usize,
len,
metadata.len() | flags.bits(),
metadata.as_ptr() as usize,
)
}
}
pub fn sys_call_ro(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ,
metadata,
)
}
}
pub fn sys_call_wo(fd: usize, payload: &[u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_ptr(),
payload.len(),
flags | CallFlags::WRITE,
metadata,
)
}
}
pub fn sys_call_rw(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe {
raw_sys_call(
fd,
payload.as_mut_ptr(),
payload.len(),
flags | CallFlags::READ | CallFlags::WRITE,
metadata,
)
}
}
pub fn sys_call(
fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
unsafe { raw_sys_call(fd, payload.as_mut_ptr(), payload.len(), flags, metadata) }
}
pub fn this_proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
proc_call(
crate::current_proc_fd().as_raw_fd(),
payload,
flags,
metadata,
)
}
pub fn proc_call(
proc_fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
sys_call(proc_fd, payload, flags, metadata)
}
pub fn thread_call(
thread_fd: usize,
payload: &mut [u8],
flags: CallFlags,
metadata: &[u64],
) -> Result<usize> {
sys_call(thread_fd, payload, flags, metadata)
}
pub fn this_thread_call(payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result<usize> {
thread_call(
RtTcb::current().thread_fd().as_raw_fd(),
payload,
flags,
metadata,
)
}
#[derive(Clone, Copy, Debug)]
pub enum WaitpidTarget {
AnyChild,
AnyGroupMember,
SingleProc { pid: usize },
ProcGroup { pgid: usize },
}
impl WaitpidTarget {
pub fn from_posix_arg(raw: isize) -> Self {
match raw {
0 => Self::AnyGroupMember,
-1 => Self::AnyChild,
1.. => Self::SingleProc { pid: raw as usize },
..-1 => Self::ProcGroup {
pgid: -raw as usize,
},
}
}
}
pub fn sys_waitpid(target: WaitpidTarget, status: &mut usize, flags: WaitFlags) -> Result<usize> {
let (call, pid) = match target {
WaitpidTarget::AnyChild => (ProcCall::Waitpid, 0),
WaitpidTarget::SingleProc { pid } => (ProcCall::Waitpid, pid),
WaitpidTarget::AnyGroupMember => (ProcCall::Waitpgid, 0),
WaitpidTarget::ProcGroup { pgid } => (ProcCall::Waitpgid, pgid),
};
wrapper(true, false, || {
this_proc_call(
unsafe { plain::as_mut_bytes(status) },
CallFlags::empty(),
&[call as u64, pid as u64, flags.bits() as u64],
)
})
}
pub fn posix_kill_thread(thread_fd: usize, signal: u32) -> Result<()> {
// TODO: don't hardcode?
if signal > 64 {
return Err(Error::new(EINVAL));
}
match wrapper(false, true, || {
thread_call(
thread_fd,
&mut [],
CallFlags::empty(),
&[ThreadCall::SignalThread as u64, signal.into()],
)
}) {
Ok(_) | Err(Error { errno: ERESTART }) => Ok(()),
Err(error) => Err(error),
}
}
static UMASK: AtomicU32 = AtomicU32::new(0o022);
/// Controls the set of bits removed from the `mode` mask when new file descriptors are created.
///
/// Must be validated by the caller
//
// TODO: validate here?
#[inline]
pub fn swap_umask(mask: u32) -> u32 {
UMASK.swap(mask, Ordering::AcqRel)
}
#[inline]
pub fn get_umask() -> u32 {
UMASK.load(Ordering::Acquire)
}
/// Real/Effective/Set-User/Group ID
pub struct Resugid<T> {
pub ruid: T,
pub euid: T,
pub suid: T,
pub rgid: T,
pub egid: T,
pub sgid: T,
}
/// Sets [res][ug]id, fields that are None will be unchanged.
pub fn posix_setresugid(ids: &Resugid<Option<u32>>) -> Result<()> {
// TODO: not sure how "tmp" an IPC call is?
let _sig_guard = tmp_disable_signals();
let mut guard = DYNAMIC_PROC_INFO.lock();
let mut buf = [0_u8; size_of::<u32>() * 6];
plain::slice_from_mut_bytes(&mut buf)
.unwrap()
.copy_from_slice(&[
ids.ruid.unwrap_or(u32::MAX),
ids.euid.unwrap_or(u32::MAX),
ids.suid.unwrap_or(u32::MAX),
ids.rgid.unwrap_or(u32::MAX),
ids.egid.unwrap_or(u32::MAX),
ids.sgid.unwrap_or(u32::MAX),
]);
this_proc_call(&mut buf, CallFlags::empty(), &[ProcCall::SetResugid as u64])?;
if let Some(ruid) = ids.ruid {
guard.ruid = ruid;
}
if let Some(euid) = ids.euid {
guard.euid = euid;
}
if let Some(suid) = ids.suid {
guard.suid = suid;
}
if let Some(rgid) = ids.rgid {
guard.rgid = rgid;
}
if let Some(egid) = ids.egid {
guard.egid = egid;
}
if let Some(sgid) = ids.sgid {
guard.sgid = sgid;
}
Ok(())
}
pub fn posix_getresugid() -> Resugid<u32> {
let _sig_guard = tmp_disable_signals();
let DynamicProcInfo {
ruid,
euid,
suid,
rgid,
egid,
sgid,
..
} = *DYNAMIC_PROC_INFO.lock();
Resugid {
ruid,
euid,
suid,
rgid,
egid,
sgid,
}
}
pub fn getens() -> Result<usize> {
read_proc_meta(crate::current_proc_fd()).map(|meta| meta.ens as usize)
}
pub fn get_proc_credentials(cap_fd: usize, target_pid: usize, buf: &mut [u8]) -> Result<usize> {
if buf.len() < size_of::<redox_protocols::protocol::ProcMeta>() {
return Err(Error::new(EINVAL));
}
proc_call(
cap_fd,
buf,
CallFlags::empty(),
&[ProcCall::GetProcCredentials as u64, target_pid as u64],
)
}
pub fn posix_exit(status: i32) -> ! {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Exit as u64, (status & 0xFF) as u64],
)
.expect("failed to call proc mgr with Exit");
let _ = syscall::write(1, b"redox-rt: ProcCall::Exit FAILED, abort()ing!\n");
core::intrinsics::abort();
}
pub fn posix_getpgid(pid: usize) -> Result<usize> {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Setpgid as u64, pid as u64, u64::wrapping_neg(1)],
)
}
pub fn posix_setpgid(pid: usize, pgid: usize) -> Result<()> {
if pgid == usize::wrapping_neg(1) {
return Err(Error::new(EINVAL));
}
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Setpgid as u64, pid as u64, pgid as u64],
)?;
Ok(())
}
pub fn posix_getsid(pid: usize) -> Result<usize> {
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::Getsid as u64, pid as u64],
)
}
pub fn posix_setsid() -> Result<u32> {
this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Setsid as u64])?;
Ok(posix_getpid())
}
pub fn posix_nanosleep(rqtp: &TimeSpec, rmtp: &mut TimeSpec) -> Result<()> {
wrapper(false, false, || syscall::nanosleep(rqtp, rmtp))?;
Ok(())
}
pub fn setns(fd: usize) -> Option<FdGuardUpper> {
let mut info = DYNAMIC_PROC_INFO.lock();
let new_fd_guard = FdGuard::new(fd).to_upper().unwrap();
let old_fd_guard = replace(&mut info.ns_fd, Some(new_fd_guard));
old_fd_guard
}
pub fn getns() -> Result<usize> {
let cur_ns = crate::current_namespace_fd()?;
if cur_ns == usize::MAX {
Err(Error::new(ENODEV))
} else {
Ok(cur_ns)
}
}
pub fn open<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
let path = path.as_ref();
let fcntl_flags = flags & syscall::O_FCNTL_MASK;
unsafe {
syscall::syscall5(
syscall::SYS_OPENAT,
crate::current_namespace_fd()?,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
)
}
}
pub fn openat<T: AsRef<str>>(
fd: usize,
path: T,
flags: usize,
fcntl_flags: usize,
) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall::syscall5(
syscall::SYS_OPENAT,
fd,
path.as_ptr() as usize,
path.len(),
flags,
fcntl_flags,
)
}
}
pub fn unlink<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
let path = path.as_ref();
unsafe {
syscall::syscall4(
syscall::SYS_UNLINKAT,
crate::current_namespace_fd()?,
path.as_ptr() as usize,
path.len(),
flags,
)
}
}
pub fn mkns(names: &[IoSlice]) -> Result<FdGuardUpper> {
let mut buf = Vec::from((NsDup::ForkNs as usize).to_ne_bytes());
for name in names {
let name_bytes = name.as_slice();
let len = name_bytes.len();
let _scheme_name = core::str::from_utf8(name_bytes).map_err(|_| Error::new(EINVAL))?;
buf.extend_from_slice(&len.to_ne_bytes());
buf.extend_from_slice(name_bytes);
}
FdGuard::new(syscall::dup(crate::current_namespace_fd()?, &buf)?).to_upper()
}
pub fn register_scheme_to_ns(ns_fd: usize, name: &str, cap_fd: usize) -> Result<()> {
let mut buf = alloc::vec::Vec::from((NsDup::IssueRegister as usize).to_ne_bytes());
buf.extend_from_slice(name.as_bytes());
let ns_this_scheme = FdGuard::new(syscall::dup(ns_fd, &buf)?);
let cap_bytes = cap_fd.to_ne_bytes();
ns_this_scheme.call_wo(&cap_bytes, CallFlags::FD, &[])?;
Ok(())
}
pub fn std_fs_call_ro(fd: usize, payload: &mut [u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_ro(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn std_fs_call_wo(fd: usize, payload: &[u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_wo(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn std_fs_call_rw(fd: usize, payload: &mut [u8], metadata: &StdFsCallMeta) -> Result<usize> {
sys_call_rw(fd, payload, CallFlags::STD_FS, metadata)
}
pub fn fstat(fd: usize, stat: &mut syscall::Stat) -> Result<usize> {
std_fs_call_ro(fd, stat, &StdFsCallMeta::new(StdFsCallKind::Fstat, 0, 0))
}
pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result<usize> {
let _siglock = tmp_disable_signals();
let raw_fd = syscall::fcntl(fd, cmd, arg)?;
Ok(FdGuard::new(raw_fd).as_raw_fd())
}
-70
View File
@@ -1,70 +0,0 @@
use core::mem::size_of;
use syscall::Result;
use crate::{RtTcb, arch::*, proc::*, signal::tmp_disable_signals, static_proc_info};
/// Spawns a new context sharing the same address space as the current one (i.e. a new thread).
pub unsafe fn rlct_clone_impl(stack: *mut usize, tcb: &RtTcb) -> Result<usize> {
let proc_info = static_proc_info();
let cur_proc_fd = proc_info.proc_fd.as_ref().unwrap();
let cur_thr_fd = RtTcb::current().thread_fd();
let new_thr_fd = cur_proc_fd.dup(b"new-thread")?.to_upper().unwrap();
// Inherit existing address space
{
let cur_addr_space_fd = cur_thr_fd.dup(b"addrspace")?;
let new_addr_space_sel_fd = new_thr_fd.dup(b"current-addrspace")?;
let buf = create_set_addr_space_buf(
cur_addr_space_fd.as_raw_fd(),
__relibc_internal_rlct_clone_ret as *const () as usize,
stack as usize,
);
new_addr_space_sel_fd.write(&buf)?;
}
// Inherit reference to file table
{
let cur_filetable_fd = cur_thr_fd.dup(b"filetable")?;
let new_filetable_sel_fd = new_thr_fd.dup(b"current-filetable")?;
new_filetable_sel_fd.write(&usize::to_ne_bytes(cur_filetable_fd.as_raw_fd()))?;
}
// Since the signal handler is not yet initialized, signals specifically targeting the thread
// (relibc is only required to implement thread-specific signals that already originate from
// the same process) will be discarded. Process-specific signals will ignore this new thread,
// until it has initialized its own signal handler.
let start_fd = new_thr_fd.dup(b"start")?;
let fd = new_thr_fd.as_raw_fd();
unsafe {
tcb.thr_fd.get().write(Some(new_thr_fd));
}
// Unblock context.
start_fd.write(&[0])?;
Ok(fd)
}
pub unsafe fn exit_this_thread(stack_base: *mut (), stack_size: usize) -> ! {
let _guard = tmp_disable_signals();
let tcb = RtTcb::current();
// TODO: modify interface so it writes directly to the thread fd?
let status_fd = tcb.thread_fd().dup(b"status").unwrap();
let _ = unsafe { syscall::funmap(tcb as *const RtTcb as usize, syscall::PAGE_SIZE) };
let mut buf = [0; size_of::<usize>() * 3];
plain::slice_from_mut_bytes(&mut buf)
.unwrap()
.copy_from_slice(&[usize::MAX, stack_base as usize, stack_size]);
// TODO: SYS_CALL w/CONSUME
status_fd.write(&buf).unwrap();
unreachable!()
}
-58
View File
@@ -1,58 +0,0 @@
#!/usr/bin/env bash
set -e
target=$1
deps_dir=$2
if [ -z "$target" ] || [ -z "$deps_dir" ]; then
echo "Usage:\n\t./renamesyms.sh TARGET DEPS_DIR"
exit 1
fi
if [ ! -f "$target" ]; then
echo "Target file '$target' does not exist"
exit 1
fi
if [ ! -d "$deps_dir" ] ; then
echo "Deps dir '$deps_dir' does not exist or not a directory"
exit 1
fi
symbols_file=`mktemp`
special_syms=(
__rdl_oom
__rg_alloc
__rg_alloc_zeroed
__rg_dealloc
__rg_oom
__rg_realloc
__rust_alloc
__rust_alloc_error_handler
__rust_alloc_error_handler_should_panic
__rust_alloc_zeroed
__rust_dealloc
__rust_no_alloc_shim_is_unstable
__rust_realloc
)
for dep in `find $deps_dir -type f -name "*.rlib"`; do
"${NM}" --format=posix -g "$dep" 2>/dev/null | sed 's/.*:.*//g' | awk '{if ($2 == "T") print $1}' | sed 's/^\(.*\)$/\1 __relibc_\1/g' >> $symbols_file
done
for special_sym in "${special_syms[@]}"; do
echo "$special_sym __relibc_$special_sym" >> $symbols_file
done
mangled_alloc_syms=$("${NM}" --format=posix -g "$target" 2>/dev/null | awk '{print $1}' | grep "7___rustc" || true)
for sym in $mangled_alloc_syms; do
echo "$sym __relibc_$sym" >> $symbols_file
done
sorted_file=`mktemp`
sort -u "$symbols_file" > "$sorted_file"
rm -f "$symbols_file"
"${OBJCOPY}" --redefine-syms="$sorted_file" "$target"
rm -f "$sorted_file"
BIN
View File
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More