diff --git a/lib/csu/amd64/Scrt1.s b/lib/csu/amd64/Scrt1.s new file mode 100644 index 0000000..8b20894 --- /dev/null +++ b/lib/csu/amd64/Scrt1.s @@ -0,0 +1,262 @@ + .text + .file "/ubixos/usr/src/lib/csu/amd64/crt1.c" + # Start of file scope inline assembly + .ident "$FreeBSD: releng/11.1/lib/csu/amd64/crt1.c 292000 2015-12-08 19:32:58Z emaste $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/crtbrand.c 321309 2017-07-20 23:39:50Z gjb $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/ignore_init.c 245133 2013-01-07 17:58:27Z kib $" + + # End of file scope inline assembly + .globl _start + .p2align 4, 0x90 + .type _start,@function +_start: # @_start + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi0: + .cfi_def_cfa_offset 16 +.Lcfi1: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi2: + .cfi_def_cfa_register %rbp + pushq %r15 + pushq %r14 + pushq %r13 + pushq %r12 + pushq %rbx + pushq %rax +.Lcfi3: + .cfi_offset %rbx, -56 +.Lcfi4: + .cfi_offset %r12, -48 +.Lcfi5: + .cfi_offset %r13, -40 +.Lcfi6: + .cfi_offset %r14, -32 +.Lcfi7: + .cfi_offset %r15, -24 + movq (%rdi), %r13 + movslq %r13d, %rax + leaq 16(%rdi,%rax,8), %rax + movq %rax, -48(%rbp) # 8-byte Spill + movq environ@GOTPCREL(%rip), %rax + cmpq $0, (%rax) + jne .LBB0_2 +# BB#1: + movq -48(%rbp), %rcx # 8-byte Reload + movq %rcx, (%rax) +.LBB0_2: + addq $8, %rdi + testl %r13d, %r13d + jle .LBB0_10 +# BB#3: + movq (%rdi), %rax + testq %rax, %rax + je .LBB0_10 +# BB#4: + movq __progname@GOTPCREL(%rip), %rcx + jmp .LBB0_5 + .p2align 4, 0x90 +.LBB0_9: # in Loop: Header=BB0_5 Depth=1 + incq %rax +.LBB0_5: # =>This Loop Header: Depth=1 + # Child Loop BB0_6 Depth 2 + movq %rax, (%rcx) + jmp .LBB0_6 + .p2align 4, 0x90 +.LBB0_8: # in Loop: Header=BB0_6 Depth=2 + incq %rax +.LBB0_6: # Parent Loop BB0_5 Depth=1 + # => This Inner Loop Header: Depth=2 + movzbl (%rax), %edx + cmpb $47, %dl + je .LBB0_9 +# BB#7: # in Loop: Header=BB0_6 Depth=2 + testb %dl, %dl + jne .LBB0_8 +.LBB0_10: + movq %rdi, %r15 + cmpq $0, _DYNAMIC@GOTPCREL(%rip) + je .LBB0_12 +# BB#11: + movq %rsi, %rdi + callq atexit@PLT + cmpq $0, _DYNAMIC@GOTPCREL(%rip) + je .LBB0_14 + jmp .LBB0_24 +.LBB0_12: + callq _init_tls@PLT + cmpq $0, _DYNAMIC@GOTPCREL(%rip) + jne .LBB0_24 +.LBB0_14: + leaq finalizer(%rip), %rdi + callq atexit@PLT + leaq __preinit_array_start(%rip), %r12 + leaq __preinit_array_end(%rip), %rax + subq %r12, %rax + movq %rax, %rcx + sarq $63, %rcx + shrq $61, %rcx + addq %rax, %rcx + sarq $3, %rcx + movq %r15, %r14 + movq %r13, %r15 + movq %rcx, %r13 + je .LBB0_19 +# BB#15: + xorl %ebx, %ebx + .p2align 4, 0x90 +.LBB0_16: # =>This Inner Loop Header: Depth=1 + movq (%r12), %rax + cmpq $2, %rax + jb .LBB0_18 +# BB#17: # in Loop: Header=BB0_16 Depth=1 + movl %r15d, %edi + movq %r14, %rsi + movq -48(%rbp), %rdx # 8-byte Reload + callq *%rax +.LBB0_18: # in Loop: Header=BB0_16 Depth=1 + incq %rbx + addq $8, %r12 + cmpq %r13, %rbx + jb .LBB0_16 +.LBB0_19: + movq %r15, %r13 + movq %r14, %r15 + callq _init + leaq __init_array_start(%rip), %rbx + leaq __init_array_end(%rip), %rax + subq %rbx, %rax + movq %rax, %r12 + sarq $63, %r12 + shrq $61, %r12 + addq %rax, %r12 + sarq $3, %r12 + je .LBB0_24 +# BB#20: + xorl %r14d, %r14d + .p2align 4, 0x90 +.LBB0_21: # =>This Inner Loop Header: Depth=1 + movq (%rbx), %rax + cmpq $2, %rax + jb .LBB0_23 +# BB#22: # in Loop: Header=BB0_21 Depth=1 + movl %r13d, %edi + movq %r15, %rsi + movq -48(%rbp), %rdx # 8-byte Reload + callq *%rax +.LBB0_23: # in Loop: Header=BB0_21 Depth=1 + incq %r14 + addq $8, %rbx + cmpq %r12, %r14 + jb .LBB0_21 +.LBB0_24: + movl %r13d, %edi + movq %r15, %rsi + movq -48(%rbp), %rdx # 8-byte Reload + callq main@PLT + movl %eax, %edi + callq exit@PLT +.Lfunc_end0: + .size _start, .Lfunc_end0-_start + .cfi_endproc + + .p2align 4, 0x90 + .type finalizer,@function +finalizer: # @finalizer + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi8: + .cfi_def_cfa_offset 16 +.Lcfi9: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi10: + .cfi_def_cfa_register %rbp + pushq %r14 + pushq %rbx +.Lcfi11: + .cfi_offset %rbx, -32 +.Lcfi12: + .cfi_offset %r14, -24 + leaq __fini_array_start(%rip), %r14 + leaq __fini_array_end(%rip), %rax + subq %r14, %rax + movq %rax, %rbx + sarq $63, %rbx + shrq $61, %rbx + addq %rax, %rbx + sarq $3, %rbx + je .LBB1_3 + .p2align 4, 0x90 +.LBB1_1: # =>This Inner Loop Header: Depth=1 + movq -8(%r14,%rbx,8), %rax + decq %rbx + cmpq $1, %rax + jbe .LBB1_2 +# BB#4: # in Loop: Header=BB1_1 Depth=1 + callq *%rax +.LBB1_2: # in Loop: Header=BB1_1 Depth=1 + testq %rbx, %rbx + jne .LBB1_1 +.LBB1_3: + popq %rbx + popq %r14 + popq %rbp + jmp _fini # TAILCALL +.Lfunc_end1: + .size finalizer, .Lfunc_end1-finalizer + .cfi_endproc + + .type abitag,@object # @abitag + .section .note.tag,"a",@note + .p2align 2 +abitag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 1 # 0x1 + .asciz "FreeBSD" + .long 1101001 # 0x10ccc9 + .size abitag, 24 + + .type .L.str,@object # @.str + .section .rodata.str1.1,"aMS",@progbits,1 +.L.str: + .zero 1 + .size .L.str, 1 + + .type __progname,@object # @__progname + .data + .globl __progname + .p2align 3 +__progname: + .quad .L.str + .size __progname, 8 + + .type crt_noinit_tag,@object # @crt_noinit_tag + .section .note.tag,"a",@note + .p2align 2 +crt_noinit_tag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 2 # 0x2 + .asciz "FreeBSD" + .long 0 # 0x0 + .size crt_noinit_tag, 24 + + .type environ,@object # @environ + .comm environ,8,8 + .hidden __preinit_array_end + .hidden __preinit_array_start + .hidden __init_array_end + .hidden __init_array_start + .hidden __fini_array_end + .hidden __fini_array_start + .hidden _init + .hidden _fini + .weak _DYNAMIC + + .ident "FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)" + .section ".note.GNU-stack","",@progbits diff --git a/lib/csu/amd64/crt1.s b/lib/csu/amd64/crt1.s new file mode 100644 index 0000000..eb7a2c3 --- /dev/null +++ b/lib/csu/amd64/crt1.s @@ -0,0 +1,274 @@ + .text + .file "/ubixos/usr/src/lib/csu/amd64/crt1.c" + # Start of file scope inline assembly + .ident "$FreeBSD: releng/11.1/lib/csu/amd64/crt1.c 292000 2015-12-08 19:32:58Z emaste $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/crtbrand.c 321309 2017-07-20 23:39:50Z gjb $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/ignore_init.c 245133 2013-01-07 17:58:27Z kib $" + + # End of file scope inline assembly + .globl _start + .p2align 4, 0x90 + .type _start,@function +_start: # @_start + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi0: + .cfi_def_cfa_offset 16 +.Lcfi1: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi2: + .cfi_def_cfa_register %rbp + pushq %r15 + pushq %r14 + pushq %r13 + pushq %r12 + pushq %rbx + pushq %rax +.Lcfi3: + .cfi_offset %rbx, -56 +.Lcfi4: + .cfi_offset %r12, -48 +.Lcfi5: + .cfi_offset %r13, -40 +.Lcfi6: + .cfi_offset %r14, -32 +.Lcfi7: + .cfi_offset %r15, -24 + movq %rdi, %r14 + movq (%r14), %r15 + movslq %r15d, %rax + leaq 16(%r14,%rax,8), %r13 + cmpq $0, environ(%rip) + jne .LBB0_2 +# BB#1: + movq %r13, environ(%rip) +.LBB0_2: + addq $8, %r14 + testl %r15d, %r15d + jle .LBB0_9 +# BB#3: + movq (%r14), %rax + testq %rax, %rax + jne .LBB0_4 + jmp .LBB0_9 + .p2align 4, 0x90 +.LBB0_8: # in Loop: Header=BB0_4 Depth=1 + incq %rax +.LBB0_4: # =>This Loop Header: Depth=1 + # Child Loop BB0_5 Depth 2 + movq %rax, __progname(%rip) + jmp .LBB0_5 + .p2align 4, 0x90 +.LBB0_7: # in Loop: Header=BB0_5 Depth=2 + incq %rax +.LBB0_5: # Parent Loop BB0_4 Depth=1 + # => This Inner Loop Header: Depth=2 + movzbl (%rax), %ecx + cmpb $47, %cl + je .LBB0_8 +# BB#6: # in Loop: Header=BB0_5 Depth=2 + testb %cl, %cl + jne .LBB0_7 +.LBB0_9: + movl $_DYNAMIC, %eax + testq %rax, %rax + je .LBB0_11 +# BB#10: + movq %rsi, %rdi + callq atexit + jmp .LBB0_12 +.LBB0_11: + callq _init_tls +.LBB0_12: + movl $_DYNAMIC, %eax + testq %rax, %rax + jne .LBB0_23 +# BB#13: + movl $finalizer, %edi + callq atexit + movl $__preinit_array_start, %eax + movl $__preinit_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB0_18 +# BB#14: + xorl %r12d, %r12d + movl $__preinit_array_start, %eax + movl $__preinit_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rbx + sarq $63, %rbx + shrq $61, %rbx + addq %rcx, %rbx + sarq $3, %rbx + .p2align 4, 0x90 +.LBB0_15: # =>This Inner Loop Header: Depth=1 + movq __preinit_array_start(,%r12,8), %rax + cmpq $2, %rax + jb .LBB0_17 +# BB#16: # in Loop: Header=BB0_15 Depth=1 + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq *%rax +.LBB0_17: # in Loop: Header=BB0_15 Depth=1 + incq %r12 + cmpq %rbx, %r12 + jb .LBB0_15 +.LBB0_18: + callq _init + movl $__init_array_start, %eax + movl $__init_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB0_23 +# BB#19: + xorl %ebx, %ebx + movl $__init_array_start, %eax + movl $__init_array_end, %ecx + subq %rax, %rcx + movq %rcx, %r12 + sarq $63, %r12 + shrq $61, %r12 + addq %rcx, %r12 + sarq $3, %r12 + .p2align 4, 0x90 +.LBB0_20: # =>This Inner Loop Header: Depth=1 + movq __init_array_start(,%rbx,8), %rax + cmpq $2, %rax + jb .LBB0_22 +# BB#21: # in Loop: Header=BB0_20 Depth=1 + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq *%rax +.LBB0_22: # in Loop: Header=BB0_20 Depth=1 + incq %rbx + cmpq %r12, %rbx + jb .LBB0_20 +.LBB0_23: + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq main + movl %eax, %edi + callq exit +.Lfunc_end0: + .size _start, .Lfunc_end0-_start + .cfi_endproc + + .p2align 4, 0x90 + .type finalizer,@function +finalizer: # @finalizer + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi8: + .cfi_def_cfa_offset 16 +.Lcfi9: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi10: + .cfi_def_cfa_register %rbp + pushq %rbx + pushq %rax +.Lcfi11: + .cfi_offset %rbx, -24 + movl $__fini_array_start, %eax + movl $__fini_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB1_4 +# BB#1: + movl $__fini_array_start, %eax + movl $__fini_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rbx + sarq $63, %rbx + shrq $61, %rbx + addq %rcx, %rbx + sarq $3, %rbx + .p2align 4, 0x90 +.LBB1_2: # =>This Inner Loop Header: Depth=1 + movq __fini_array_start-8(,%rbx,8), %rax + decq %rbx + cmpq $1, %rax + jbe .LBB1_3 +# BB#5: # in Loop: Header=BB1_2 Depth=1 + callq *%rax +.LBB1_3: # in Loop: Header=BB1_2 Depth=1 + testq %rbx, %rbx + jne .LBB1_2 +.LBB1_4: + addq $8, %rsp + popq %rbx + popq %rbp + jmp _fini # TAILCALL +.Lfunc_end1: + .size finalizer, .Lfunc_end1-finalizer + .cfi_endproc + + .type abitag,@object # @abitag + .section .note.tag,"a",@note + .p2align 2 +abitag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 1 # 0x1 + .asciz "FreeBSD" + .long 1101001 # 0x10ccc9 + .size abitag, 24 + + .type .L.str,@object # @.str + .section .rodata.str1.1,"aMS",@progbits,1 +.L.str: + .zero 1 + .size .L.str, 1 + + .type __progname,@object # @__progname + .data + .globl __progname + .p2align 3 +__progname: + .quad .L.str + .size __progname, 8 + + .type crt_noinit_tag,@object # @crt_noinit_tag + .section .note.tag,"a",@note + .p2align 2 +crt_noinit_tag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 2 # 0x2 + .asciz "FreeBSD" + .long 0 # 0x0 + .size crt_noinit_tag, 24 + + .type environ,@object # @environ + .comm environ,8,8 + .hidden __preinit_array_end + .hidden __preinit_array_start + .hidden __init_array_end + .hidden __init_array_start + .hidden __fini_array_end + .hidden __fini_array_start + .hidden _init + .hidden _fini + .weak _DYNAMIC + + .ident "FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)" + .section ".note.GNU-stack","",@progbits diff --git a/lib/csu/amd64/gcrt1.s b/lib/csu/amd64/gcrt1.s new file mode 100644 index 0000000..3769bb6 --- /dev/null +++ b/lib/csu/amd64/gcrt1.s @@ -0,0 +1,282 @@ + .text + .file "/ubixos/usr/src/lib/csu/amd64/crt1.c" + # Start of file scope inline assembly + .ident "$FreeBSD: releng/11.1/lib/csu/amd64/crt1.c 292000 2015-12-08 19:32:58Z emaste $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/crtbrand.c 321309 2017-07-20 23:39:50Z gjb $" + .ident "$FreeBSD: releng/11.1/lib/csu/common/ignore_init.c 245133 2013-01-07 17:58:27Z kib $" + + # End of file scope inline assembly + .globl _start + .p2align 4, 0x90 + .type _start,@function +_start: # @_start + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi0: + .cfi_def_cfa_offset 16 +.Lcfi1: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi2: + .cfi_def_cfa_register %rbp + pushq %r15 + pushq %r14 + pushq %r13 + pushq %r12 + pushq %rbx + pushq %rax +.Lcfi3: + .cfi_offset %rbx, -56 +.Lcfi4: + .cfi_offset %r12, -48 +.Lcfi5: + .cfi_offset %r13, -40 +.Lcfi6: + .cfi_offset %r14, -32 +.Lcfi7: + .cfi_offset %r15, -24 + movq %rdi, %r14 + movq (%r14), %r15 + movslq %r15d, %rax + leaq 16(%r14,%rax,8), %r13 + cmpq $0, environ(%rip) + jne .LBB0_2 +# BB#1: + movq %r13, environ(%rip) +.LBB0_2: + addq $8, %r14 + testl %r15d, %r15d + jle .LBB0_9 +# BB#3: + movq (%r14), %rax + testq %rax, %rax + jne .LBB0_4 + jmp .LBB0_9 + .p2align 4, 0x90 +.LBB0_8: # in Loop: Header=BB0_4 Depth=1 + incq %rax +.LBB0_4: # =>This Loop Header: Depth=1 + # Child Loop BB0_5 Depth 2 + movq %rax, __progname(%rip) + jmp .LBB0_5 + .p2align 4, 0x90 +.LBB0_7: # in Loop: Header=BB0_5 Depth=2 + incq %rax +.LBB0_5: # Parent Loop BB0_4 Depth=1 + # => This Inner Loop Header: Depth=2 + movzbl (%rax), %ecx + cmpb $47, %cl + je .LBB0_8 +# BB#6: # in Loop: Header=BB0_5 Depth=2 + testb %cl, %cl + jne .LBB0_7 +.LBB0_9: + movl $_DYNAMIC, %eax + testq %rax, %rax + je .LBB0_11 +# BB#10: + movq %rsi, %rdi + callq atexit + jmp .LBB0_12 +.LBB0_11: + callq _init_tls +.LBB0_12: + movl $_mcleanup, %edi + callq atexit + movl $eprol, %edi + movl $etext, %esi + callq monstartup + #APP +eprol: + #NO_APP + movl $_DYNAMIC, %eax + testq %rax, %rax + jne .LBB0_23 +# BB#13: + movl $finalizer, %edi + callq atexit + movl $__preinit_array_start, %eax + movl $__preinit_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB0_18 +# BB#14: + xorl %r12d, %r12d + movl $__preinit_array_start, %eax + movl $__preinit_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rbx + sarq $63, %rbx + shrq $61, %rbx + addq %rcx, %rbx + sarq $3, %rbx + .p2align 4, 0x90 +.LBB0_15: # =>This Inner Loop Header: Depth=1 + movq __preinit_array_start(,%r12,8), %rax + cmpq $2, %rax + jb .LBB0_17 +# BB#16: # in Loop: Header=BB0_15 Depth=1 + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq *%rax +.LBB0_17: # in Loop: Header=BB0_15 Depth=1 + incq %r12 + cmpq %rbx, %r12 + jb .LBB0_15 +.LBB0_18: + callq _init + movl $__init_array_start, %eax + movl $__init_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB0_23 +# BB#19: + xorl %ebx, %ebx + movl $__init_array_start, %eax + movl $__init_array_end, %ecx + subq %rax, %rcx + movq %rcx, %r12 + sarq $63, %r12 + shrq $61, %r12 + addq %rcx, %r12 + sarq $3, %r12 + .p2align 4, 0x90 +.LBB0_20: # =>This Inner Loop Header: Depth=1 + movq __init_array_start(,%rbx,8), %rax + cmpq $2, %rax + jb .LBB0_22 +# BB#21: # in Loop: Header=BB0_20 Depth=1 + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq *%rax +.LBB0_22: # in Loop: Header=BB0_20 Depth=1 + incq %rbx + cmpq %r12, %rbx + jb .LBB0_20 +.LBB0_23: + movl %r15d, %edi + movq %r14, %rsi + movq %r13, %rdx + callq main + movl %eax, %edi + callq exit +.Lfunc_end0: + .size _start, .Lfunc_end0-_start + .cfi_endproc + + .p2align 4, 0x90 + .type finalizer,@function +finalizer: # @finalizer + .cfi_startproc +# BB#0: + pushq %rbp +.Lcfi8: + .cfi_def_cfa_offset 16 +.Lcfi9: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi10: + .cfi_def_cfa_register %rbp + pushq %rbx + pushq %rax +.Lcfi11: + .cfi_offset %rbx, -24 + movl $__fini_array_start, %eax + movl $__fini_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rax + sarq $63, %rax + shrq $61, %rax + addq %rcx, %rax + sarq $3, %rax + je .LBB1_4 +# BB#1: + movl $__fini_array_start, %eax + movl $__fini_array_end, %ecx + subq %rax, %rcx + movq %rcx, %rbx + sarq $63, %rbx + shrq $61, %rbx + addq %rcx, %rbx + sarq $3, %rbx + .p2align 4, 0x90 +.LBB1_2: # =>This Inner Loop Header: Depth=1 + movq __fini_array_start-8(,%rbx,8), %rax + decq %rbx + cmpq $1, %rax + jbe .LBB1_3 +# BB#5: # in Loop: Header=BB1_2 Depth=1 + callq *%rax +.LBB1_3: # in Loop: Header=BB1_2 Depth=1 + testq %rbx, %rbx + jne .LBB1_2 +.LBB1_4: + addq $8, %rsp + popq %rbx + popq %rbp + jmp _fini # TAILCALL +.Lfunc_end1: + .size finalizer, .Lfunc_end1-finalizer + .cfi_endproc + + .type abitag,@object # @abitag + .section .note.tag,"a",@note + .p2align 2 +abitag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 1 # 0x1 + .asciz "FreeBSD" + .long 1101001 # 0x10ccc9 + .size abitag, 24 + + .type .L.str,@object # @.str + .section .rodata.str1.1,"aMS",@progbits,1 +.L.str: + .zero 1 + .size .L.str, 1 + + .type __progname,@object # @__progname + .data + .globl __progname + .p2align 3 +__progname: + .quad .L.str + .size __progname, 8 + + .type crt_noinit_tag,@object # @crt_noinit_tag + .section .note.tag,"a",@note + .p2align 2 +crt_noinit_tag: + .long 8 # 0x8 + .long 4 # 0x4 + .long 2 # 0x2 + .asciz "FreeBSD" + .long 0 # 0x0 + .size crt_noinit_tag, 24 + + .type environ,@object # @environ + .comm environ,8,8 + .hidden __preinit_array_end + .hidden __preinit_array_start + .hidden __init_array_end + .hidden __init_array_start + .hidden __fini_array_end + .hidden __fini_array_start + .hidden _init + .hidden _fini + .weak _DYNAMIC + + .ident "FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)" + .section ".note.GNU-stack","",@progbits diff --git a/sys/fs/vfs/file.c b/sys/fs/vfs/file.c index 6c0042a..25d97b5 100644 --- a/sys/fs/vfs/file.c +++ b/sys/fs/vfs/file.c @@ -36,6 +36,7 @@ #include #include #include +#include static struct spinLock fdTable_lock = SPIN_LOCK_INITIALIZER; @@ -140,6 +141,29 @@ return (0); } +int sys_fchdir( struct thread *td, struct sys_fchdir_args *args ) { + int error = 0; + struct file *fdd = 0x0; + fileDescriptor_t *fd = 0x0; + + getfd(td, &fdd, args->fd); + + fd = fdd->fd; + + if (fdd == 0 || fdd->fd == 0x0) { + error = -1; + } +else { + if ( strstr( fd->fileName, ":" ) == 0x0 ) { + sprintf( _current->oInfo.cwd, "%s%s", _current->oInfo.cwd, fd->fileName ); + } + else { + sprintf( _current->oInfo.cwd, fd->fileName ); + } +} + return (error); +} + int sysUnlink( const char *path, int *retVal ) { *retVal = unlink( path ); return (*retVal); @@ -330,7 +354,10 @@ return (NULL); } - strcpy( fileName, file ); + if (file[0] == "." && file[1] == '\0') + strcpy(fileName, _current->oInfo.cwd); + else + strcpy( fileName, file ); if ( strstr( fileName, ":" ) ) { mountPoint = (char *) strtok( (char *) &fileName, ":" ); diff --git a/sys/fs/vfs/stat.c b/sys/fs/vfs/stat.c index 7f8c570..ff102b6 100644 --- a/sys/fs/vfs/stat.c +++ b/sys/fs/vfs/stat.c @@ -121,6 +121,55 @@ return(error); } +int sys_fstatat(struct thread *td, struct sys_fstatat_args *args) { + int error = 0; + + struct file *fdd = 0x0; + fileDescriptor_t *fd = 0x0; + struct stat *sb = 0x0; + int uP = 0x0; + + //kprintf("FSTATAT(%i:%s:%s)", args->fd, args->path, args->flag); + + if (strlen(args->path) > 0) { + fd = fopen(args->path,"rb"); + uP = 1; + } + else { + getfd(td, &fdd, args->fd); + if (fdd == 0 || fdd->fd == 0x0) { + error = -1; + } + else { + fd = fdd->fd; + } + } + + if (fd == 0x0) { + error = -1; + } + else { + sb = args->buf; + sb->st_dev = 0xDEADBEEF; + sb->st_ino = fd->ino; + sb->st_mode = fd->inode.u.ufs2_i.di_mode; + sb->st_nlink = fd->inode.u.ufs2_i.di_nlink; + sb->st_uid = fd->inode.u.ufs2_i.di_uid; + sb->st_gid = fd->inode.u.ufs2_i.di_gid; + sb->st_rdev = 0xBEEFDEAD; + sb->st_size = fd->inode.u.ufs2_i.di_size; + sb->st_atime = fd->inode.u.ufs2_i.di_atime; + sb->st_mtime = fd->inode.u.ufs2_i.di_mtime; + sb->st_ctime = fd->inode.u.ufs2_i.di_ctime; + //kprintf("FSTAT(%i:%s:%i)=st_ino 0x%X, st_mode=0x%X, st_uid %i, st_gid %i, st_size=0x%X:0x%X", args->fd, args->path, args->flag, sb->st_ino, sb->st_mode, sb->st_uid, sb->st_gid, sb->st_size, fd->size); + if (uP == 1) + fclose(fd); + } + + td->td_retval[0] = error; + return(error); +} + int sys_fstatfs(struct thread *td, struct sys_fstatfs_args *args) { int error = 0; @@ -180,6 +229,67 @@ } +int sys_statfs(struct thread *td, struct sys_statfs_args *args) { + int error = 0; + fileDescriptor_t *fd = 0x0; + + fd = fopen(args->path, "rb"); + + if (fd == 0) { + error = -1; + } + else { + /* + args->buf->st_dev = 0xDEADBEEF; + args->buf->st_ino = fd->fd->ino; + args->buf->st_mode = fd->fd->inode.u.ufs2_i.di_mode; + args->buf->st_nlink = fd->fd->inode.u.ufs2_i.di_nlink; + args->buf->st_uid = fd->fd->inode.u.ufs2_i.di_uid; + args->buf->st_gid = fd->fd->inode.u.ufs2_i.di_gid; + args->buf->st_rdev = 0xBEEFDEAD; + args->buf->st_size = fd->fd->inode.u.ufs2_i.di_size; + args->buf->st_atime = fd->fd->inode.u.ufs2_i.di_atime; + args->buf->st_mtime = fd->fd->inode.u.ufs2_i.di_mtime; + args->buf->st_ctime = fd->fd->inode.u.ufs2_i.di_ctime; + //MrOlsen kprintf("LSTAT(%i)=st_ino 0x%X, st_mode=0x%X, st_uid %i, st_gid %i, st_size=0x%X", error, args->buf->st_ino, args->buf->st_mode, args->buf->st_uid, args->buf->st_gid, args->buf->st_size); + //fclose(fd); + */ + +//kprintf("sFS: %s", args->path); + +args->buf->f_version=0x20030518; +args->buf->f_type=0x35; +args->buf->f_flags=0x1000; +args->buf->f_bsize=0x1000; +args->buf->f_iosize=0x8000; +args->buf->f_blocks=0x7bf9d; +args->buf->f_bfree=0x73c0c; +args->buf->f_bavail=0x69d5c; +args->buf->f_files=0x3fffe; +args->buf->f_ffree=0x3d3f0; +args->buf->f_syncwrites=0x75232; +args->buf->f_asyncwrites=0x2b804; +args->buf->f_syncreads=0x2edea; +args->buf->f_asyncreads=0x6182; +args->buf->f_namemax=0xFF; +args->buf->f_owner=0x0; +args->buf->f_fsid.val[0]=0x5A31F4F0; +args->buf->f_fsid.val[1]=0x65E7C98F; +//args->buf->f_charspare= {""}; +sprintf(args->buf->f_fstypename, "ufs"); +sprintf(args->buf->f_mntfromname, "/dev/ada0s1a"); +sprintf(args->buf->f_mntonname,"/"); + + + } + + td->td_retval[0] = error; + return(error); + + +} + + /* Return stat of path do not follow if link return stat of link */ int sys_lstat(struct thread *td, struct sys_lstat_args *args) { td->td_retval[0] = _sys_stat(args->path, args->sb, STAT_LSTAT); diff --git a/sys/include/net/lwipopts.h b/sys/include/net/lwipopts.h index e9eb0b7..f648244 100644 --- a/sys/include/net/lwipopts.h +++ b/sys/include/net/lwipopts.h @@ -138,7 +138,7 @@ #define LWIP_MULTICAST_PING 0 -#define LWIP_RAW 0 +#define LWIP_RAW 1 #define RAW_TTL (IP_DEFAULT_TTL) @@ -199,7 +199,7 @@ #define TCP_OVERSIZE TCP_MSS -#define LWIP_TCP_TIMESTAMPS 0 +#define LWIP_TCP_TIMESTAMPS 1 #define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 4), (TCP_MSS * 4)) @@ -270,7 +270,7 @@ #define LWIP_NETCONN 1 -#define LWIP_TCPIP_TIMEOUT 0 +#define LWIP_TCPIP_TIMEOUT 1 #define LWIP_NETCONN_SEM_PER_THREAD 0 @@ -286,9 +286,9 @@ #define LWIP_TCP_KEEPALIVE 0 -#define LWIP_SO_SNDTIMEO 0 +#define LWIP_SO_SNDTIMEO 1 -#define LWIP_SO_RCVTIMEO 0 +#define LWIP_SO_RCVTIMEO 1 #define LWIP_SO_SNDRCVTIMEO_NONSTANDARD 0 diff --git a/sys/include/sys/descrip.h b/sys/include/sys/descrip.h index 2cfc903..84cd2a6 100644 --- a/sys/include/sys/descrip.h +++ b/sys/include/sys/descrip.h @@ -103,6 +103,8 @@ uint16_t f_type; struct fileOps *f_ops; fileDescriptor_t *fd; + int fd_type; + int socket; }; struct fileOps { diff --git a/sys/include/sys/sysproto.h b/sys/include/sys/sysproto.h index e90f829..ebb86b9 100644 --- a/sys/include/sys/sysproto.h +++ b/sys/include/sys/sysproto.h @@ -515,6 +515,51 @@ char amode_l_[PADL_(int)]; int amode; char amode_r_[PADR_(int)]; }; +struct sys_statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; + +struct sys_fstatat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct stat *)]; struct stat * buf; char buf_r_[PADR_(struct stat *)]; + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; + +struct sys_fchdir_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; + +struct sys_getdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(u_int)]; u_int count; char count_r_[PADR_(u_int)]; + char basep_l_[PADL_(long *)]; long * basep; char basep_r_[PADR_(long *)]; +}; + +struct sys_socket_args { + char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)]; + char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)]; + char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)]; +}; + +struct sys_setsockopt_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; + char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)]; + char valsize_l_[PADL_(int)]; int valsize; char valsize_r_[PADR_(int)]; +}; + +struct sys_select_args { + char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)]; + char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)]; + char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)]; + char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)]; + char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)]; +}; + //Func Defs int sys_invalid(struct thread *, void *); @@ -555,10 +600,12 @@ int fstatfs(struct thread *td, struct sys_fstatfs_args *uap); int mprotect(struct thread *td, struct mprotect_args *uap); +int sys_statfs(struct thread *td, struct sys_statfs_args *args); int sys_fstatfs(struct thread *td, struct sys_fstatfs_args *); int sys_stat(struct thread *td, struct sys_stat_args *); int sys_lstat(struct thread *td, struct sys_lstat_args *); int sys_fstat(struct thread *td, struct sys_fstat_args *); +int sys_fstatat(struct thread *td, struct sys_fstatat_args *); int sys_openat(struct thread *td, struct sys_openat_args *); int sys_sysarch(struct thread *td, struct sys_sysarch_args *); @@ -581,9 +628,11 @@ int sys_setpgid(struct thread *td, struct sys_setpgid_args *); int sys_access(struct thread *td, struct sys_access_args *); +int sys_fchdir(struct thread *td, struct sys_fchdir_args *); + +int sys_getdirentries(struct thread *td, struct sys_getdirentries_args *); + +int sys_socket(struct thread *td, struct sys_socket_args *); +int sys_setsockopt(struct thread *td, struct sys_setsockopt_args *); +int sys_select(sutrct thread *td, struct sys_select_args *); #endif - -/*** - END - ***/ - diff --git a/sys/include/vfs/file.h b/sys/include/vfs/file.h index 5812344..a4ae543 100644 --- a/sys/include/vfs/file.h +++ b/sys/include/vfs/file.h @@ -76,6 +76,7 @@ int dsk_meta; uint32_t resid; struct inode inode; + int fd_type; } fileDescriptor_t; typedef struct userFileDescriptorStruct { diff --git a/sys/kernel/gen_calls.c b/sys/kernel/gen_calls.c index 336c5e5..9513da1 100644 --- a/sys/kernel/gen_calls.c +++ b/sys/kernel/gen_calls.c @@ -144,7 +144,7 @@ int sys_wait4(struct thread *td, struct sys_wait4_args *args) { int error = 0; - kprintf("wait4: %i", args->pid); + //MrOlsen 2018kprintf("wait4: %i", args->pid); if (args->pid == -1) { diff --git a/sys/kernel/syscalls_posix.c b/sys/kernel/syscalls_posix.c index 0e36407..934a7fb 100644 --- a/sys/kernel/syscalls_posix.c +++ b/sys/kernel/syscalls_posix.c @@ -43,8 +43,8 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, { 0, "No Call", sys_invalid, SYSCALL_VALID }, { 0, "No Call", sys_invalid, SYSCALL_VALID }, - { ARG_COUNT(sys_chdir_args), "Change Dir", (sys_call_t *) sys_chdir, SYSCALL_VALID }, - { 0, "No Call", sys_invalid, SYSCALL_VALID }, + { ARG_COUNT(sys_chdir_args), "Change Dir", (sys_call_t *) sys_chdir, SYSCALL_VALID }, // 12 - chdir + { ARG_COUNT(sys_fchdir_args), "fchdir", sys_fchdir, SYSCALL_VALID }, // 13 - fchdir { 0, "No Call", sys_invalid, SYSCALL_VALID }, { 0, "No Call", sys_invalid, SYSCALL_VALID }, { 0, "No Call", sys_invalid, SYSCALL_VALID }, @@ -124,11 +124,11 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 90 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 91 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 92 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 93 - Invalid */ + { ARG_COUNT(sys_select_args), "select", sys_select, SYSCALL_VALID }, // 93 - select { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 94 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 95 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 96 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 97 - Invalid */ + { ARG_COUNT(sys_socket_args), "socket", sys_socket, SYSCALL_VALID }, // 97 - socket { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 98 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 99 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 100 - Invalid */ @@ -136,7 +136,7 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 102 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 103 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 104 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 105 - Invalid */ + { ARG_COUNT(sys_setsockopt_args), "setsockopt", sys_setsockopt, SYSCALL_VALID }, // 105 setsockopt { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 106 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 107 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 108 - Invalid */ @@ -227,7 +227,7 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 193 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 194 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 195 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 196 - Invalid */ + { ARG_COUNT(sys_getdirentries_args), "getdirentries", sys_getdirentries, SYSCALL_VALID }, // 196 - getdirentries { ARG_COUNT(sys_mmap_args), "MMAP", (sys_call_t *) sys_mmap, SYSCALL_VALID }, /* 197 - sys_mmap */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 198 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 199 - Invalid */ @@ -427,8 +427,8 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 383 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 384 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 385 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 386 - Invalid */ - { ARG_COUNT(sys_fstatfs_args), "fstatfs", (sys_call_t *) sys_fstatfs, SYSCALL_VALID }, /* 397 fstatfs */ + { ARG_COUNT(sys_statfs_args), "statfs", (sys_call_t *) sys_statfs, SYSCALL_VALID }, // 396 statfs + { ARG_COUNT(sys_fstatfs_args), "fstatfs", (sys_call_t *) sys_fstatfs, SYSCALL_VALID }, // 397 fstatfs { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 398 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 399 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 400 - Invalid */ @@ -524,7 +524,7 @@ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 350 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 351 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 352 - Invalid */ - { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 353 - Invalid */ + { ARG_COUNT(sys_fstatat_args), "fstatat", sys_fstatat, SYSCALL_VALID }, // 493 - fstatat { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 354 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 355 - Invalid */ { 0, "No Call", sys_invalid, SYSCALL_VALID }, /* 356 - Invalid */ diff --git a/sys/kernel/vfs_calls.c b/sys/kernel/vfs_calls.c index b748804..0ff5785 100644 --- a/sys/kernel/vfs_calls.c +++ b/sys/kernel/vfs_calls.c @@ -32,6 +32,7 @@ #include #include #include +#include int sys_open(struct thread *td, struct sys_open_args *args) { int error = 0x0; @@ -43,7 +44,8 @@ if (error) return (error); - nfp->fd = fopen(args->path, "r"); + kprintf("sO: 0x%X:%s", args->mode, args->path); + nfp->fd = fopen(args->path, "rb"); if (nfp->fd == 0x0) { fdestroy(td, nfp, fd); @@ -60,7 +62,6 @@ int sys_close(struct thread *td, struct sys_close_args *args) { struct file *fd = 0x0; - getfd(td, &fd, args->fd); if (fd == 0x0) { @@ -119,6 +120,9 @@ if ( c == '\n') buf[x++] = '\n'; + bf[0] = '\n'; + kprint(bf); + //MROlsen 2018 kprintf("READ: %i", x); td->td_retval[0] = x; @@ -162,3 +166,33 @@ td->td_retval[0] = 0; return(0); } + +int sys_getdirentries(struct thread *td, struct sys_getdirentries_args *args) { + //kprintf("GDE: [%i:%i:0x%X]", args->fd, args->count, args->basep); + struct file *fd = 0x0; + getfd(td, &fd, args->fd); + + char buf[DEV_BSIZE]; + struct dirent *d; + char *s; + ssize_t n; + + //fd->offset = 0; + td->td_retval[0] = fread(args->buf, args->count, 1, fd->fd); + //n = fsread(fd->fd->ino, args->buf, DEV_BSIZE, fd->fd); + //td->td_retval[0] = n; + + /* + while ((n = fsread(*ino, buf, DEV_BSIZE, fd)) > 0) + for (s = buf; s < buf + DEV_BSIZE;) { + d = (void *) s; + if (!strcmp(name, d->d_name)) { + *ino = d->d_fileno; + return d->d_type; + } + s += d->d_reclen; + } +*/ + + return(0); +} diff --git a/sys/net/api/sockets.c b/sys/net/api/sockets.c index 884922b..977406c 100644 --- a/sys/net/api/sockets.c +++ b/sys/net/api/sockets.c @@ -44,6 +44,7 @@ * */ +#include #include #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ @@ -2194,6 +2195,7 @@ u8_t err = 0; struct lwip_sock *sock = get_socket(s); #if !LWIP_TCPIP_CORE_LOCKING +kprintf("%s:%i: %i", __FILE__, __LINE__, err); LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); #endif /* !LWIP_TCPIP_CORE_LOCKING */ @@ -2207,19 +2209,24 @@ } #if LWIP_TCPIP_CORE_LOCKING +kprintf("%s:%i: %i", __FILE__, __LINE__, err); /* core-locking can just call the -impl function */ LOCK_TCPIP_CORE(); err = lwip_setsockopt_impl(s, level, optname, optval, optlen); UNLOCK_TCPIP_CORE(); +kprintf("%s:%i: %i", __FILE__, __LINE__, err); #else /* LWIP_TCPIP_CORE_LOCKING */ #if LWIP_MPU_COMPATIBLE +kprintf("%s:%i: %i", __FILE__, __LINE__, err); /* MPU_COMPATIBLE copies the optval data, so check for max size here */ if (optlen > LWIP_SETGETSOCKOPT_MAXOPTLEN) { sock_set_errno(sock, ENOBUFS); +kprintf("%s:%i: %i", __FILE__, __LINE__, err); return -1; } +kprintf("%s:%i: %i", __FILE__, __LINE__, err); #endif /* LWIP_MPU_COMPATIBLE */ LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(data, sock); @@ -2251,6 +2258,8 @@ LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data); #endif /* LWIP_TCPIP_CORE_LOCKING */ +kprintf("%s:%i: %i", __FILE__, __LINE__, err); + sock_set_errno(sock, err); return err ? -1 : 0; } diff --git a/sys/net/net/sys_arch.c b/sys/net/net/sys_arch.c index 63890bc..869caaa 100644 --- a/sys/net/net/sys_arch.c +++ b/sys/net/net/sys_arch.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "net/debug.h" #include "net/sys.h" @@ -480,3 +482,81 @@ uint32_t sys_now() { return (sys_unix_now()); } + + +int sys_socket(struct thread *td, struct sys_socket_args *args) { + int error = 0x0; + int fd = 0x0; + struct file *nfp = 0x0; + + error = falloc(td, &nfp, &fd); + + if (error) + return (error); + + nfp->socket = lwip_socket(args->domain, args->type, args->protocol); + nfp->fd_type = 2; + kprintf("socket(%i:%i): 0x%X:0x%X:0x%X", nfp->socket, fd, args->domain, args->type, args->protocol); + + if (nfp->fd == 0x0 && nfp->socket) { + fdestroy(td, nfp, fd); + + td->td_retval[0] = -1; + error = -1; + } + else { + td->td_retval[0] = fd;//nfp->fd; //MrOlsen 2018index; + } + + return (error); +} + +int sys_setsockopt(struct thread *td, struct sys_setsockopt_args *args) { + struct file *fd = 0x0; + getfd(td, &fd, args->s); + + td->td_retval[0] = lwip_setsockopt(fd->socket, args->level, args->name, args->val, args->valsize); + kprintf("SSO: %i:%i:%i", args->s, fd->socket, td->td_retval[0]); + td->td_retval[0] = 0; + + return(0); +} + +int sys_select(struct thread *td, struct sys_select_args *args) { + int error = 0; + int i = 0; + + fd_set rfds; + fd_set wfds; + fd_set efds; + + FD_ZERO(&rfds); + FD_ZERO(&wfds); + FD_ZERO(&efds); + + if (args->in != 0x0) { + for (i = 0;i < args->nd;i++) { + rfds[i] = (struct file *)td->o_files[args->in[0]].socket; + } + } + + if (args->ou != 0x0) { + rfds = (fd_set *)kmalloc(sizeof(fd_set) * args->nd); + for (i = 0;i < args->nd;i++) { + rfds[i] = (struct file *)td->o_files[args->ou[0]].socket; + } + } + + if (args->ex != 0x0) { + rfds = (fd_set *)kmalloc(sizeof(fd_set) * args->nd); + for (i = 0;i < args->nd;i++) { + rfds[i] = (struct file *)td->o_files[args->ex[0]].socket; + } + } + + + if ((td->td_retval[0] = lwip_select(nd,&rfds,&wfds,&efds,args->timeval)) == -1) + error = -1; + + return(error); +}