@@ -6,11 +6,11 @@ import (
66 "flag"
77)
88
9- // +------------+---------+---------+
10- // | magic mark | option1 | option2 |
11- // +------------+---------+---------+
12- // | 0xFC | var | var |
13- // +------------+---------+---------+
9+ // +------------+---------+---------+-----------+
10+ // | magic mark | option1 | option2 | option... |
11+ // +------------+---------+---------+-----------+
12+ // | 0xFC | var | var | var |
13+ // +------------+---------+---------+-----------+
1414
1515const (
1616 // StubSize is the option stub total size at the runtime tail.
@@ -22,21 +22,31 @@ const (
2222
2323// options offset of the option stub.
2424const (
25- OptOffsetNotEraseInstruction = 1
26- OptOffsetNotAdjustProtect = 2
27- OptOffsetNotTrackCurrentThread = 3
25+ OptOffsetDisableSysmon = iota + 1
26+ OptOffsetDisableWatchdog
27+ OptOffsetNotEraseInstruction
28+ OptOffsetNotAdjustProtect
29+ OptOffsetTrackCurrentThread
2830)
2931
3032// Options contains options about Gleam-RT.
3133type Options struct {
34+ // disable sysmon for implement single thread model.
35+ DisableSysmon bool `toml:"disable_sysmon" json:"disable_sysmon"`
36+
37+ // disable watchdog for implement single thread model.
38+ // it will overwrite the control from upper module.
39+ DisableWatchdog bool `toml:"disable_watchdog" json:"disable_watchdog"`
40+
3241 // not erase runtime instructions after call Runtime_M.Exit.
33- NotEraseInstruction bool
42+ NotEraseInstruction bool `toml:"not_erase_instruction" json:"not_erase_instruction"`
3443
3544 // not adjust current memory page protect for erase runtime.
36- NotAdjustProtect bool
45+ NotAdjustProtect bool `toml:"not_adjust_protect" json:"not_adjust_protect"`
3746
3847 // track current thread for test or debug mode.
39- TrackCurrentThread bool
48+ // it maybe improved the single thread model.
49+ TrackCurrentThread bool `toml:"track_current_thread" json:"track_current_thread"`
4050}
4151
4252// Set is used to adjust options in the runtime shellcode template.
@@ -58,6 +68,18 @@ func Set(tpl []byte, opts *Options) ([]byte, error) {
5868 copy (output , tpl )
5969 stub = output [len (output )- StubSize :]
6070 var opt byte
71+ if opts .DisableSysmon {
72+ opt = 1
73+ } else {
74+ opt = 0
75+ }
76+ stub [OptOffsetDisableSysmon ] = opt
77+ if opts .DisableWatchdog {
78+ opt = 1
79+ } else {
80+ opt = 0
81+ }
82+ stub [OptOffsetDisableWatchdog ] = opt
6183 if opts .NotEraseInstruction {
6284 opt = 1
6385 } else {
@@ -75,7 +97,7 @@ func Set(tpl []byte, opts *Options) ([]byte, error) {
7597 } else {
7698 opt = 0
7799 }
78- stub [OptOffsetNotTrackCurrentThread ] = opt
100+ stub [OptOffsetTrackCurrentThread ] = opt
79101 return output , nil
80102}
81103
@@ -93,13 +115,19 @@ func Get(sc []byte, offset int) (*Options, error) {
93115 // read option from stub
94116 opts := Options {}
95117 stub := sc [offset :]
118+ if stub [OptOffsetDisableSysmon ] != 0 {
119+ opts .DisableSysmon = true
120+ }
121+ if stub [OptOffsetDisableWatchdog ] != 0 {
122+ opts .DisableWatchdog = true
123+ }
96124 if stub [OptOffsetNotEraseInstruction ] != 0 {
97125 opts .NotEraseInstruction = true
98126 }
99127 if stub [OptOffsetNotAdjustProtect ] != 0 {
100128 opts .NotAdjustProtect = true
101129 }
102- if stub [OptOffsetNotTrackCurrentThread ] != 0 {
130+ if stub [OptOffsetTrackCurrentThread ] != 0 {
103131 opts .TrackCurrentThread = true
104132 }
105133 return & opts , nil
@@ -108,15 +136,23 @@ func Get(sc []byte, offset int) (*Options, error) {
108136// Flag is used to read options from command line.
109137func Flag (opts * Options ) {
110138 flag .BoolVar (
111- & opts .NotEraseInstruction , "opt-nei" , false ,
112- "not erase runtime instructions after call Runtime_M.Exit" ,
139+ & opts .DisableSysmon , "grt-ds" , false ,
140+ "Gleam-RT: disable sysmon for implement single thread model" ,
141+ )
142+ flag .BoolVar (
143+ & opts .DisableWatchdog , "grt-dw" , false ,
144+ "Gleam-RT: disable watchdog for implement single thread model." ,
145+ )
146+ flag .BoolVar (
147+ & opts .NotEraseInstruction , "grt-nei" , false ,
148+ "Gleam-RT: not erase runtime instructions after runtime stop" ,
113149 )
114150 flag .BoolVar (
115- & opts .NotAdjustProtect , "opt -nap" , false ,
116- "not adjust current memory page protect for erase runtime" ,
151+ & opts .NotAdjustProtect , "grt -nap" , false ,
152+ "Gleam-RT: not adjust current memory page protect for erase runtime" ,
117153 )
118154 flag .BoolVar (
119- & opts .TrackCurrentThread , "opt -tct" , false ,
120- "track current thread for test or debug mode" ,
155+ & opts .TrackCurrentThread , "grt -tct" , false ,
156+ "Gleam-RT: track current thread for test or debug mode" ,
121157 )
122158}
0 commit comments