| 1 |
// kretprobe data tapset |
| 2 |
// Copyright (C) 2009, 2011 Red Hat Inc. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
|
| 9 |
|
| 10 |
// This is an internally-used tapset for sharing data between kretprobe |
| 11 |
// entry / return handlers. See the function |
| 12 |
// dwarf_var_expanding_visitor::gen_kretprobe_saved_return |
| 13 |
// for details. |
| 14 |
// |
| 15 |
// Note, invalid calls are silently ignored... |
| 16 |
|
| 17 |
%{ |
| 18 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,11,0) |
| 19 |
#define get_kretprobe(p) ((p)->rp) |
| 20 |
#endif |
| 21 |
|
| 22 |
static void * |
| 23 |
_kretprobe_data(struct kretprobe_instance *pi, size_t offset, size_t length) |
| 24 |
{ |
| 25 |
size_t end = offset + length; |
| 26 |
if (end > offset && pi && end <= get_kretprobe(pi)->data_size) |
| 27 |
return &pi->data[offset]; |
| 28 |
return NULL; |
| 29 |
} |
| 30 |
%} |
| 31 |
|
| 32 |
function _get_kretprobe_long:long(i:long) %{ /* pure */ |
| 33 |
if (CONTEXT->probe_type == stp_probe_type_kretprobe) { |
| 34 |
size_t offset = STAP_ARG_i * sizeof(int64_t); |
| 35 |
const int64_t *data = _kretprobe_data(CONTEXT->ips.krp.pi, offset, sizeof(int64_t)); |
| 36 |
STAP_RETVALUE = data ? *data : 0; |
| 37 |
} |
| 38 |
%} |
| 39 |
|
| 40 |
function _set_kretprobe_long(i:long, value:long) %{ /* impure */ |
| 41 |
if (CONTEXT->probe_type == stp_probe_type_kretprobe) { |
| 42 |
size_t offset = STAP_ARG_i * sizeof(int64_t); |
| 43 |
int64_t *data = _kretprobe_data(CONTEXT->ips.krp.pi, offset, sizeof(int64_t)); |
| 44 |
if (data) |
| 45 |
*data = STAP_ARG_value; |
| 46 |
} |
| 47 |
%} |
| 48 |
|
| 49 |
function _get_kretprobe_string:string(i:long) %{ /* pure */ |
| 50 |
if (CONTEXT->probe_type == stp_probe_type_kretprobe) { |
| 51 |
size_t offset = CONTEXT->ips.krp.pi_longs * sizeof(int64_t) + |
| 52 |
STAP_ARG_i * MAXSTRINGLEN; |
| 53 |
const char *data = _kretprobe_data(CONTEXT->ips.krp.pi, offset, MAXSTRINGLEN); |
| 54 |
strlcpy(STAP_RETVALUE, data ?: "", MAXSTRINGLEN); |
| 55 |
} |
| 56 |
%} |
| 57 |
|
| 58 |
function _set_kretprobe_string(i:long, value:string) %{ /* impure */ /* unmodified-fnargs */ |
| 59 |
if (CONTEXT->probe_type == stp_probe_type_kretprobe) { |
| 60 |
size_t offset = CONTEXT->ips.krp.pi_longs * sizeof(int64_t) + |
| 61 |
STAP_ARG_i * MAXSTRINGLEN; |
| 62 |
char *data = _kretprobe_data(CONTEXT->ips.krp.pi, offset, MAXSTRINGLEN); |
| 63 |
if (data) |
| 64 |
strlcpy(data, STAP_ARG_value, MAXSTRINGLEN); |
| 65 |
} |
| 66 |
%} |