From: DeaDDooMER Date: Tue, 30 Jul 2019 18:38:45 +0000 (+0300) Subject: make common posix bindings X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=4257db65ead872485357beb6f30c0f0fa6e7009c;p=cpc.git make common posix bindings --- diff --git a/src/cpfront/linux/486/Posix/Mod/Csignal.cp b/src/cpfront/linux/486/Posix/Mod/Csignal.cp index 43100ca..1e2c77d 100644 --- a/src/cpfront/linux/486/Posix/Mod/Csignal.cp +++ b/src/cpfront/linux/486/Posix/Mod/Csignal.cp @@ -101,8 +101,6 @@ MODULE PosixCsignal ['signal.h']; SIGTTOU* = 22; SIGUSR1* = 10; SIGUSR2* = 12; - SIGPOLL* = 29; - SIGPROF* = 27; SIGSYS* = 31; SIGTRAP* = 5; SIGURG* = 23; @@ -122,9 +120,9 @@ MODULE PosixCsignal ['signal.h']; TYPE Pstruct_sigaction* = POINTER TO struct_sigaction; struct_sigaction* ['struct sigaction'] = RECORD [noalign] (* 140 *) - handler*: RECORD [union] (* 4 *) - sa_handler*: PROCEDURE [ccall] (sig: int); (* 0+4 *) - sa_sigaction*: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *) + handler* ["/*handler"]: RECORD [union] (* 4 *) + sa_handler* ["*/sa_handler"]: PROCEDURE [ccall] (sig: int); (* 0+4 *) + sa_sigaction* ["*/sa_sigaction"]: PROCEDURE [ccall] (sig: int; IN siginfo: siginfo_t; context: PosixCtypes.Pvoid); (* 0+4 *) END; (* 0+4 *) sa_mask*: sigset_t; (* 4+128 *) sa_flags*: int; (* 132+4 *) @@ -141,7 +139,6 @@ MODULE PosixCsignal ['signal.h']; SA_RESETHAND* = -2147483648; SA_RESTART* = 268435456; SA_SIGINFO* = 4; - SA_NOCLDWAIT* = 2; SA_NODEFER* = 1073741824; SS_ONSTACK* = 1; SS_DISABLE* = 2; @@ -207,49 +204,32 @@ MODULE PosixCsignal ['signal.h']; ss_size*: size_t; (* 8+4 *) END; - TYPE - P_siginfo_t* = POINTER TO _siginfo_t; - _siginfo_t* ['siginfo_t'] = RECORD [noalign] (* 128 *) - si_signo*: int; (* 0+4 *) - si_errno*: int; (* 4+4 *) - si_code*: int; (* 8+4 *) - si_pid*: pid_t; (* 12+4 *) - si_addr*: PosixCtypes.Pvoid; (* 12+4 *) - si_band*: long; (* 12+4 *) - si_uid*: uid_t; (* 16+4 *) - si_status*: int; (* 20+4 *) - si_value*: union_sigval; (* 20+4 *) - END; - TYPE Psiginfo_t* = POINTER TO siginfo_t; siginfo_t* ['siginfo_t'] = RECORD [noalign] (* 128 *) si_signo*: int; (* 0+4 *) si_errno*: int; (* 4+4 *) si_code*: int; (* 8+4 *) - info*: RECORD [union] (* 12 *) + info* ["/*info"]: RECORD [union] (* 12 *) sigill*: RECORD [noalign] (* 4 *) - si_addr*: PosixCtypes.Pvoid; (* 0+4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) END; (* 0+4 *) sigfpe*: RECORD [noalign] (* 4 *) - si_addr*: PosixCtypes.Pvoid; (* 0+4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) END; (* 0+4 *) sigsegv*: RECORD [noalign] (* 4 *) - si_addr*: PosixCtypes.Pvoid; (* 0+4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) END; (* 0+4 *) sigbus*: RECORD [noalign] (* 4 *) - si_addr*: PosixCtypes.Pvoid; (* 0+4 *) + si_addr* ["*/si_addr"]: PosixCtypes.Pvoid; (* 0+4 *) END; (* 0+4 *) sigchld*: RECORD [noalign] (* 12 *) - si_pid*: pid_t; (* 0+4 *) - si_uid*: uid_t; (* 4+4 *) - si_status*: int; (* 8+4 *) + si_pid* ["*/si_pid"]: pid_t; (* 0+4 *) + si_uid* ["*/si_uid"]: uid_t; (* 4+4 *) + si_status* ["*/si_status"]: int; (* 8+4 *) END; (* 0+12 *) - sigpoll*: RECORD [noalign] (* 4 *) - si_band*: long; (* 0+4 *) - END; (* 0+4 *) other*: RECORD [noalign] (* 4 *) - si_value*: union_sigval; (* 0+4 *) + si_value* ["*/si_value"]: union_sigval; (* 0+4 *) END; (* 8+4 *) END; (* 12+12 *) END; @@ -291,14 +271,6 @@ MODULE PosixCsignal ['signal.h']; CLD_STOPPED* = 5; CLD_CONTINUED* = 6; - CONST - POLL_IN* = 1; - POLL_OUT* = 2; - POLL_MSG* = 3; - POLL_ERR* = 4; - POLL_PRI* = 5; - POLL_HUP* = 6; - CONST SI_USER* = 0; SI_QUEUE* = -1; @@ -311,7 +283,7 @@ MODULE PosixCsignal ['signal.h']; PROCEDURE [ccall] psiginfo* (IN pinfo: siginfo_t; IN [nil] s: ARRAY [untagged] OF SHORTCHAR); PROCEDURE [ccall] psignal* (sig: int; IN [nil] s: ARRAY [untagged] OF SHORTCHAR); PROCEDURE [ccall] pthread_kill* (thread: pthread_t; sig: int): int; - PROCEDURE [ccall] pthread_sigmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int; + PROCEDURE [ccall] pthread_sigmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oldset: sigset_t): int; PROCEDURE [ccall] raise* (sig: int): int; PROCEDURE [ccall] sigaction* (sig: int; IN [nil] act: struct_sigaction; VAR [nil] oact: struct_sigaction): int; PROCEDURE [ccall] sigaddset* (VAR set: sigset_t; signum: int): int; @@ -319,18 +291,13 @@ MODULE PosixCsignal ['signal.h']; PROCEDURE [ccall] sigdelset* (VAR set: sigset_t; signum: int): int; PROCEDURE [ccall] sigemptyset* (VAR set: sigset_t): int; PROCEDURE [ccall] sigfillset* (VAR set: sigset_t): int; - PROCEDURE [ccall] sighold* (sig: int): int; - PROCEDURE [ccall] sigignore* (sig: int): int; - PROCEDURE [ccall] siginterrupt* (sig, flag: int): int; - PROCEDURE [ccall] sigismember* (IN set: sigset_t; signum: int): int; - PROCEDURE [ccall] sigpause* (sig: int): int; + PROCEDURE [ccall] sigismember* (VAR set: sigset_t; signum: int): int; PROCEDURE [ccall] sigpending* (VAR set: sigset_t): int; - PROCEDURE [ccall] sigprocmask* (how: int; IN [nil] set: sigset_t; VAR [nil] oset: sigset_t): int; + PROCEDURE [ccall] sigprocmask* (how: int; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): int; PROCEDURE [ccall] sigqueue* (pid: pid_t; sig: int; IN value: union_sigval): int; - PROCEDURE [ccall] sigrelse* (sig: int): int; - PROCEDURE [ccall] sigsuspend* (IN sigmask: sigset_t): int; - PROCEDURE [ccall] sigtimedwait* (IN set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int; - PROCEDURE [ccall] sigwait* (IN set: sigset_t; VAR sig: int): int; - PROCEDURE [ccall] sigwaitinfo* (IN set: sigset_t; VAR [nil] info: siginfo_t): int; + PROCEDURE [ccall] sigsuspend* (VAR sigmask: sigset_t): int; + PROCEDURE [ccall] sigtimedwait* (VAR set: sigset_t; VAR [nil] info: siginfo_t; IN timeout: struct_timespec): int; + PROCEDURE [ccall] sigwait* (VAR set: sigset_t; VAR sig: int): int; + PROCEDURE [ccall] sigwaitinfo* (VAR set: sigset_t; VAR [nil] info: siginfo_t): int; END PosixCsignal. diff --git a/src/cpfront/linux/486/Posix/Mod/Csys_mman.cp b/src/cpfront/linux/486/Posix/Mod/Csys_mman.cp index 6ff9357..d27cecd 100644 --- a/src/cpfront/linux/486/Posix/Mod/Csys_mman.cp +++ b/src/cpfront/linux/486/Posix/Mod/Csys_mman.cp @@ -51,10 +51,6 @@ MODULE PosixCsys_mman ['sys/mman.h']; MS_INVALIDATE* = 2; MS_SYNC* = 4; - CONST - MCL_CURRENT* = 1; - MCL_FUTURE* = 2; - CONST MAP_FAILED* = -1; @@ -71,12 +67,10 @@ MODULE PosixCsys_mman ['sys/mman.h']; size_t* = PosixCsys_types.size_t; PROCEDURE [ccall] mlock* (addr: PosixCtypes.Pvoid; len: size_t): int; - PROCEDURE [ccall] mlockall* (flags: int): int; PROCEDURE [ccall] mmap* (addr: PosixCtypes.Pvoid; len: size_t; prot, flags, fildes: int; off: off_t): PosixCtypes.Pvoid; PROCEDURE [ccall] mprotect* (addr: PosixCtypes.Pvoid; len: size_t; prot: int): int; PROCEDURE [ccall] msync* (addr: PosixCtypes.Pvoid; len: size_t; flags: int): int; PROCEDURE [ccall] munlock* (addr: PosixCtypes.Pvoid; len: size_t): int; - PROCEDURE [ccall] munlockall* (): int; PROCEDURE [ccall] munmap* (addr: PosixCtypes.Pvoid; len: size_t): int; PROCEDURE [ccall] posix_madvise* (addr: PosixCtypes.Pvoid; len: size_t; advice: int): int; PROCEDURE [ccall] posix_mem_offset* (addr: PosixCtypes.Pvoid; len: size_t; VAR off: off_t; VAR contng_len: size_t; VAR fildes: int): int; diff --git a/src/cpfront/posix/generic/System/Mod/Kernel.cp b/src/cpfront/posix/generic/System/Mod/Kernel.cp index bf9e33d..7c2c0bf 100644 --- a/src/cpfront/posix/generic/System/Mod/Kernel.cp +++ b/src/cpfront/posix/generic/System/Mod/Kernel.cp @@ -203,8 +203,8 @@ MODULE Kernel; trapCount-: INTEGER; err-, pc-, sp-, fp-, stack-, val-: INTEGER; - isTry: BOOLEAN; - startEnv: setjmp.sigjmp_buf; + isTry, checkReadable: BOOLEAN; + startEnv, checkReadableEnv: setjmp.sigjmp_buf; tryEnv: setjmp.jmp_buf; startDLink, tryDLink: DLink; @@ -538,11 +538,24 @@ MODULE Kernel; PROCEDURE^ Try* (h: TryHandler; a, b, c: INTEGER); PROCEDURE IsReadable* (from, to: INTEGER): BOOLEAN; - VAR i: INTEGER; + VAR r: BOOLEAN; res: setjmp.int; i: INTEGER; x: BYTE; BEGIN - i := trapCount; - Try(TryRead, from, to, 0); - RETURN trapCount = i + r := checkReadable; + checkReadable := TRUE; + res := setjmp.sigsetjmp(checkReadableEnv, 1); + IF res = 0 THEN + IF from <= to THEN + FOR i := from TO to DO + S.GET(i, x) + END + ELSE + FOR i := to TO from BY -1 DO + S.GET(i, x) + END + END + END; + checkReadable := r; + RETURN res = 0 END IsReadable; (* --------------------- NEW implementation (portable) -------------------- *) @@ -1754,20 +1767,21 @@ MODULE Kernel; stdlib.abort END Trap; - PROCEDURE [ccall] TrapHandler (signo: signal.int; IN _info: signal.siginfo_t; context: ADDRESS); - TYPE SigInfo = POINTER [untagged] TO signal._siginfo_t; - VAR res: signal.int; info: SigInfo; + PROCEDURE [ccall] TrapHandler (signo: signal.int; IN info: signal.siginfo_t; context: ADDRESS); + VAR res: signal.int; BEGIN - info := S.VAL(SigInfo, S.ADR(_info)); (* !!! hack for CPfront *) + IF checkReadable THEN + setjmp.siglongjmp(checkReadableEnv, 1) + END; IF trapped THEN DefaultTrapViewer; IF ~secondTrap THEN trapped := FALSE; secondTrap := TRUE END END; - err := -signo; pc := 0; sp := 0; fp := 0; stack := 0; val := 0; + err := -signo; pc := 0; sp := 0; fp := 0; stack := baseStack; val := 0; CASE signo OF | signal.SIGFPE: - pc := info.si_addr; val := info.si_code; + pc := info.info.sigfpe.si_addr; CASE info.si_code OF | signal.FPE_INTDIV: err := 139 (* division by zero *) | signal.FPE_INTOVF: err := 138 (* integer overflow *) @@ -1783,13 +1797,13 @@ MODULE Kernel; val := info.si_code; err := 200 (* keyboard interrupt *) | signal.SIGSEGV: - val := info.si_addr; + val := info.info.sigsegv.si_addr; err := 203 (* illigal read *) | signal.SIGBUS: - val := info.si_addr; + val := info.info.sigbus.si_addr; err := 10001H (* bus error *) | signal.SIGILL: - pc := info.si_addr; + pc := info.info.sigill.si_addr; err := 202; (* illigal instruction *) IF IsReadable(pc, pc + 4) THEN S.GET(pc, val) @@ -1801,7 +1815,6 @@ MODULE Kernel; (* !!! InitFPU *) TrapCleanup; IF isTry THEN - SetDLink(tryDLink); setjmp._longjmp(tryEnv, 1) END; IF (err = 128) OR (err = 200) & ~intTrap THEN (* do nothing *) @@ -1811,7 +1824,6 @@ MODULE Kernel; END; trapped := FALSE; secondTrap := FALSE; IF restart # NIL THEN - SetDLink(startDLink); setjmp.siglongjmp(startEnv, 1) END; stdlib.abort