github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/runtime/deepcopy.go (about) 1 package runtime 2 3 import ( 4 "unsafe" 5 ) 6 7 type DPTpe = _type 8 9 type TrackerEntry struct { 10 Src uintptr 11 Size uintptr 12 } 13 14 type AllocTracker = []TrackerEntry 15 16 type CopyTpe func(unsafe.Pointer, *DPTpe) unsafe.Pointer 17 type CopyTpe2 func(unsafe.Pointer, *DPTpe) (unsafe.Pointer, AllocTracker) 18 19 var ( 20 DeepCopier CopyTpe 21 DeepCopierSend CopyTpe2 22 CanShallowCopy func(*DPTpe) bool 23 ) 24 25 func SetCopier(cp CopyTpe, csc func(*DPTpe) bool) { 26 DeepCopier = cp 27 CanShallowCopy = csc 28 } 29 30 func SetCopiers(cp CopyTpe, cp2 CopyTpe2, csc func(*DPTpe) bool) { 31 DeepCopier = cp 32 DeepCopierSend = cp2 33 CanShallowCopy = csc 34 } 35 36 func storeCopy(dst unsafe.Pointer, val unsafe.Pointer, size uint16) { 37 panic("bitch") 38 } 39 40 func copyIn(size uintptr) uintptr { 41 src := make([]byte, int(size)) 42 return uintptr(unsafe.Pointer(&src[0])) 43 } 44 45 func doCopy(sg *sudog, dest unsafe.Pointer, c *hchan) { 46 notInit := (DeepCopier == nil || dest == nil) 47 missingInfo := isEnclave && c.encltpe == nil 48 rcvDirect := (isEnclave && sg.id == -1) || (!isEnclave && sg.id != -1) 49 if notInit || missingInfo { 50 return 51 } 52 if !sg.needcpy && !rcvDirect { 53 return 54 } 55 // now you need to do a copy 56 tpe := c.elemtype 57 if isEnclave { 58 tpe = c.encltpe 59 } 60 61 // by default that's handled 62 if CanShallowCopy(tpe) { 63 return 64 } 65 //extract address 66 orig := *(*uintptr)(unsafe.Pointer(uintptr(dest))) 67 68 typedmemmove(tpe, dest, DeepCopier(dest, tpe)) 69 // non-enclave does a non-direct recv 70 if !isEnclave && sg.id == -1 { 71 go func() { 72 Cooprt.Uach <- uintptr(orig) 73 }() 74 } 75 } 76 77 func sendCopy(dest *sudog, src unsafe.Pointer, c *hchan) bool { 78 doesNotApply := !isEnclave || c.isencl || dest.elem == nil 79 if doesNotApply { 80 return false 81 } 82 nocpy := c.encltpe == nil || CanShallowCopy(c.encltpe) 83 if nocpy { 84 return false 85 } 86 r, tracker := DeepCopierSend(src, c.encltpe) 87 UnsafeAllocator.registerTracker(tracker) 88 typedmemmove(c.encltpe, dest.elem, r) 89 return true 90 }