src/Pure/General/secure.ML
author wenzelm
Mon, 15 Feb 2016 14:55:44 +0100
changeset 62337 d3996d5873dd
parent 60956 10d463883dc2
child 62356 e307a410f46c
permissions -rw-r--r--
proper syntax;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/secure.ML
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     3
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     4
Secure critical operations.
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     5
*)
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     6
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     7
signature SECURE =
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
     8
sig
20977
dbf1eca9b34e tuned signature;
wenzelm
parents: 20925
diff changeset
     9
  val set_secure: unit -> unit
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    10
  val is_secure: unit -> bool
26080
d920e4c8ba82 export deny_secure;
wenzelm
parents: 25753
diff changeset
    11
  val deny_secure: string -> unit
31330
7bfbd0e07a40 export secure_mltext;
wenzelm
parents: 30672
diff changeset
    12
  val secure_mltext: unit -> unit
60956
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 58846
diff changeset
    13
  val use_text: use_context ->
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 58846
diff changeset
    14
    {line: int, file: string, verbose: bool, debug: bool} -> string -> unit
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 58846
diff changeset
    15
  val use_file: use_context -> {verbose: bool, debug: bool} -> string -> unit
30625
d53d1a16d5ee replaced install_pp/make_pp by more general toplevel_pp based on use_text;
wenzelm
parents: 29606
diff changeset
    16
  val toplevel_pp: string list -> string -> unit
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    17
end;
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    18
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    19
structure Secure: SECURE =
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    20
struct
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    21
20992
05c3703cc6c5 added execute/system;
wenzelm
parents: 20977
diff changeset
    22
(** secure flag **)
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    23
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 31473
diff changeset
    24
val secure = Unsynchronized.ref false;
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    25
20977
dbf1eca9b34e tuned signature;
wenzelm
parents: 20925
diff changeset
    26
fun set_secure () = secure := true;
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    27
fun is_secure () = ! secure;
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    28
22567
1565d476a9e2 removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
wenzelm
parents: 22144
diff changeset
    29
fun deny_secure msg = if is_secure () then error msg else ();
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    30
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    31
25753
99c9fc5e11f2 tuned spaces;
wenzelm
parents: 25703
diff changeset
    32
20992
05c3703cc6c5 added execute/system;
wenzelm
parents: 20977
diff changeset
    33
(** critical operations **)
05c3703cc6c5 added execute/system;
wenzelm
parents: 20977
diff changeset
    34
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    35
fun secure_mltext () = deny_secure "Cannot evaluate ML source in secure mode";
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    36
30672
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_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
    38
val raw_use_file = use_file;
beaadd5af500 more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents: 30625
diff changeset
    39
val raw_toplevel_pp = toplevel_pp;
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    40
60956
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 58846
diff changeset
    41
fun use_text context flags (text: string) = (secure_mltext (); raw_use_text context flags text);
10d463883dc2 explicit debug flag for ML compiler;
wenzelm
parents: 58846
diff changeset
    42
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
    43
30672
beaadd5af500 more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents: 30625
diff changeset
    44
fun toplevel_pp path pp = (secure_mltext (); raw_toplevel_pp ML_Parse.global_context path pp);
30625
d53d1a16d5ee replaced install_pp/make_pp by more general toplevel_pp based on use_text;
wenzelm
parents: 29606
diff changeset
    45
20925
2d19e511fe2c Secure critical operations.
wenzelm
parents:
diff changeset
    46
end;