Bladeren bron

Kernel: IsReadable implemented

Alexander Shiryaev 12 jaren geleden
bovenliggende
commit
0afec9f6db

BIN
BlackBox/Linux/Lin/Mod/Kernel.odc


+ 17 - 9
BlackBox/Linux/Lin/Mod/Kernel.txt

@@ -16,7 +16,6 @@ MODULE Kernel;
 
 		TODO:
 			handle stack overflow exceptions
-			IsReadable0
 			correct cmdLine
 			Quit from TrapHandler
 	*)
@@ -619,11 +618,21 @@ MODULE Kernel;
 *)
 
 	(* Alexander Shiryaev, 2012.10: Linux: can be implemented through mincore/madvise *)
+	(* This procedure can be called from TrapHandler also *)
 	PROCEDURE IsReadable* (from, to: INTEGER): BOOLEAN;
 		(* check wether memory between from (incl.) and to (excl.) may be read *)
 		VAR res: BOOLEAN; res1: INTEGER;
 			x: SHORTCHAR;
+			mask, omask: Libc.sigset_t;
 	BEGIN
+		(* save old sigmask and unblock SIGSEGV *)
+			res1 := Libc.sigemptyset(S.ADR(mask));
+			ASSERT(res1 = 0, 100);
+			res1 := Libc.sigaddset(S.ADR(mask), Libc.SIGSEGV);
+			ASSERT(res1 = 0, 101);
+			res1 := Libc.sigprocmask(Libc.SIG_UNBLOCK, S.ADR(mask), S.ADR(omask));
+			ASSERT(res1 = 0, 102);
+
 		res := FALSE;
 		res1 := Libc.sigsetjmp(isReadableContext, Libc.TRUE);
 		IF res1 = 0 THEN
@@ -635,18 +644,17 @@ MODULE Kernel;
 			UNTIL from = to;
 			res := TRUE
 		ELSE
-			ASSERT(res1 = 1, 100)
+			ASSERT(res1 = 1, 103)
 		END;
 		isReadableCheck := FALSE;
+
+		(* restore saved sigmask *)
+			res1 := Libc.sigprocmask(Libc.SIG_SETMASK, S.ADR(omask), Libc.NULL);
+			ASSERT(res1 = 0, 104);
+
 		RETURN res
 	END IsReadable;
 
-	(* to call from TrapHandler *)
-	PROCEDURE IsReadable0 (from, to: INTEGER): BOOLEAN;
-	BEGIN
-		RETURN TRUE (* TODO *)
-	END IsReadable0;
-
 	(* --------------------- NEW implementation (portable) -------------------- *)
 
 	PROCEDURE^ NewBlock (size: INTEGER): Block;
@@ -1850,7 +1858,7 @@ MODULE Kernel;
 				err := 200 (* Interrupt (ANSI). *)
 			| Libc.SIGILL: (* Illegal instruction (ANSI). *)
 				err := 202; val := 0;
-				IF IsReadable0(pc, pc + 4) THEN
+				IF IsReadable(pc, pc + 4) THEN
 					S.GET(pc, val);
 					IF val MOD 100H = 8DH THEN	(* lea reg,reg *)
 						IF val DIV 100H MOD 100H = 0F0H THEN

BIN
BlackBox/Linux/Lin/Mod/Libc.odc


+ 6 - 0
BlackBox/Linux/Lin/Mod/Libc.txt

@@ -237,6 +237,10 @@ MODULE LinLibc ["libc.so.6"];
 		O_WRONLY* = {0} ;	(* Open write-only *)
 		O_RDWR* = {1} ;	(* Open read/write *)
 
+		SIG_BLOCK* = 0;	(* Block signals *)
+		SIG_UNBLOCK* = 1;	(* Unblock signals *)
+		SIG_SETMASK* = 2;	(* Set the set of blocked signals *)
+
 		_SC_PAGESIZE* = 30;
 
 		SIGSTKSZ* = 8192;
@@ -457,4 +461,6 @@ MODULE LinLibc ["libc.so.6"];
 	
 	PROCEDURE [ccall] sigaltstack* (VAR [nil] ss: stack_t; VAR [nil] oss: stack_t): INTEGER;
 
+	PROCEDURE [ccall] sigprocmask* (how: INTEGER; set: Ptrsigset_t; oldset: Ptrsigset_t): INTEGER;
+
 END LinLibc.

BIN
BlackBox/Linux/libBB.so


BIN
BlackBox/Linux/libBB0.so


BIN
BlackBox/OpenBSD/Lin/Mod/Kernel.odc


+ 18 - 10
BlackBox/OpenBSD/Lin/Mod/Kernel.txt

@@ -16,7 +16,6 @@ MODULE Kernel;
 
 		TODO:
 			handle stack overflow exceptions
-			IsReadable0
 			correct cmdLine
 			Quit from TrapHandler
 	*)
@@ -617,11 +616,21 @@ MODULE Kernel;
 *)
 
 	(* Alexander Shiryaev, 2012.10: I do not know other way that works in OpenBSD *)
+	(* This procedure can be called from TrapHandler also *)
 	PROCEDURE IsReadable* (from, to: INTEGER): BOOLEAN;
 		(* check wether memory between from (incl.) and to (excl.) may be read *)
 		VAR res: BOOLEAN; res1: INTEGER;
 			x: SHORTCHAR;
+			mask, omask: Libc.sigset_t;
 	BEGIN
+		(* save old sigmask and unblock SIGSEGV *)
+			res1 := Libc.sigemptyset(S.ADR(mask));
+			ASSERT(res1 = 0, 100);
+			res1 := Libc.sigaddset(S.ADR(mask), Libc.SIGSEGV);
+			ASSERT(res1 = 0, 101);
+			res1 := Libc.sigprocmask(Libc.SIG_UNBLOCK, mask, omask);
+			ASSERT(res1 = 0, 102);
+
 		res := FALSE;
 		res1 := Libc.sigsetjmp(isReadableContext, Libc.TRUE);
 		IF res1 = 0 THEN
@@ -633,18 +642,17 @@ MODULE Kernel;
 			UNTIL from = to;
 			res := TRUE
 		ELSE
-			ASSERT(res1 = 1, 100)
+			ASSERT(res1 = 1, 103)
 		END;
 		isReadableCheck := FALSE;
+
+		(* restore saved sigmask *)
+			res1 := Libc.sigprocmask(Libc.SIG_SETMASK, omask, NIL);
+			ASSERT(res1 = 0, 104);
+
 		RETURN res
 	END IsReadable;
 
-	(* to call from TrapHandler *)
-	PROCEDURE IsReadable0 (from, to: INTEGER): BOOLEAN;
-	BEGIN
-		RETURN TRUE (* TODO *)
-	END IsReadable0;
-
 	(* --------------------- NEW implementation (portable) -------------------- *)
 
 	PROCEDURE^ NewBlock (size: INTEGER): Block;
@@ -1897,7 +1905,7 @@ MODULE Kernel;
 		WriteString("================================"); WriteLn
 	END ShowTrap;
 
-	PROCEDURE (* [ccall] *) TrapHandler (sig: INTEGER; siginfo: Libc.Ptrsiginfo_t; context: Libc.Ptrucontext_t);
+	PROCEDURE [ccall] TrapHandler (sig: INTEGER; siginfo: Libc.Ptrsiginfo_t; context: Libc.Ptrucontext_t);
 	BEGIN
 		IF isReadableCheck THEN
 			isReadableCheck := FALSE;
@@ -1934,7 +1942,7 @@ MODULE Kernel;
 				err := 200 (* Interrupt (ANSI). *)
 			| Libc.SIGILL: (* Illegal instruction (ANSI). *)
 				err := 202; val := 0;
-				IF IsReadable0(pc, pc + 4) THEN
+				IF IsReadable(pc, pc + 4) THEN
 					S.GET(pc, val);
 					IF val MOD 100H = 8DH THEN	(* lea reg,reg *)
 						IF val DIV 100H MOD 100H = 0F0H THEN

+ 8 - 1
BlackBox/OpenBSD/Lin/Mod/Libc.txt

@@ -377,6 +377,11 @@ MODULE LinLibc ["libc.so.66.0"];
 		MINSIGSTKSZ* = 8192; (* minimum allowable stack *)
 		SIGSTKSZ* = MINSIGSTKSZ + 32768; (* recommended stack size *)
 
+		(* OpenBSD 5.2 /usr/include/sys/signal.h *)
+		SIG_BLOCK* = 1; (* block specified signal set *)
+		SIG_UNBLOCK* = 2; (* unblock specified signal set *)
+		SIG_SETMASK* = 3; (* set specified signal set *)
+
 	TYPE
 		(* OpenBSD OK *)
 		__ftw_func_t* = PROCEDURE (fileName: PtrSTR; VAR [nil] stat: stat_t; flag: INTEGER): INTEGER; (* OpenBSD 5.2: OK *)
@@ -466,7 +471,7 @@ MODULE LinLibc ["libc.so.66.0"];
 
 		Ptrsigset_t* = INTEGER;
 		sigaction_t* = RECORD [untagged] (* OpenBSD 5.2 /usr/include/sys/signal.h *)
-			sa_sigaction*: PROCEDURE (* [ccall] *) (sig: INTEGER; siginfo: Ptrsiginfo_t; ptr: Ptrucontext_t); (* union with sa_handler*: PtrProc;*)
+			sa_sigaction*: PROCEDURE [ccall] (sig: INTEGER; siginfo: Ptrsiginfo_t; ptr: Ptrucontext_t); (* union with sa_handler*: PtrProc;*)
 			sa_mask*: sigset_t;
 			sa_flags*: SET;
 			(* sa_restorer*: LONGINT; *) (* OpenBSD *)
@@ -775,4 +780,6 @@ MODULE LinLibc ["libc.so.66.0"];
 
 	PROCEDURE [ccall] sigreturn* (ucontext_t: Ptrucontext_t): INTEGER;
 
+	PROCEDURE [ccall] sigprocmask* (how: INTEGER; VAR [nil] set: sigset_t; VAR [nil] oset: sigset_t): INTEGER;
+
 END LinLibc.

BIN
BlackBox/OpenBSD/libBB.so


BIN
BlackBox/OpenBSD/libBB0.so