mirror of
https://github.com/Noratrieb/libuwuc.git
synced 2026-01-14 11:45:05 +01:00
fix argv handling
This commit is contained in:
parent
21d3f12572
commit
613482b8c4
7 changed files with 28 additions and 5 deletions
|
|
@ -4,7 +4,9 @@ use crate::utils::SharedThinCstr;
|
|||
|
||||
/// The entrypoint of the program.
|
||||
/// This is called by a bit of assembly handling architecture-specific _start.
|
||||
pub(crate) unsafe extern "C" fn start(argc: u64, argv: *const *const c_char, rsp: u64) -> ! {
|
||||
pub(crate) unsafe extern "C" fn start(rsp: u64) -> ! {
|
||||
let argc = (rsp as *const u64).read();
|
||||
let argv = (rsp + 8) as *const *const c_char;
|
||||
let envp = (8 + 8 * argc + rsp + 8) as *mut Option<SharedThinCstr<'static>>;
|
||||
|
||||
crate::env::init(envp);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ core::arch::global_asm!(
|
|||
"mov rbp, 0",
|
||||
// We're off to a good start already.
|
||||
// Pass the variables to the start function arguments.
|
||||
"mov rdi, [rsp]", // &argc = rsp
|
||||
"mov rsi, [rsp+8]", // &argv = rsp+8
|
||||
"mov rdx, rsp",
|
||||
"mov rdi, rsp",
|
||||
|
||||
// The stack will be 16-byte aligned at process entry already.
|
||||
// So we're good to go!
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub unsafe extern "C" fn printf(format: *const u8, mut args: ...) -> c_int {
|
|||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn __fprintf_chk(file: &FileStream, _flag: c_int, format: *const u8, mut args: ...) -> c_int {
|
||||
pub unsafe extern "C" fn __fprintf_chk(_flag: c_int, file: &FileStream, format: *const u8, mut args: ...) -> c_int {
|
||||
let mut sink = WriteCounter(file, 0);
|
||||
|
||||
let result = libuwuc::fmt::printf::printf_generic(
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@
|
|||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||
'';
|
||||
packages = (with pkgs; [
|
||||
gef
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,18 @@ for test in tests/c/*; do
|
|||
exit 1
|
||||
fi
|
||||
|
||||
printf "test $name "
|
||||
|
||||
OUTPUT=$("$test_dir/$name")
|
||||
code="$?"
|
||||
if [ "$code" -ne "0" ]; then
|
||||
echo -e "\e[31mFAIL\e[0m"
|
||||
echo "error: test failed with code $code: $test, running $test_dir/$name"
|
||||
echo "------ output:"
|
||||
echo "$OUTPUT"
|
||||
echo "-----"
|
||||
else
|
||||
echo -e "\e[32mPASS\e[0m"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
|
|||
9
tests/c/argv.c
Normal file
9
tests/c/argv.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
char *self = argv[0];
|
||||
char first = self[0];
|
||||
if (first != '/') {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
8
tests/c/malloc.c
Normal file
8
tests/c/malloc.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include<stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char *alloc = (char*) malloc(10);
|
||||
*alloc = 1;
|
||||
*(alloc + 9) = 2;
|
||||
free(alloc);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue