Skip to content

Commit 0111ebb

Browse files
committed
Address review comments
1 parent f705452 commit 0111ebb

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

internal/otelcontextmapping_linux.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
package internal
1111

1212
import (
13-
"encoding/binary"
1413
"fmt"
1514
"os"
1615
"structs"
17-
"sync/atomic"
16+
"sync"
1817
"unsafe"
1918

2019
"golang.org/x/sys/unix"
@@ -79,17 +78,22 @@ func CreateOtelProcessContextMapping(data []byte) error {
7978
}
8079

8180
addr := uintptr(unsafe.Pointer(&mappingBytes[0]))
82-
header := processContextHeader{
83-
Version: 1,
84-
PayloadSize: uint32(len(data)),
85-
PayloadAddr: addr + uintptr(headerSize),
86-
}
8781

88-
copy(mappingBytes[headerSize:], data)
89-
copy(mappingBytes[:headerSize], unsafe.Slice((*byte)(unsafe.Pointer(&header)), headerSize))
90-
// write atomically the signature last to ensure that once a process validates the signature, it can safely read the whole data
91-
sig := binary.NativeEndian.Uint64(unsafe.Slice(unsafe.StringData(otelContextSignature), len(otelContextSignature)))
92-
atomic.StoreUint64((*uint64)(unsafe.Pointer(&mappingBytes[0])), sig)
82+
var wg sync.WaitGroup
83+
wg.Add(1)
84+
go func() {
85+
defer wg.Done()
86+
header := processContextHeader{
87+
Version: 1,
88+
PayloadSize: uint32(len(data)),
89+
PayloadAddr: addr + uintptr(headerSize),
90+
}
91+
copy(mappingBytes[headerSize:], data)
92+
copy(mappingBytes[:headerSize], unsafe.Slice((*byte)(unsafe.Pointer(&header)), headerSize))
93+
}()
94+
wg.Wait()
95+
// write the signature last to ensure that once a process validates the signature, it can safely read the whole data
96+
copy(mappingBytes, otelContextSignature)
9397

9498
err = unix.Mprotect(mappingBytes, unix.PROT_READ)
9599
if err != nil {

0 commit comments

Comments
 (0)