@@ -22,7 +22,8 @@ const (
2222
2323// options offset of the option stub.
2424const (
25- OptOffsetDisableDetector = iota + 1
25+ OptOffsetEnableSecurityMode = iota + 1
26+ OptOffsetDisableDetector
2627 OptOffsetDisableSysmon
2728 OptOffsetDisableWatchdog
2829 OptOffsetNotEraseInstruction
@@ -32,6 +33,9 @@ const (
3233
3334// Options contains options about Gleam-RT.
3435type Options struct {
36+ // detect environment when initialize runtime, if not safe, stop at once.
37+ EnableSecurityMode bool `toml:"enable_security_mode" json:"enable_security_mode"`
38+
3539 // disable detector for test or debug.
3640 DisableDetector bool `toml:"disable_detector" json:"disable_detector"`
3741
@@ -72,6 +76,12 @@ func Set(tpl []byte, opts *Options) ([]byte, error) {
7276 copy (output , tpl )
7377 stub = output [len (output )- StubSize :]
7478 var opt byte
79+ if opts .EnableSecurityMode {
80+ opt = 1
81+ } else {
82+ opt = 0
83+ }
84+ stub [OptOffsetEnableSecurityMode ] = opt
7585 if opts .DisableDetector {
7686 opt = 1
7787 } else {
@@ -125,6 +135,9 @@ func Get(sc []byte, offset int) (*Options, error) {
125135 // read option from stub
126136 opts := Options {}
127137 stub := sc [offset :]
138+ if stub [OptOffsetEnableSecurityMode ] != 0 {
139+ opts .EnableSecurityMode = true
140+ }
128141 if stub [OptOffsetDisableDetector ] != 0 {
129142 opts .DisableDetector = true
130143 }
@@ -148,6 +161,10 @@ func Get(sc []byte, offset int) (*Options, error) {
148161
149162// Flag is used to read options from command line.
150163func Flag (opts * Options ) {
164+ flag .BoolVar (
165+ & opts .EnableSecurityMode , "grt-esm" , false ,
166+ "Gleam-RT: detect environment when initialize runtime" ,
167+ )
151168 flag .BoolVar (
152169 & opts .DisableDetector , "grt-dd" , false ,
153170 "Gleam-RT: disable detector for test or debug" ,
0 commit comments