Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tracer/norace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !race

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package tracer
package tracer // import "go.opentelemetry.io/ebpf-profiler/tracer"

import (
"unsafe"

"go.opentelemetry.io/ebpf-profiler/support"
)

func traceFromRaw(raw []byte) *support.Trace {
return (*support.Trace)(unsafe.Pointer(unsafe.SliceData(raw)))
}
20 changes: 20 additions & 0 deletions tracer/race.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build race

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package tracer
package tracer // import "go.opentelemetry.io/ebpf-profiler/tracer"

import (
"unsafe"

"go.opentelemetry.io/ebpf-profiler/support"
)

func traceFromRaw(raw []byte) *support.Trace {
// workaround for "fatal error: checkptr: converted pointer straddles multiple allocations"
fullSizeCopy := make([]byte, unsafe.Sizeof(support.Trace{}))
copy(fullSizeCopy, raw)
return (*support.Trace)(unsafe.Pointer(unsafe.SliceData(fullSizeCopy)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to norace, this logic results in a different Trace.Hash (as the writes to raw through the pointer don't take effect) but since we don't use this hash at all anymore I opened #901 to remove it.

}
2 changes: 1 addition & 1 deletion tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ func (t *Tracer) loadBpfTrace(raw []byte, cpu int) *host.Trace {
}

frameSize := support.Sizeof_Frame
ptr := (*support.Trace)(unsafe.Pointer(unsafe.SliceData(raw)))
ptr := traceFromRaw(raw)

// NOTE: can't do exact check here: kernel adds a few padding bytes to messages.
if len(raw) < frameListOffs+int(ptr.Stack_len)*frameSize {
Expand Down