2017-06-16 00:36:39 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2017. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License. ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-11-03 17:03:39 +01:00
|
|
|
$Revision$
|
2017-06-16 00:36:39 +02:00
|
|
|
|
2017-12-20 02:07:10 +01:00
|
|
|
ENOENT = 2
|
|
|
|
EBADF = 9
|
|
|
|
EFAULT = 14
|
|
|
|
;EINVAL = 22 11 defined in stack.inc
|
|
|
|
ENFILE = 23
|
|
|
|
EMFILE = 24
|
|
|
|
EPIPE = 32
|
|
|
|
|
|
|
|
FILEOP_CLOSE = 0
|
|
|
|
FILEOP_READ = 1
|
|
|
|
FILEOP_WRITE = 2
|
2017-06-16 00:36:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
include "futex.inc"
|
|
|
|
|
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
sys_futex_call:
|
|
|
|
dd sys_futex.destroy ;1
|
|
|
|
dd sys_futex.wait ;2
|
|
|
|
dd sys_futex.wake ;3
|
|
|
|
dd sys_futex.requeue ;4
|
|
|
|
dd sys_futex.cmp_requeue ;5
|
|
|
|
dd sys_futex.wait_bitset ;6
|
|
|
|
dd sys_futex.wake_bitset ;7
|
|
|
|
endg
|
|
|
|
|
|
|
|
include "pipe.inc"
|
|
|
|
|
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
sys_posix_call:
|
|
|
|
dd sys_futex.init ;0 futex_init
|
|
|
|
dd sys_futex ;1 futex_destroy
|
|
|
|
dd sys_futex ;2 futex_wait
|
|
|
|
dd sys_futex ;3 futex_wake
|
|
|
|
dd sys_futex ;4 reserved
|
|
|
|
dd sys_futex ;5 reserved
|
|
|
|
dd sys_futex ;6 reserved
|
|
|
|
dd sys_futex ;7 reserved
|
|
|
|
dd sys_posix.fail ;8 sys_open
|
|
|
|
dd sys_posix.fail ;9 sys_close
|
2017-06-16 09:53:37 +02:00
|
|
|
dd sys_read ;10 read()
|
|
|
|
dd sys_write ;11 write()
|
2017-06-16 00:36:39 +02:00
|
|
|
dd sys_posix.fail ;12 sys_dup3
|
|
|
|
dd sys_pipe2 ;13
|
|
|
|
.end:
|
|
|
|
endg
|
|
|
|
|
|
|
|
align 4
|
|
|
|
sys_posix:
|
|
|
|
cmp ebx, (sys_posix_call.end-sys_posix_call)/4
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
jmp dword [sys_posix_call+ebx*4]
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
mov [esp+SYSCALL_STACK._eax], -EBADF
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;ssize_t read(int fd, void *buf, size_t count);
|
|
|
|
; ecx fd
|
|
|
|
; edx buf
|
|
|
|
; esi count
|
|
|
|
|
|
|
|
align 4
|
|
|
|
sys_read:
|
|
|
|
cmp ecx, STDERR_FILENO
|
|
|
|
jbe .fail
|
|
|
|
cmp ecx, (PROC.pdt_0 - PROC.htab)/4
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
mov edi, [current_process]
|
|
|
|
mov ebp, [edi+PROC.htab+ecx*4]
|
|
|
|
|
|
|
|
cmp [ebp+FILED.magic], 'PIPE'
|
|
|
|
jne .fail
|
|
|
|
cmp [ebp+FILED.handle], ecx
|
|
|
|
jne .fail
|
|
|
|
|
2017-06-17 00:47:00 +02:00
|
|
|
test [ebp+FILED.mode], F_READ
|
|
|
|
jz .fail
|
|
|
|
|
2017-06-16 00:36:39 +02:00
|
|
|
mov ebp, [ebp+FILED.file]
|
|
|
|
mov eax, [ebp]
|
|
|
|
jmp dword [eax+FILEOP_READ*4]
|
|
|
|
.fail:
|
|
|
|
mov [esp+SYSCALL_STACK._eax], -EBADF
|
|
|
|
ret
|
|
|
|
|
2017-06-16 09:53:37 +02:00
|
|
|
;ssize_t write(int fd, const void *buf, size_t count);
|
|
|
|
; ecx fd
|
|
|
|
; edx buf
|
|
|
|
; esi count
|
|
|
|
|
|
|
|
align 4
|
|
|
|
sys_write:
|
|
|
|
cmp ecx, STDERR_FILENO
|
|
|
|
jbe .fail
|
|
|
|
cmp ecx, (PROC.pdt_0 - PROC.htab)/4
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
mov edi, [current_process]
|
|
|
|
mov ebp, [edi+PROC.htab+ecx*4]
|
|
|
|
|
|
|
|
cmp [ebp+FILED.magic], 'PIPE'
|
|
|
|
jne .fail
|
|
|
|
cmp [ebp+FILED.handle], ecx
|
|
|
|
jne .fail
|
2017-06-17 00:47:00 +02:00
|
|
|
test [ebp+FILED.mode], F_WRITE
|
|
|
|
jz .fail
|
2017-06-16 09:53:37 +02:00
|
|
|
|
|
|
|
mov ebp, [ebp+FILED.file]
|
|
|
|
mov eax, [ebp]
|
|
|
|
jmp dword [eax+FILEOP_WRITE*4]
|
|
|
|
.fail:
|
|
|
|
mov [esp+SYSCALL_STACK._eax], -EBADF
|
|
|
|
ret
|
|
|
|
|