| author | wenzelm | 
| Tue, 23 Feb 2016 16:20:12 +0100 | |
| changeset 62387 | ad3eb2889f9a | 
| parent 62356 | e307a410f46c | 
| permissions | -rw-r--r-- | 
| 20925 | 1  | 
(* Title: Pure/General/secure.ML  | 
2  | 
Author: Makarius  | 
|
3  | 
||
4  | 
Secure critical operations.  | 
|
5  | 
*)  | 
|
6  | 
||
7  | 
signature SECURE =  | 
|
8  | 
sig  | 
|
| 20977 | 9  | 
val set_secure: unit -> unit  | 
| 20925 | 10  | 
val is_secure: unit -> bool  | 
| 26080 | 11  | 
val deny_secure: string -> unit  | 
| 31330 | 12  | 
val secure_mltext: unit -> unit  | 
| 60956 | 13  | 
val use_text: use_context ->  | 
14  | 
    {line: int, file: string, verbose: bool, debug: bool} -> string -> unit
 | 
|
15  | 
  val use_file: use_context -> {verbose: bool, debug: bool} -> string -> unit
 | 
|
| 20925 | 16  | 
end;  | 
17  | 
||
18  | 
structure Secure: SECURE =  | 
|
19  | 
struct  | 
|
20  | 
||
| 20992 | 21  | 
(** secure flag **)  | 
| 20925 | 22  | 
|
| 32738 | 23  | 
val secure = Unsynchronized.ref false;  | 
| 20925 | 24  | 
|
| 20977 | 25  | 
fun set_secure () = secure := true;  | 
| 20925 | 26  | 
fun is_secure () = ! secure;  | 
27  | 
||
| 
22567
 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 
wenzelm 
parents: 
22144 
diff
changeset
 | 
28  | 
fun deny_secure msg = if is_secure () then error msg else ();  | 
| 20925 | 29  | 
|
30  | 
||
| 25753 | 31  | 
|
| 20992 | 32  | 
(** critical operations **)  | 
33  | 
||
| 20925 | 34  | 
fun secure_mltext () = deny_secure "Cannot evaluate ML source in secure mode";  | 
35  | 
||
| 
30672
 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 
wenzelm 
parents: 
30625 
diff
changeset
 | 
36  | 
val raw_use_text = use_text;  | 
| 
 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 
wenzelm 
parents: 
30625 
diff
changeset
 | 
37  | 
val raw_use_file = use_file;  | 
| 20925 | 38  | 
|
| 60956 | 39  | 
fun use_text context flags (text: string) = (secure_mltext (); raw_use_text context flags text);  | 
40  | 
fun use_file context flags (file: string) = (secure_mltext (); raw_use_file context flags file);  | 
|
| 
23922
 
707639e9497d
marked some CRITICAL sections (for multithreading);
 
wenzelm 
parents: 
22567 
diff
changeset
 | 
41  | 
|
| 20925 | 42  | 
end;  |