aboutsummaryrefslogtreecommitdiff
path: root/pk
AgeCommit message (Collapse)AuthorFilesLines
2024-05-20Use kassert in load_elf (#327)Zixian Cai1-3/+3
Signed-off-by: Zixian Cai <2891235+caizixian@users.noreply.github.com>
2024-05-20Implementation of riscv_hwprobe syscall from Linux (#325)Wojciech Muła2-0/+52
See: https://www.kernel.org/doc/html/latest/arch/riscv/hwprobe.html
2024-05-20mprotect whole ELF segment, not just file portionAndrew Waterman1-3/+3
2024-05-20Don't mmap ELF segments with zero fileszAndrew Waterman1-2/+4
2024-05-20Add ELF header sanity checkAndrew Waterman1-0/+2
2024-05-20Implement syscall readlinkat and readv (#318)mylai-mtk2-0/+88
* Implement syscall readlinkat * Implement syscall readv by read syscalls Since pk lacks kernel-space dynamic memory management, we implement readv with normal read syscalls rather than forwarding it to spike
2024-02-15Zicfilp: Handle software check exception -- landing pad faultMing-Yi Lai1-0/+16
2024-02-15Zicfilp: Support enabling userspace Zicfilp mechanismMing-Yi Lai1-0/+9
2023-05-01pk: fix __do_brk when new addr is not feasible (#295)xukl2-7/+3
Linux kernel simply return current brk when request brk addr is not feasible. The pk should probably do the same.
2022-08-05Specify text section in rest_of_boot_loader definitionAndrew Waterman1-1/+3
Fixes #282
2022-04-30Fix a file leak in function `at_kfd` (#276)MaxXing1-1/+3
2022-04-11Handle unimplemented syscalls gracefullyAndrew Waterman1-11/+1
We previously kernel-panicked because that made it more obvious when a syscall implementation was missing. These days, it's more common that the C library will do something sensible in response to returning -ENOSYS. Favor that approach to avoid frustrating users.
2022-04-08Stub out sysinfo syscallAndrew Waterman2-0/+2
2022-02-08Fix local variable register usage for ra (#268)Fangrui Song1-2/+1
See https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables "Other than when invoking the Extended asm, the contents of the specified register are not guaranteed." Also revert 90191ad93eac47d61ab9cc89084050ad1541d160.
2022-01-28pk: thwart an attempt from the compiler to optimizeSaleem Abdulrasool1-1/+2
The memory manager maintains the first free page as the page after the `_end` synthetic emitted by the linker. This value is stored in a translation unit local variable. This value is only ever written to from `init_early_alloc` which is static and only ever invoked from `pk_vm_init`. Furthermore, the value that `first_free_page` is ever set to is computed as a rounding of the _address_ of `_end`. Because the address of the symbol cannot change during execution of a normal program, this is effectively a constant, making the computed value a "constant" which can be re-materialized. Now, with the knowledge that the value is effectively a constant that can be re-materialized and the fact that the value is ever written to at a single position, we can simply re-materialize the value if it was ever changed in `free_page_addr`. This will allow the 8-byte value to be truncated to 1-byte. Now, we can inline `__early_pgalloc_align`, and because the combination of `__early_alloc` and `__early_pgalloc_align` is small, we can inline that again at the two sites locally. This changes the `__augment_page_freelist` to re-materialize the constant when needed for the allocation. The re-materialization however uses a pc-relative addressing, which now computes a different value than expected - the address has become a VA rather than a PA. This results in the address computed by `free_page_addr` (which is the result of the `__early_pgalloc_align`) to be a virtual address after the relocation, which then propagates through `__early_alloc` to the value in `__augment_page_freelist`, which is then consumed by `__page_alloc`, which will treat the now VA as a PA and perform an additional translation to a VA. Mark the value as `volatile` to indicate that the value must be read at all points to thwart the size optimization of the compiler resulting in a mis-compilation resulting in the eventual invalid memory access during the `memset` that follows the allocation. Thanks to @nzmichaelh for the help in tracking this down!
2022-01-09fix file leakAndrew Waterman1-1/+1
Eliminate excess reference count when associating fd with file. Fixes #258
2021-08-27pk: correct the handling of SYS_getcwd (#250)Saleem Abdulrasool1-1/+1
`SYS_getcwd` is different from `getcwd` in that the return value is < 0 on failure otherwise it is the length of the string. The proxy kernel was treating 0 as success and all other values as error. As a result, we would never return a valid value for `getcwd`. The following program now executes properly with the Proxy Kernel: ```c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <linux/limits.h> int main(int argc, char **argv) { unsigned char buffer[PATH_MAX + 1] = {0}; if (getcwd(buffer, PATH_MAX)) printf("cwd: %s\n", buffer); return EXIT_SUCCESS; } ```
2021-05-18Add __early_pgalloc_align; refactor __early_alloc to use itAndrew Waterman1-3/+11
2021-05-18Fix range checkAndrew Waterman1-2/+3
2021-05-07pk: make breakpoints fatalAndrew Waterman1-2/+1
Resolves #216
2021-05-05replace `spbtr` with `satp` (#241)Saleem Abdulrasool1-1/+1
The LLVM IAS currently does not support the older spelling for the CSR. Update the references to the modern name.
2021-05-05replace `sbadaddr` with `stval` (#243)Saleem Abdulrasool1-1/+1
This replaces use of the old `sbadaddr` CSR name with the current `stval` name. The old spelling is not supported by the LLVM IAS, however, the modern spelling is supported by both LLVM and binutils.
2021-04-28pk: Fix __clear_cache() compilation issue with recent compilers (#240)Christoph Müllner1-1/+2
Using recent compilers we get the following error message: ../pk/pk.c: In function 'run_loaded_program.constprop': ../pk/pk.c:177:3: error: both arguments to '__builtin___clear_cache' must be pointers 177 | __clear_cache(0, 0); | ^~~~~~~~~~~~~~~~~~~ Let's use the existing function __riscv_flush_icache(), give it a header with a prototype and use it to emits the FENCE.I instruction directly. See #239 Suggested-by: Andrew Waterman <andrew@sifive.com> Signed-off-by: Christoph Muellner <cmuellner@linux.com>
2021-03-29pk: vm cleanups; use narrower TLB flushesAndrew Waterman1-9/+15
2021-03-29pk: remove vestigial trapframe_t::insn fieldAndrew Waterman4-14/+1
This assumes that stval is populated with the opcode on illegal instruction exceptions. But since we're only using the opcode for error reporting, it's OK if this assumption is violated.
2021-03-29M-mode code doesn't need access to pk's page tableAndrew Waterman1-0/+2
2021-03-29pk: correctly restore sstatus.SUM in strcpy_from_userAndrew Waterman1-3/+7
2021-03-26pk: support printk before file initAndrew Waterman2-4/+3
2021-03-26pk: don't init files until VM setup is completeAndrew Waterman1-2/+2
2021-03-25pk: refactor vm free list managementAndrew Waterman4-61/+115
2021-03-25pk: support >2 GiB of user memory for RV64Andrew Waterman7-34/+76
Previously, the pk would always run from virtual address MEM_START. Instead, remap it into the negative virtual addresses, allowing user processes to expand beyond MEM_START.
2021-03-25Add some missing syscall stubsAndrew Waterman2-0/+10
2021-03-25pk: avoid assertion failures on brk syscallsAndrew Waterman1-3/+5
Return the old brk if mmap fails, rather than just asserting out
2021-03-25pk: avoid out-of-memory errorsAndrew Waterman2-50/+107
Estimate available memory and return -1 from mmap if not enough is available, rather than assert-failing.
2021-03-25pk: remove linear VA mapping constraintAndrew Waterman1-46/+83
This will improve flexibility going forward.
2021-03-25pk: only access user memory through explicit accessorsAndrew Waterman9-77/+278
Enforced with sstatus.SUM.
2021-03-25Add `statx` syscall (#234)huaixv3-0/+23
2020-11-29Remove unused file_stat, copy_stat functionsAndrew Waterman4-28/+0
2020-11-29Remove use of copy_stat() from sys_fstat and sys_lstat (#228)Marcus Comstedt1-2/+4
2020-11-23use MEM_START, not DRAM_BASE, for pk mappingsAndrew Waterman2-3/+3
2020-11-17Remove use of copy_stat() from sys_fstatatMarcus Comstedt1-1/+1
The system call should return the stat struct in kernel format, not libc format.
2020-11-11pk: Fix pushing of argc to match linux kernel behaviourMarcus Comstedt1-3/+3
The linux kernel pushes argc as an int, not an uintptr_t. (The offset to the next element is still sizeof(uintptr_t).)
2020-03-16Fix CPI calcualtion for -s option (#192)davidmetz1-1/+1
This attempt at rounding leads to wrong results, for example: 314689951 cycles 314690101 instructions 0.90 CPI With my change results in: 314689951 cycles 314690101 instructions 0.99 CPI I think this was supposed to be part of rounding behaviour but it doesn't work if only the final digit does it and there is no carry... Instead I changed it to truncate after the second digit
2020-01-13Enable vector unit if present (continuation of ↵Andrew Waterman1-1/+1
77a5df569451571d608650a34183d53df99790ec)
2019-10-23Add --help (#179)Luís Marques1-14/+35
2019-10-22Implement dup3 syscall (#162)Luís Marques4-0/+32
2019-10-22Make performance counters always 64 bits wide (#178)Luís Marques4-18/+77
This prevents the counters from easily overflowing for a 32-bit pk.
2019-10-01Only accept statically linked binaries (#176)Luís Marques2-0/+4
2019-06-11configure: Add option to set physical memory start addressGabriel L. Somlo1-1/+1
For systems where physical memory is mapped to a start address different from 0x80000000, allow the default to be overridden using the --with-mem-start argument to the configure script. Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
2019-05-09Allow up to 2 KiB of argumentsAndrew Waterman1-1/+4
Closes #161