Usermode/ld-acess - Syscall stub changes
authorJohn Hodge <[email protected]>
Sat, 15 Oct 2011 00:24:34 +0000 (08:24 +0800)
committerJohn Hodge <[email protected]>
Sat, 15 Oct 2011 00:24:34 +0000 (08:24 +0800)
- SYS_CLONE stack switch moved to usermode
- ARMv7 syscall fixes

Usermode/Libraries/ld-acess.so_src/arch/armv7.S.h
Usermode/Libraries/ld-acess.so_src/arch/x86.asm.h
Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h

index 75c56d8..85a3ac6 100644 (file)
@@ -7,7 +7,7 @@
 .globl _start
 .extern SoMain
 _start:
-       push {r1,r2,r3}
+       pop {r0}
        bl SoMain
        
        mov r4, r0
@@ -58,19 +58,59 @@ _errno:     .long   0       @ Placed in .text, to allow use of relative addressing
        mov pc, lr
 .endm
 
+.macro syscall5 _name, _num
+.globl \_name
+\_name:
+       push {r4}
+       ldr r4, [sp,#4]
+       svc #\_num
+       str r2, _errno
+       pop {r4}
+       mov pc, lr
+.endm
+
+.macro syscall6 _name, _num
+.globl \_name
+\_name:
+       push {r4,r5}
+       ldr r4, [sp,#8]
+       ldr r5, [sp,#12]
+       svc #\_num
+       str r2, _errno
+       pop {r4,r5}
+       mov pc, lr
+.endm
+
 #define SYSCALL0(_name,_num)   syscall0 _name, _num
 #define SYSCALL1(_name,_num)   SYSCALL0(_name, _num)
 #define SYSCALL2(_name,_num)   SYSCALL0(_name, _num)
 #define SYSCALL3(_name,_num)   SYSCALL0(_name, _num)
 #define SYSCALL4(_name,_num)   SYSCALL0(_name, _num)
 // TODO: 5/6 need special handling, because the args are on the stack
-#define SYSCALL5(_name,_num)   SYSCALL0(_name, _num)
-#define SYSCALL6(_name,_num)   SYSCALL0(_name, _num)
+#define SYSCALL5(_name,_num)   syscall5 _name, _num
+#define SYSCALL6(_name,_num)   syscall6 _name, _num
 
 // Override the clone syscall
 #define _exit  _exit_raw
+#define _clone _clone_raw
 #include "syscalls.s.h"
 #undef _exit
+#undef _clone
+
+.globl _clone
+_clone:
+       push {r4}
+       mov r4, r1
+       svc #SYS_CLONE
+       str r2, _errno
+       tst r4, r4
+       beq _clone_ret
+       @ If in child, set SP
+       tst r0,r0
+       movne sp, r4
+_clone_ret:
+       pop {r4}
+       mov pc, lr
 
 .globl _exit
 _exit:
index a569637..4de2527 100644 (file)
@@ -161,6 +161,7 @@ clone:
        push ebp
        mov ebp, esp
        push ebx
+       push edx
        
        mov ebx, [ebp+12]       ; Get new stack pointer
        
@@ -192,11 +193,20 @@ clone:
        sub ebx, 12
        %endif
 .doCall:
+       mov edx, ebx    ; Save new stack
        mov eax, SYS_CLONE
        mov ecx, ebx    ; Stack
        mov ebx, [ebp+8]        ; Flags
        SYSCALL_OP
        mov [_errno], ebx
+       
+       test eax, eax
+       jnz .ret
+       test edx, edx
+       jz .ret
+       mov esp, edx
+.ret:
+       pop edx
        pop ebx
        pop ebp
        ret
index ea605ef..62fc400 100644 (file)
@@ -152,6 +152,9 @@ clone:
        push rbp
        mov rbp, rsp
        push rbx
+       push r11
+       
+       mov r12, rsi    ; Save in a reg for after the clone
        
        ; Check if the new stack is being used
        test rsi, rsi
@@ -166,10 +169,19 @@ clone:
        mov eax, SYS_CLONE
        SYSCALL_OP
        mov [rel _errno], ebx
+
+       ; Change stack pointer
+       test eax, eax
+       jnz .ret
+       test r12, r12
+       jz .ret
+       mov rsp, rsi
+.ret:
        pop rbx
        pop rbp
        ret
 
+
 [global _exit:func]
 _exit:
        xor eax, eax

UCC git Repository :: git.ucc.asn.au