@@ -19,6 +19,14 @@ import (
1919
2020const HashSize = C .sizeof_cm_hash
2121
22+ type SharingMode = C.cm_sharing_mode
23+
24+ const (
25+ SharingNone SharingMode = iota
26+ SharingConfig
27+ SharingAll
28+ )
29+
2230// Common type aliases
2331type Hash = [HashSize ]byte
2432
@@ -58,11 +66,12 @@ func (m *Machine) Delete() {
5866}
5967
6068// create
61- func (m * Machine ) Create (config , runtimeConfig string ) error {
69+ func (m * Machine ) Create (config , runtimeConfig , dir string ) error {
6270 var err error
6371 m .callCAPI (func () {
6472 var cConfig * C.char
6573 var cRuntime * C.char
74+ var cDir * C.char
6675 if config != "" {
6776 cConfig = C .CString (config )
6877 defer C .free (unsafe .Pointer (cConfig ))
@@ -71,7 +80,11 @@ func (m *Machine) Create(config, runtimeConfig string) error {
7180 cRuntime = C .CString (runtimeConfig )
7281 defer C .free (unsafe .Pointer (cRuntime ))
7382 }
74- err = newError (C .cm_create_new (cConfig , cRuntime , & m .ptr ))
83+ if dir != "" {
84+ cDir = C .CString (dir )
85+ defer C .free (unsafe .Pointer (cDir ))
86+ }
87+ err = newError (C .cm_create_new (cConfig , cRuntime , cDir , & m .ptr ))
7588 })
7689 return err
7790}
@@ -119,35 +132,14 @@ func (m *Machine) GetInitialConfig() (string, error) {
119132 return res , nil
120133}
121134
122- // get_memory_ranges
123- func (m * Machine ) GetMemoryRanges () (string , error ) {
124- var ranges * C.char
125- var err error
126- var res string
127-
128- m .callCAPI (func () {
129- err = newError (C .cm_get_memory_ranges (m .ptr , & ranges ))
130- if err != nil || ranges == nil {
131- return
132- }
133- res = C .GoString (ranges )
134- // no need to free 'ranges' here, as it is a static string
135- })
136-
137- if err != nil {
138- return "" , err
139- }
140- return res , nil
141- }
142-
143135// get_proof
144136func (m * Machine ) GetProof (address uint64 , log2size int32 ) (string , error ) {
145137 var proof * C.char
146138 var err error
147139 var res string
148140
149141 m .callCAPI (func () {
150- err = newError (C .cm_get_proof (m .ptr , C .uint64_t (address ), C .int32_t (log2size ), & proof ))
142+ err = newError (C .cm_get_proof (m .ptr , C .uint64_t (address ), C .int32_t (log2size ), C . int32_t ( HashTreeLog2RootSize ), & proof ))
151143 if err != nil || proof == nil {
152144 return
153145 }
@@ -241,7 +233,7 @@ func (m *Machine) Load(dir string, runtimeConfig string) error {
241233 cRuntime = C .CString (runtimeConfig )
242234 defer C .free (unsafe .Pointer (cRuntime ))
243235 }
244- err = newError (C .cm_load (m .ptr , cDir , cRuntime ))
236+ err = newError (C .cm_load (m .ptr , cDir , cRuntime , SharingNone ))
245237 })
246238
247239 return err
@@ -369,6 +361,53 @@ func (m *Machine) Run(mcycleEnd uint64) (BreakReason, error) {
369361 return BreakReason (br ), nil
370362}
371363
364+ // collect_mcycle_root_hashes
365+ func (m * Machine ) CollectMCycleRootHashes (mcycleEnd , mcyclePeriod , mcyclePhase uint64 , log2BundleMcycleCount int32 , previousBackTree string ) ([]byte , error ) {
366+ var err error
367+ var result * C.char
368+
369+ m .callCAPI (func () {
370+ var previousBackTreeC * C.char
371+ if previousBackTree != "" {
372+ previousBackTreeC = C .CString (previousBackTree )
373+ defer C .free (unsafe .Pointer (previousBackTreeC ))
374+ }
375+ err = newError (C .cm_collect_mcycle_root_hashes (
376+ m .ptr ,
377+ C .uint64_t (mcycleEnd ),
378+ C .uint64_t (mcyclePeriod ),
379+ C .uint64_t (mcyclePhase ),
380+ C .int32_t (log2BundleMcycleCount ),
381+ previousBackTreeC ,
382+ & result ))
383+ })
384+
385+ if err != nil {
386+ return []byte {}, err
387+ }
388+ return []byte (C .GoString (result )), nil
389+ }
390+
391+ // collect_uarch_cycle_root_hashes
392+ func (m * Machine ) CollectUarchCycleRootHashes (mcycleEnd uint64 , log2BundleMcycleCount int32 ) ([]byte , error ) {
393+ var err error
394+ var result * C.char
395+
396+ m .callCAPI (func () {
397+ err = newError (C .cm_collect_uarch_cycle_root_hashes (
398+ m .ptr ,
399+ C .uint64_t (mcycleEnd ),
400+ C .int32_t (log2BundleMcycleCount ),
401+ & result ))
402+ })
403+
404+ if err != nil {
405+ return []byte {}, err
406+ }
407+ return []byte (C .GoString (result )), nil
408+ }
409+
410+
372411// send_cmio_response
373412func (m * Machine ) SendCmioResponse (reason uint16 , data []byte ) error {
374413 var err error
@@ -414,7 +453,7 @@ func (m *Machine) Store(directory string) error {
414453 m .callCAPI (func () {
415454 cDir := C .CString (directory )
416455 defer C .free (unsafe .Pointer (cDir ))
417- err = newError (C .cm_store (m .ptr , cDir ))
456+ err = newError (C .cm_store (m .ptr , cDir , SharingAll ))
418457 })
419458
420459 return err
0 commit comments