diff options
author | JozanLeClerc <JozanLeClerc@noemail.net> | 2020-11-20 17:18:59 +0000 |
---|---|---|
committer | JozanLeClerc <JozanLeClerc@noemail.net> | 2020-11-20 17:18:59 +0000 |
commit | 1fd458b241dab419c47f577df6a6adce47113287 (patch) | |
tree | d12a5c2629ce15371710b8796ebdcfa6d61edc0c | |
parent | Added LICENSE (diff) | |
download | bsdsetsid-1fd458b241dab419c47f577df6a6adce47113287.tar.gz bsdsetsid-1fd458b241dab419c47f577df6a6adce47113287.tar.bz2 bsdsetsid-1fd458b241dab419c47f577df6a6adce47113287.tar.xz bsdsetsid-1fd458b241dab419c47f577df6a6adce47113287.tar.zst bsdsetsid-1fd458b241dab419c47f577df6a6adce47113287.zip |
Errors I do not understand
FossilOrigin-Name: 7908f3891d84f726b01bd9641094654c295550ff
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | src/c_bsdsetsid.S | 54 | ||||
-rw-r--r-- | src/e_err.S | 113 | ||||
-rw-r--r-- | src/u_print.S | 12 | ||||
-rw-r--r-- | src/u_strlen.S | 3 |
5 files changed, 144 insertions, 41 deletions
@@ -23,12 +23,13 @@ PREFIX := /usr/local/ DESTDIR := SRCS := ${SRCS_DIR}c_bsdsetsid.S +SRCS += ${SRCS_DIR}e_err.S SRCS += ${SRCS_DIR}u_print.S SRCS += ${SRCS_DIR}u_strlen.S OBJS = ${SRCS:.S=.o} -AS = as +# AS = yasm # ASFLAGS = -felf64 # ASFLAGS += -pgas diff --git a/src/c_bsdsetsid.S b/src/c_bsdsetsid.S index 4c9189c..b0027f9 100644 --- a/src/c_bsdsetsid.S +++ b/src/c_bsdsetsid.S @@ -39,32 +39,47 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * bsdsetsid: src/c_bsdsetsid.S - * 2020-11-18 12:37 + * 2020-11-20 18:18 * Joe * * This is the entrypoint of the program. */ .text -.extern u_strlen -.extern u_pout -.extern u_perr .globl main main: cmpb $0x1, %dil - jle c_noarg + jle e_noarg xor %rax, %rax - movb $0x2, %al /* SYS_fork */ + movb $0x2, %al syscall - jc c_fork_fail + jc e_fork cmp $0x0, %rax je c_child -c_child: +c_parent: + mov %rax, %rdi +# xor %r8, %r8 +# lea (%r8), %rsi + mov $0x0, %rdx + mov $0x0, %rcx xor %rax, %rax - movb $0x93, %al /* SYS_setsid */ + movb $0x7, %al /* SYS_wait4 */ syscall + + xor %rdi, %rdi + movb %al, %dil + 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 mov $0x1, %rcx @@ -72,31 +87,12 @@ c_child: lea 0(%rsi, %rcx, 8), %rsi movb $0x3b, %al /* SYS_execve */ syscall + jc e_execve pop %rsi jmp c_exit -c_fork_fail: - lea forkfail_str, %rdi - call u_perr - mov $0x2, %rdi - xor %rax, %rax - movb $0x1, %al /* SYS_exit */ - syscall - -c_noarg: - lea noarg_str, %rdi - call u_perr - mov $0x1, %rdi - xor %rax, %rax - movb $0x1, %al /* SYS_exit */ - syscall - c_exit: xor %rdi, %rdi xor %rax, %rax movb $0x1, %al /* SYS_exit */ syscall - -.data -noarg_str: .asciz "bsdsetsid: no command specified" -forkfail_str: .asciz "bsdsetsid: fork failed" diff --git a/src/e_err.S b/src/e_err.S new file mode 100644 index 0000000..bf5fa1d --- /dev/null +++ b/src/e_err.S @@ -0,0 +1,113 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * bsdsetsid: src/e_err.S + * 2020-11-20 16:43 + * Joe + * + * General error handling happen here. + */ + +.text +.extern strerror +.globl e_execve +.globl e_fork +.globl e_noarg +.globl e_setsid + +e_noarg: + lea e_noarg_str, %rdi + call u_perr + mov $0x1, %rdi + jmp e_exit + +e_fork: + push %rax + lea e_fork_str, %rdi + call u_perr + pop %rax + mov %rax, %rdi + call strerror + mov %rax, %rdi + call u_perr + mov $0x2, %rdi + jmp e_exit + +e_setsid: + push %rax + lea e_setsid_str, %rdi + call u_perr + pop %rax + mov %rax, %rdi + call strerror + mov %rax, %rdi + call u_perr + lea nl, %rdi + call u_perr + mov $0x3, %rdi + jmp e_exit + +e_execve: + push %rax + lea e_execve_str, %rdi + call u_perr + pop %rax + mov %rax, %rdi + call strerror + mov %rax, %rdi + call u_perr + lea nl, %rdi + call u_perr + mov $0x4, %rdi + xor %rax, %rax + movb $0x1, %al /* SYS_exit */ + syscall + +e_exit: + xor %rax, %rax + movb $0x1, %al /* sys_exit */ + syscall + +.data +nl: .asciz "\n" +e_setsid_str: .asciz "bsdsetsid: setsid: " +e_execve_str: .asciz "bsdsetsid: execve: " +e_fork_str: .asciz "bsdsetsid: fork: " +e_noarg_str: .asciz "bsdsetsid: no command specified\n" diff --git a/src/u_print.S b/src/u_print.S index 969cf28..36fca6d 100644 --- a/src/u_print.S +++ b/src/u_print.S @@ -38,7 +38,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * bsdsetsid: src/c_bsdsetsid.S + * bsdsetsid: src/u_print.S * 2020-11-19 13:27 * Joe * @@ -46,7 +46,6 @@ */ .text -.extern u_strlen .globl u_pout .globl u_perr @@ -55,7 +54,7 @@ u_pout: jmp u_print u_perr: - mov $0x2, %r11 /* stderr */ + mov $0x2, %r11 /* stderr */ jmp u_print u_print: @@ -65,11 +64,4 @@ u_print: mov %r11, %rdi mov $0x4, %rax /* SYS_write */ syscall - lea nl, %rsi - mov $0x1, %rdx - mov $0x4, %rax /* SYS_write */ - syscall ret - -.data -nl: .asciz "\n" diff --git a/src/u_strlen.S b/src/u_strlen.S index 2cfbb1b..fb783ab 100644 --- a/src/u_strlen.S +++ b/src/u_strlen.S @@ -38,12 +38,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * bsdsetsid: src/c_bsdsetsid.S + * bsdsetsid: src/u_strlen.S * 2020-11-19 14:10 * Joe * * Simple implementation of strlen. */ + .text .globl u_strlen |