Aarch64 fix, make i686 compile.

This commit is contained in:
4lDO2
2025-04-14 23:25:47 +02:00
parent 0213ac2d15
commit 2fbbdcc1c9
4 changed files with 66 additions and 28 deletions
+4 -4
View File
@@ -254,9 +254,9 @@ asmfunction!(__relibc_internal_sigentry: ["
add x1, x5, #{tcb_sa_off} + {sa_tmp_rt_inf}
str x2, [x1]
mov x2, #{RTINF_SIZE}
adrp x3, {proc_call}
add x3, x3, :lo12:{proc_call}
mov x4, #1
adrp x4, {proc_call}
add x4, x4, :lo12:{proc_call}
mov x3, #1
svc 0
mov x0, x5 // restore TCB pointer
cbnz x0, 1b
@@ -479,4 +479,4 @@ pub unsafe fn arch_pre(stack: &mut SigStack, os: &mut SigArea) -> PosixStackt {
}
}
pub(crate) static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: &[usize] = &[ProcCall::Sigdeq as usize];
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
+53 -19
View File
@@ -1,9 +1,10 @@
use core::{mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use core::{cell::SyncUnsafeCell, mem::offset_of, ptr::NonNull, sync::atomic::Ordering};
use syscall::*;
use crate::{
proc::{fork_inner, FdGuard},
proc::{fork_inner, FdGuard, ForkArgs},
protocol::{ProcCall, RtSigInfo},
signal::{inner_fastcall, PosixStackt, RtSigarea, SigStack, PROC_CONTROL_STRUCT},
RtTcb,
};
@@ -20,8 +21,11 @@ pub struct SigArea {
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_id_inf: u64,
pub tmp_mm0: u64,
@@ -79,16 +83,30 @@ pub fn copy_env_regs(cur_pid_fd: usize, new_pid_fd: usize) -> Result<()> {
Ok(())
}
unsafe extern "cdecl" fn fork_impl(initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp))
unsafe extern "fastcall" fn fork_impl(args: &ForkArgs, initial_rsp: *mut usize) -> usize {
Error::mux(fork_inner(initial_rsp, args))
}
unsafe extern "cdecl" fn child_hook(cur_filetable_fd: usize, new_pid_fd: usize) {
// TODO: duplicate code with x86_64
unsafe extern "cdecl" fn child_hook(
cur_filetable_fd: usize,
new_proc_fd: usize,
new_thr_fd: usize,
) {
let _ = syscall::close(cur_filetable_fd);
crate::child_hook_common(FdGuard::new(new_pid_fd));
crate::child_hook_common(crate::ChildHookCommonArgs {
new_thr_fd: FdGuard::new(new_thr_fd),
new_proc_fd: if new_proc_fd == usize::MAX {
None
} else {
Some(FdGuard::new(new_proc_fd))
},
});
}
asmfunction!(__relibc_internal_fork_wrapper -> usize: ["
asmfunction!(__relibc_internal_fork_wrapper (usize) -> usize: ["
mov ecx, [esp+4]
push ebp
mov ebp, esp
@@ -103,9 +121,9 @@ asmfunction!(__relibc_internal_fork_wrapper -> usize: ["
//TODO stmxcsr [esp+16]
fnstcw [esp+24]
push esp
mov edx, esp
call {fork_impl}
pop esp
jmp 2f
"] <= [fork_impl = sym fork_impl]);
@@ -137,6 +155,9 @@ asmfunction!(__relibc_internal_sigentry: ["
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]
@@ -176,13 +197,18 @@ asmfunction!(__relibc_internal_sigentry: ["
bt edx, eax
jc 8f
mov edx, ebx
lea ecx, [eax+32]
mov eax, {SYS_SIGDEQUEUE}
mov edx, gs:[0]
add edx, {tcb_sa_off} + {sa_tmp_rt_inf}
// 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}
lea edx, [eax+32]
mov [ecx], edx
mov esi, 1
mov edi, {proc_call}
mov eax, {SYS_CALL}
int 0x80
mov ebx, edx
test eax, eax
jnz 1b
@@ -228,9 +254,9 @@ asmfunction!(__relibc_internal_sigentry: ["
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 ebx
push edi
push esi
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
@@ -286,8 +312,11 @@ __relibc_internal_sigentry_crit_third:
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),
@@ -305,8 +334,10 @@ __relibc_internal_sigentry_crit_third:
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_SIGDEQUEUE = const syscall::SYS_SIGDEQUEUE,
SYS_CALL = const syscall::SYS_CALL,
]);
asmfunction!(__relibc_internal_rlct_clone_ret -> usize: ["
@@ -377,3 +408,6 @@ pub fn current_sp() -> usize {
}
sp
}
pub static PROC_FD: SyncUnsafeCell<usize> = SyncUnsafeCell::new(usize::MAX);
static PROC_CALL: [usize; 1] = [ProcCall::Sigdeq as usize];
+2 -2
View File
@@ -233,8 +233,8 @@ asmfunction!(__relibc_internal_sigentry: ["
// otherwise, try (competitively) dequeueing realtime signal
// SYS_CALL(fd, payload_base, payload_len, metadata_len, metadata_base | (flags << 8))
// rax rdi rsi rdx r10 r8
// 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]
+7 -3
View File
@@ -121,7 +121,7 @@ where
|o| core::mem::take(&mut o.tree),
);
pread_all(*image_file as usize, header.e_phoff.into(), phs).map_err(|_| Error::new(EIO))?;
pread_all(*image_file as usize, u64::from(header.e_phoff), phs).map_err(|_| Error::new(EIO))?;
for ph_idx in 0..phnum {
let ph_bytes = &phs[ph_idx * phentsize..(ph_idx + 1) * phentsize];
@@ -144,7 +144,11 @@ where
// PT_INTERP must come before any PT_LOAD, so we don't have to iterate twice.
PT_INTERP => {
let mut interp = vec![0_u8; segment.p_filesz as usize];
pread_all(*image_file as usize, segment.p_offset.into(), &mut interp)?;
pread_all(
*image_file as usize,
u64::from(segment.p_offset),
&mut interp,
)?;
return Ok(FexecResult::Interp {
path: interp.into_boxed_slice(),
@@ -193,7 +197,7 @@ where
};
pread_all(
*image_file,
segment.p_offset.into(),
u64::from(segment.p_offset),
&mut dst_memory[voff..voff + filesz],
)?;
}