Skip to content

Commit 041bf2d

Browse files
committed
Bump Custom Labels ABI to v1 (for Node support)
1 parent ed07a3c commit 041bf2d

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

interpreter/customlabels/customlabels.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818

1919
const (
2020
abiVersionExport = "custom_labels_abi_version"
21-
tlsExport = "custom_labels_thread_local_data"
21+
tlsExport = "custom_labels_current_set"
2222
)
2323

24-
var dsoRegex = regexp.MustCompile(`.*/libcustomlabels.*\.so`)
24+
var dsoRegex = regexp.MustCompile(`.*/libcustomlabels.*\.so|.*/customlabels\.node`)
2525

2626
type data struct {
2727
abiVersionElfVA libpf.Address
@@ -125,12 +125,14 @@ type instance struct {
125125
func (d data) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
126126
bias libpf.Address, rm remotememory.RemoteMemory) (interpreter.Instance, error) {
127127

128-
abiVersionPtr := rm.Ptr(bias + d.abiVersionElfVA)
129-
abiVersion := rm.Uint32(abiVersionPtr)
128+
abiVersion, err := rm.Uint32Checked(bias + d.abiVersionElfVA)
129+
if err != nil {
130+
return nil, fmt.Errorf("failed to read custom labels ABI version: %w", err)
131+
}
130132

131-
if abiVersion != 0 {
133+
if abiVersion != 1 {
132134
return nil, fmt.Errorf("unsupported custom labels ABI version: %d"+
133-
" (only 0 is supported)", abiVersion)
135+
" (only 1 is supported)", abiVersion)
134136
}
135137

136138
var tlsOffset uint64

remotememory/remotememory.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ func (rm RemoteMemory) Uint32(addr libpf.Address) uint32 {
7171
return binary.LittleEndian.Uint32(buf[:])
7272
}
7373

74+
// Uint32Checked reads a 32-bit unsigned integer from remote memory
75+
func (rm RemoteMemory) Uint32Checked(addr libpf.Address) (uint32, error) {
76+
var buf [4]byte
77+
if err := rm.Read(addr, buf[:]); err != nil {
78+
return 0, err
79+
}
80+
return binary.LittleEndian.Uint32(buf[:]), nil
81+
}
82+
7483
// Uint64 reads a 64-bit unsigned integer from remote memory
7584
func (rm RemoteMemory) Uint64(addr libpf.Address) uint64 {
7685
var buf [8]byte

support/ebpf/interpreter_dispatcher.ebpf.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,36 @@ bool get_native_custom_labels(struct pt_regs *ctx, UnwindState *state, void *dat
436436
u64 offset = tsd_base + proc->tls_offset;
437437
DEBUG_PRINT("native custom labels data at 0x%llx", offset);
438438

439-
NativeCustomLabelsThreadLocalData tls;
439+
NativeCustomLabelsSet *p_current_set;
440440
int err;
441-
if ((err = bpf_probe_read_user(&tls, sizeof(tls), (void *)(offset)))) {
441+
if ((err = bpf_probe_read_user(&p_current_set, sizeof(void *), (void *)(offset)))) {
442+
increment_metric(metricID_UnwindNativeCustomLabelsErrReadData);
443+
DEBUG_PRINT("Failed to read custom labels current set pointer: %d", err);
444+
return false;
445+
}
446+
447+
if (!p_current_set) {
448+
DEBUG_PRINT("Null labelset");
449+
return true;
450+
}
451+
452+
NativeCustomLabelsSet current_set;
453+
if ((err = bpf_probe_read_user(&current_set, sizeof(current_set), p_current_set))) {
442454
increment_metric(metricID_UnwindNativeCustomLabelsErrReadData);
443455
DEBUG_PRINT("Failed to read custom labels data: %d", err);
444456
return false;
445457
}
446458

447-
DEBUG_PRINT("Native custom labels count: %lu", tls.count);
459+
DEBUG_PRINT("Native custom labels count: %lu", current_set.count);
448460

449-
int remaining = MIN(tls.count, MAX_CUSTOM_LABELS);
461+
int remaining = MIN(current_set.count, MAX_CUSTOM_LABELS);
450462
int i = 0;
451463
int ct = 0;
452464

453465
while (remaining) {
454466
if (i >= MAX_CUSTOM_LABELS)
455467
break;
456-
NativeCustomLabel *lbl_ptr = tls.storage + i;
468+
NativeCustomLabel *lbl_ptr = current_set.storage + i;
457469
++i;
458470
NativeCustomLabel lbl;
459471
if ((err = bpf_probe_read_user(&lbl, sizeof(lbl), (void *)(lbl_ptr)))) {
1.98 KB
Binary file not shown.
1.97 KB
Binary file not shown.

support/ebpf/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ typedef struct NativeCustomLabel {
577577
typedef struct NativeCustomLabelsThreadLocalData {
578578
NativeCustomLabel *storage;
579579
size_t count;
580-
} NativeCustomLabelsThreadLocalData;
580+
size_t capacity;
581+
} NativeCustomLabelsSet;
581582

582583
// Container for a stack trace
583584
typedef struct Trace {

0 commit comments

Comments
 (0)