|
|
@@ -458,39 +458,30 @@ int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
|
|
|
bpf_map_update_elem(&apm_current_span_context_map, sc_ptr, &grpcClientReq->apm_sc, BPF_ANY);
|
|
|
// cw_save_current_tracking_span(&grpcClientReq->apm_sc);
|
|
|
|
|
|
- // Strategy: Write key and value separately with manual offset
|
|
|
+ // Strategy: Write key and value separately using write_target_data
|
|
|
+ // Both key and value can use write_target_data as it automatically manages memory allocation
|
|
|
// First write the key
|
|
|
char tp_key[CW_HEADER_KEY_LENGTH] = CW_HEADER_KEY_VAL;
|
|
|
- char *key_data_addr = write_target_data((void *)tp_key, sizeof(tp_key));
|
|
|
+ char *key_data_addr = cw_write_target_data((void *)tp_key, sizeof(tp_key), proc_info);
|
|
|
if (key_data_addr == NULL) {
|
|
|
bpf_printk("Key data write failed\n");
|
|
|
return 0;
|
|
|
}
|
|
|
- // bpf_printk("key_data_addr=%p\n", key_data_addr);
|
|
|
|
|
|
- // Manually advance the pointer for value (workaround for alloc_map bug)
|
|
|
- // Allocate enough space: align to 8 bytes
|
|
|
- u64 key_size_aligned = ((sizeof(tp_key) + 7) / 8) * 8;
|
|
|
-
|
|
|
- // Write value at offset from key
|
|
|
- span_context_to_cw_string(&grpcClientReq->apm_sc, storage->val);
|
|
|
- // span_context_to_w3c_string(&storage->sc, storage->val);
|
|
|
-
|
|
|
- // Try to write value with manual offset
|
|
|
- char *val_data_addr = key_data_addr + key_size_aligned;
|
|
|
- long val_write_result = bpf_probe_write_user(val_data_addr, storage->val, sizeof(storage->val));
|
|
|
- // bpf_printk("val_data_addr=%p, write_result=%ld\n", val_data_addr, val_write_result);
|
|
|
+ // Prepare and write the value
|
|
|
+ char val[CW_HEADER_VAL_LENGTH];
|
|
|
+ __builtin_memset(val, 0, sizeof(val));
|
|
|
+ span_context_to_cw_string(&grpcClientReq->apm_sc, val);
|
|
|
|
|
|
- if (val_write_result != 0) {
|
|
|
- bpf_printk("Val direct write failed\n");
|
|
|
+ // Write value using cw_write_target_data (it will automatically allocate next available position)
|
|
|
+ char *val_data_addr = cw_write_target_data((void *)val, sizeof(val), proc_info);
|
|
|
+ if (val_data_addr == NULL) {
|
|
|
+ bpf_printk("Val data write failed\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
struct go_string_ot key_str = {.str = key_data_addr, .len = sizeof(tp_key)};
|
|
|
- struct go_string_ot val_str = {.str = val_data_addr, .len = sizeof(storage->val)};
|
|
|
-
|
|
|
- // bpf_printk("key_str: len=%d, ptr=%p\n", key_str.len, key_str.str);
|
|
|
- // bpf_printk("val_str: len=%d, ptr=%p\n", val_str.len, val_str.str);
|
|
|
+ struct go_string_ot val_str = {.str = val_data_addr, .len = sizeof(val)};
|
|
|
|
|
|
// Build header field
|
|
|
storage->hf.name = key_str;
|