From 040a73a8e3763954320f36e1ac98e73ea0bb76f1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 20 Nov 2020 17:49:30 +0000 Subject: In progress FossilOrigin-Name: 541eb5074479979fbad29b2df18964971000b067 --- Makefile | 8 +------- src/c_bsdsetsid.S | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index b74f92f..1c46784 100644 --- a/Makefile +++ b/Makefile @@ -29,12 +29,6 @@ SRCS += ${SRCS_DIR}u_strlen.S OBJS = ${SRCS:.S=.o} -# AS = yasm -# ASFLAGS = -felf64 -# ASFLAGS += -pgas - -CC = cc - NAME := bsdsetsid RM := rm -f @@ -42,7 +36,7 @@ RM := rm -f .SUFFIXES: .S .o .S.o: - ${AS} ${ASFLAGS} -o ${.TARGET} ${.IMPSRC} + ${AS} -o ${.TARGET} ${.IMPSRC} ${NAME}: ${OBJS} ${CC} -o ${.TARGET} ${.ALLSRC} diff --git a/src/c_bsdsetsid.S b/src/c_bsdsetsid.S index b0027f9..7e1c6ae 100644 --- a/src/c_bsdsetsid.S +++ b/src/c_bsdsetsid.S @@ -45,6 +45,9 @@ * This is the entrypoint of the program. */ +.data +status: .space 4, 0x0 + .text .globl main @@ -53,42 +56,44 @@ main: jle e_noarg xor %rax, %rax movb $0x2, %al + push %rdi + push %rsi + push %rdx syscall - jc e_fork - cmp $0x0, %rax - je c_child + test %rax, %rax + js e_fork + jz c_child c_parent: mov %rax, %rdi -# xor %r8, %r8 -# lea (%r8), %rsi + lea status, %rsi mov $0x0, %rdx mov $0x0, %rcx xor %rax, %rax movb $0x7, %al /* SYS_wait4 */ syscall - xor %rdi, %rdi - movb %al, %dil + lea (%rsi), %rdi movb $0x7, %al xor %rax, %rax movb $0x1, %al /* SYS_exit */ syscall c_child: -# xor %rax, %rax -# movb $0x93, %al /* SYS_setsid */ -# syscall -# jc e_setsid xor %rax, %rax - push %rsi + movb $0x93, %al /* SYS_setsid */ + syscall + jc e_setsid + xor %rax, %rax + pop %rdx + pop %rsi + pop %rdi mov $0x1, %rcx mov (%rsi, %rcx, 8), %rdi lea 0(%rsi, %rcx, 8), %rsi movb $0x3b, %al /* SYS_execve */ syscall jc e_execve - pop %rsi jmp c_exit c_exit: -- cgit v1.2.3