#define STAP_MSG_RUNTIME_H_01 "myproc-unprivileged tapset function called without is_myproc checking for pid %d (euid %d)" #define STAP_MSG_LOC2C_01 "read fault [man error::fault] at 0x%lx" #define STAP_MSG_LOC2C_02 "write fault [man error::fault] at 0x%lx" #define STAP_MSG_LOC2C_03 "divide by zero in DWARF operand (%s)" #define STAP_MSG_LOC2C_04 "register access fault [man error::fault]" #define STAP_VERSION(a, b) ( ((a) << 8) + (b) ) #ifndef STAP_COMPAT_VERSION #define STAP_COMPAT_VERSION STAP_VERSION(5, 1) #endif #pragma GCC diagnostic ignored "-Wtautological-compare" #include "runtime_defines.h" #include "linux/perf_read.h" #define STP_PR_STAPUSR 0x2 #define STP_PR_STAPSYS 0x4 #define STP_PR_STAPDEV 0x8 #define STP_PRIVILEGE 0x8 int stp_required_privilege __attribute__ ((section (".stap_privilege"))) = STP_PRIVILEGE; #include "stap_common.h" static void systemtap_module_refresh (const char* modname); #include "runtime.h" #include static DEFINE_MUTEX(module_refresh_mutex); #include #define STP_ON_THE_FLY_TIMER_ENABLE struct context { #include "common_probe_context.h" union { struct probe_6503_locals { union { /* block_statement: /root/Python-3.12.4/Lib/test/dtracedata/assert_usable.stp:2 */ }; } probe_6503; } probe_locals; union { struct function___global_exit__overload_0_locals { /* no return value */ } function___global_exit__overload_0; } locals [MAXNESTING+1]; #if MAXNESTING < 0 #error "MAXNESTING must be positive" #endif #ifndef STP_LEGACY_PRINT union { } printf_locals; #endif // STP_LEGACY_PRINT }; #include "runtime_context.h" #ifndef STP_LEGACY_PRINT #endif // STP_LEGACY_PRINT static atomic_t need_module_refresh = ATOMIC_INIT(0); static struct work_struct module_refresher_work; static void module_refresher(struct work_struct *work) { systemtap_module_refresh(NULL); } #ifdef STP_ON_THE_FLY_TIMER_ENABLE #include "timer.h" static struct hrtimer module_refresh_timer; #ifndef STP_ON_THE_FLY_INTERVAL #define STP_ON_THE_FLY_INTERVAL (100*1000*1000) #endif hrtimer_return_t module_refresh_timer_cb(struct hrtimer *timer); hrtimer_return_t module_refresh_timer_cb(struct hrtimer *timer) { if (atomic_cmpxchg(&need_module_refresh, 1, 0) == 1) queue_work(systemtap_wq, &module_refresher_work); hrtimer_set_expires(timer, ktime_add(hrtimer_get_expires(timer), ktime_set(0, STP_ON_THE_FLY_INTERVAL))); return HRTIMER_RESTART; } #endif /* STP_ON_THE_FLY_TIMER_ENABLE */ #include "namespaces.h" #include "sym2.c" struct stp_globals {}; #include "common_session_state.h" #include "probe_lock.h" #ifdef STAP_NEED_GETTIMEOFDAY #include "time.c" #endif static void function___global_exit__overload_0 (struct context * __restrict__ c); struct stap_probe { const size_t index; void (* const ph) (struct context*); unsigned cond_enabled:1; #if defined(STP_TIMING) || defined(STP_ALIBI) const char location[64]; const char derivation[15]; #define STAP_PROBE_INIT_TIMING(L, D) .location=(L), .derivation=(D), #else #define STAP_PROBE_INIT_TIMING(L, D) #endif const char pp[8]; #ifdef STP_NEED_PROBE_NAME const char pn[8]; #define STAP_PROBE_INIT_NAME(PN) .pn=(PN), #else #define STAP_PROBE_INIT_NAME(PN) #endif #define STAP_PROBE_INIT(I, PH, PP, PN, L, D) { .index=(I), .ph=(PH), .cond_enabled=1, .pp=(PP), STAP_PROBE_INIT_NAME(PN) STAP_PROBE_INIT_TIMING(L, D) } } static stap_probes[]; static void probe_6503 (struct context * __restrict__ c) { __label__ deref_fault; __label__ out; struct probe_6503_locals * __restrict__ l = & c->probe_locals.probe_6503; (void) l; if (c->actionremaining < 2) { c->last_error = "MAXACTION exceeded"; goto out; } { (void) ({ _stp_print ("probe: success""\n"); }); (void) ({ c->last_stmt = "identifier 'exit' at /root/Python-3.12.4/Lib/test/dtracedata/assert_usable.stp:4:3"; function___global_exit__overload_0 (c); if (unlikely(c->last_error || c->aborted)) goto out; (void) 0; }); } deref_fault: __attribute__((unused)); out: _stp_print_flush(); } static struct stap_probe stap_probes[] = { STAP_PROBE_INIT(0, &probe_6503, "begin", "begin", "/root/Python-3.12.4/Lib/test/dtracedata/assert_usable.stp:1:1", " from: begin"), }; static void function___global_exit__overload_0 (struct context* __restrict__ c) { __label__ deref_fault; __label__ out; struct function___global_exit__overload_0_locals * __restrict__ l = & c->locals[c->nesting+1].function___global_exit__overload_0; (void) l; #define CONTEXT c #define THIS l c->last_stmt = "identifier 'exit' at /usr/share/systemtap/tapset/logging.stp:52:10"; if (unlikely (c->nesting+1 >= MAXNESTING)) { c->last_error = "MAXNESTING exceeded"; return; } else { c->nesting ++; } c->next = 0; #define STAP_NEXT do { c->next = 1; goto out; } while(0) #define STAP_RETURN() do { goto out; } while(0) #define STAP_PRINTF(fmt, ...) do { _stp_printf(fmt, ##__VA_ARGS__); } while (0) #define STAP_ERROR(...) do { snprintf(CONTEXT->error_buffer, MAXSTRINGLEN, __VA_ARGS__); CONTEXT->last_error = CONTEXT->error_buffer; goto out; } while (0) #define return goto out if (c->actionremaining < 0) { c->last_error = "MAXACTION exceeded";goto out; } { /* unprivileged */ atomic_set (session_state(), STAP_SESSION_STOPPING); _stp_exit (); } #undef return #undef STAP_PRINTF #undef STAP_ERROR #undef STAP_RETURN deref_fault: __attribute__((unused)); out: __attribute__((unused)); c->nesting --; #undef CONTEXT #undef THIS #undef STAP_NEXT #undef STAP_RETVALUE } /* ---- begin/end/error probes ---- */ static struct stap_be_probe { const struct stap_probe * const probe; int state, type; } stap_be_probes[] = { { .probe=(&stap_probes[0]), .state=STAP_SESSION_STARTING, .type=0 }, }; static void enter_be_probe (struct stap_be_probe *stp) { #ifdef STP_ALIBI atomic_inc(probe_alibi(stp->probe->index)); #else struct context* __restrict__ c = NULL; #if !INTERRUPTIBLE unsigned long flags; #endif #ifdef STP_TIMING Stat stat = probe_timing(stp->probe->index); #endif #ifdef STP_TIMING #ifdef STP_TIMING_NSECS s64 cycles_atstart = ktime_get_ns (); #else cycles_t cycles_atstart = get_cycles (); #endif #endif #if !INTERRUPTIBLE local_irq_save (flags); #endif if (unlikely ((((unsigned long) (& c)) & (THREAD_SIZE-1)) < (MINSTACKSPACE + sizeof (struct thread_info)))) { atomic_inc (skipped_count()); #ifdef STP_TIMING atomic_inc (skipped_count_lowstack()); #endif goto probe_epilogue; } { unsigned sess_state = atomic_read (session_state()); #ifdef DEBUG_PROBES _stp_dbug(__FUNCTION__, __LINE__, "session state: %d, expecting stp->state (%d)", sess_state, stp->state); #endif if (sess_state != stp->state) goto probe_epilogue; } c = _stp_runtime_entryfn_get_context(); if (!c) { #if !INTERRUPTIBLE atomic_inc (skipped_count()); #endif #ifdef STP_TIMING atomic_inc (skipped_count_reentrant()); #endif goto probe_epilogue; } c->aborted = 0; c->locked = 0; c->last_stmt = 0; c->last_error = 0; c->nesting = -1; c->uregs = 0; c->kregs = 0; c->sregs = 0; #if defined __ia64__ c->unwaddr = 0; #endif c->probe_point = stp->probe->pp; #ifdef STP_NEED_PROBE_NAME c->probe_name = stp->probe->pn; #endif c->probe_type = stp_probe_type_been; memset(&c->ips, 0, sizeof(c->ips)); c->user_mode_p = 0; c->full_uregs_p = 0; #ifdef STAP_NEED_REGPARM c->regparm = 0; #endif #if INTERRUPTIBLE c->actionremaining = MAXACTION_INTERRUPTIBLE; #else c->actionremaining = MAXACTION; #endif #if defined(STP_NEED_UNWIND_DATA) c->uwcache_user.state = uwcache_uninitialized; c->uwcache_kernel.state = uwcache_uninitialized; #endif #if defined(STAP_NEED_CONTEXT_RETURNVAL) c->returnval_override_p = 0; c->returnval_override = 0; #endif (*stp->probe->ph) (c); #ifdef STP_TIMING { #ifdef STP_TIMING_NSECS s64 cycles_atend = ktime_get_ns (); s64 cycles_elapsed = ((s64)cycles_atend > (s64)cycles_atstart) ? ((s64)cycles_atend - (s64)cycles_atstart) : (~(s64)0) - (s64)cycles_atstart + (s64)cycles_atend + 1; #else cycles_t cycles_atend = get_cycles (); int32_t cycles_elapsed = ((int32_t)cycles_atend > (int32_t)cycles_atstart) ? ((int32_t)cycles_atend - (int32_t)cycles_atstart) : (~(int32_t)0) - (int32_t)cycles_atstart + (int32_t)cycles_atend + 1; #endif #ifdef STP_TIMING if (likely (stat)) _stp_stat_add(stat, cycles_elapsed, 1, 1, 1, 1, 0); #endif } #endif c->probe_point = 0; #ifdef STP_NEED_PROBE_NAME c->probe_name = 0; #endif c->probe_type = 0; if (unlikely (c->last_error)) { if (c->last_stmt != NULL) _stp_softerror ("%s near %s", c->last_error, c->last_stmt); else _stp_softerror ("%s", c->last_error); atomic_inc (error_count()); if (atomic_read (error_count()) > MAXERRORS) { atomic_set (session_state(), STAP_SESSION_ERROR); _stp_exit (); } } probe_epilogue: if (unlikely (atomic_read (skipped_count()) > MAXSKIPPED)) { if (unlikely (pseudo_atomic_cmpxchg(session_state(), STAP_SESSION_RUNNING, STAP_SESSION_ERROR) == STAP_SESSION_RUNNING)) _stp_error ("Skipped too many probes, check MAXSKIPPED or try again with stap -t for more details."); } _stp_runtime_entryfn_put_context(c); #if !INTERRUPTIBLE local_irq_restore (flags); #endif #endif // STP_ALIBI } #ifdef STAP_NEED_TRACEPOINTS #include "linux/stp_tracepoint.c" #endif static int systemtap_module_init (void) { int rc = 0; int cpu; int i=0, j=0; const char *probe_point = ""; #if defined(STP_TIMING) #ifdef STP_TIMING_NSECS s64 cycles_atstart = ktime_get_ns(); #else cycles_t cycles_atstart = get_cycles(); #endif #endif might_sleep(); rc = _stp_handle_kallsyms_lookups(); if (rc) goto out; { #ifndef STP_NO_VERREL_CHECK const char* release = UTS_RELEASE; #ifdef STAPCONF_GENERATED_COMPILE const char* version = UTS_VERSION; #endif #ifdef STP_FULL_VERREL_CHECK if (strcmp (release, "5.14.0-503.21.1.el9_5.x86_64")) { _stp_error ("module release mismatch (%s vs %s)", release, "5.14.0-503.21.1.el9_5.x86_64"); rc = -EINVAL; } #endif #ifdef STAPCONF_GENERATED_COMPILE if (strcmp (utsname()->version, version)) { _stp_error ("module version mismatch (%s vs %s), release %s", version, utsname()->version, release); rc = -EINVAL; } #endif #endif if (_stp_module_check()) rc = -EINVAL; if (_stp_privilege_credentials == 0) { if (STP_PRIVILEGE_CONTAINS(STP_PRIVILEGE, STP_PR_STAPDEV) || STP_PRIVILEGE_CONTAINS(STP_PRIVILEGE, STP_PR_STAPUSR)) { _stp_privilege_credentials = STP_PRIVILEGE; #ifdef DEBUG_PRIVILEGE _dbug("User's privilege credentials default to %s\n", privilege_to_text(_stp_privilege_credentials)); #endif } else { _stp_error ("Unable to verify that you have the required privilege credentials to run this module (%s required). You must use staprun version 1.7 or higher.", privilege_to_text(STP_PRIVILEGE)); rc = -EINVAL; } } else { #ifdef DEBUG_PRIVILEGE _dbug("User's privilege credentials provided as %s\n", privilege_to_text(_stp_privilege_credentials)); #endif if (! STP_PRIVILEGE_CONTAINS(_stp_privilege_credentials, STP_PRIVILEGE)) { _stp_error ("Your privilege credentials (%s) are insufficient to run this module (%s required).", privilege_to_text(_stp_privilege_credentials), privilege_to_text(STP_PRIVILEGE)); rc = -EINVAL; } } } if (rc) goto out; rc = stp_session_init(); if (rc) { _stp_error ("couldn't initialize the main session (rc %d)", rc); goto out; } if (atomic_cmpxchg(session_state(), STAP_SESSION_UNINITIALIZED, STAP_SESSION_STARTING) != STAP_SESSION_UNINITIALIZED) { _stp_error ("session has already been initialized"); return -EALREADY; } #ifdef STAP_NEED_GETTIMEOFDAY rc = _stp_init_time(); if (rc) { _stp_error ("couldn't initialize gettimeofday"); goto out; } #endif #ifdef STAP_NEED_TRACEPOINTS rc = stp_tracepoint_init(); if (rc) { _stp_error ("couldn't initialize tracepoints"); goto out; } #endif #ifdef STP_NEED_UNWIND_DATA rc = _stp_init_stack(); if (rc) { _stp_error ("couldn't initialize stack support"); goto out; } #endif (void) probe_point; (void) i; (void) j; rc = _stp_runtime_contexts_alloc(); if (rc != 0) goto out; _stp_print_kernel_info("assert_usable.stp", "5.1/0.191", (num_online_cpus() * sizeof(struct context)), 1); INIT_WORK(&module_refresher_work, module_refresher); for (i=0; i<1; i++) { struct stap_be_probe* stp = & stap_be_probes [i]; if (stp->type == 0) enter_be_probe (stp); /* rc = 0 */ } if (rc) { if (probe_point) _stp_error ("probe %s registration error [man warning::pass5] (rc %d)", probe_point, rc); atomic_set (session_state(), STAP_SESSION_ERROR); goto out; } atomic_cmpxchg(session_state(), STAP_SESSION_STARTING, STAP_SESSION_RUNNING); #ifdef STP_ON_THE_FLY_TIMER_ENABLE hrtimer_init(&module_refresh_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); module_refresh_timer.function = &module_refresh_timer_cb; #endif /* STP_ON_THE_FLY_TIMER_ENABLE */ #if defined(STP_TIMING) if (likely(g_module_init_timing)) { #ifdef STP_TIMING_NSECS s64 cycles_atend = ktime_get_ns (); s64 cycles_elapsed = ((s64)cycles_atend > (s64)cycles_atstart) ? ((s64)cycles_atend - (s64)cycles_atstart) : (~(s64)0) - (s64)cycles_atstart + (s64)cycles_atend + 1; #else cycles_t cycles_atend = get_cycles (); int32_t cycles_elapsed = ((int32_t)cycles_atend > (int32_t)cycles_atstart) ? ((int32_t)cycles_atend - (int32_t)cycles_atstart) : (~(int32_t)0) - (int32_t)cycles_atstart + (int32_t)cycles_atend + 1; #endif preempt_disable(); _stp_stat_add(g_module_init_timing, cycles_elapsed, 1, 1, 1, 1, 1); preempt_enable_no_resched(); } #endif return 0; deref_fault: __attribute__((unused)); out: atomic_set (session_state(), STAP_SESSION_STOPPED); stp_synchronize_sched(); #ifdef STAP_NEED_TRACEPOINTS stp_tracepoint_exit(); #endif #ifdef STAP_NEED_GETTIMEOFDAY _stp_kill_time(); #endif _stp_runtime_contexts_free(); stp_session_exit(); return rc; } static void systemtap_module_refresh (const char *modname) { int state; int i=0, j=0; #if defined(STP_TIMING) #ifdef STP_TIMING_NSECS s64 cycles_atstart = ktime_get_ns(); #else cycles_t cycles_atstart = get_cycles(); #endif #endif mutex_lock(&module_refresh_mutex); state = atomic_read (session_state()); if (state != STAP_SESSION_RUNNING && state != STAP_SESSION_STARTING) { mutex_unlock(&module_refresh_mutex); return; } (void) i; (void) j; #if defined(STP_TIMING) if (likely(g_refresh_timing)) { #ifdef STP_TIMING_NSECS s64 cycles_atend = ktime_get_ns (); s64 cycles_elapsed = ((s64)cycles_atend > (s64)cycles_atstart) ? ((s64)cycles_atend - (s64)cycles_atstart) : (~(s64)0) - (s64)cycles_atstart + (s64)cycles_atend + 1; #else cycles_t cycles_atend = get_cycles (); int32_t cycles_elapsed = ((int32_t)cycles_atend > (int32_t)cycles_atstart) ? ((int32_t)cycles_atend - (int32_t)cycles_atstart) : (~(int32_t)0) - (int32_t)cycles_atstart + (int32_t)cycles_atend + 1; #endif preempt_disable(); _stp_stat_add(g_refresh_timing, cycles_elapsed, 1, 1, 1, 1, 1); preempt_enable_no_resched(); } #endif mutex_unlock(&module_refresh_mutex); } static void systemtap_module_exit (void) { int i=0, j=0; (void) i; (void) j; if (atomic_read (session_state()) == STAP_SESSION_STARTING) return; if (atomic_read (session_state()) == STAP_SESSION_RUNNING) atomic_set (session_state(), STAP_SESSION_STOPPING); #ifdef STP_ON_THE_FLY_TIMER_ENABLE hrtimer_cancel(&module_refresh_timer); #endif stp_synchronize_sched(); mutex_lock(&module_refresh_mutex); for (i=0; i<1; i++) { struct stap_be_probe* stp = & stap_be_probes [i]; if (stp->type == 1) enter_be_probe (stp); } for (i=0; i<1; i++) { struct stap_be_probe* stp = & stap_be_probes [i]; if (stp->type == 2) enter_be_probe (stp); } mutex_unlock(&module_refresh_mutex); stp_synchronize_sched(); _stp_runtime_context_wait(); atomic_set (session_state(), STAP_SESSION_STOPPED); stp_synchronize_sched(); _stp_runtime_contexts_free(); #ifdef STAP_NEED_TRACEPOINTS stp_tracepoint_exit(); #endif #ifdef STAP_NEED_GETTIMEOFDAY _stp_kill_time(); #endif preempt_disable(); #if defined(STP_TIMING) || defined(STP_ALIBI) #ifndef STP_STDOUT_NOT_ATTY _stp_printf("----- probe hit report: \n"); #endif for (i = 0; i < ARRAY_SIZE(stap_probes); ++i) { const struct stap_probe *const p = &stap_probes[i]; #ifndef STP_STDOUT_NOT_ATTY #ifdef STP_ALIBI int alibi = atomic_read(probe_alibi(i)); if (alibi) _stp_printf ("%s, (%s), hits: %d,%s, index: %d\n", p->pp, p->location, alibi, p->derivation, i); #endif #endif #ifdef STP_TIMING if (likely (probe_timing(i))) { #ifndef STP_STDOUT_NOT_ATTY struct stat_data *stats = _stp_stat_get (probe_timing(i), 0); if (stats->count) { int64_t avg = _stp_div64 (NULL, stats->sum, stats->count); _stp_printf ("%s, (%s), hits: %lld, " #ifdef STP_TIMING_NSECS "nsecs" #else "cycles" #endif ": %lldmin/%lldavg/%lldmax, variance: %lld,%s, index: %d\n", p->pp, p->location, (long long) stats->count, (long long) stats->min, (long long) avg, (long long) stats->max, (long long) stats->variance, p->derivation, i); } #endif preempt_enable_no_resched(); _stp_stat_del (probe_timing(i)); preempt_disable(); } #endif } #if !defined(STP_STDOUT_NOT_ATTY) && defined(STP_TIMING) _stp_printf("----- refresh report:\n"); if (likely (g_refresh_timing)) { struct stat_data *stats = _stp_stat_get (g_refresh_timing, 0); if (stats->count) { int64_t avg = _stp_div64 (NULL, stats->sum, stats->count); _stp_printf ("hits: %lld, " #ifdef STP_TIMING_NSECS "nsecs" #else "cycles" #endif ": %lldmin/%lldavg/%lldmax, variance: %lld\n", (long long) stats->count, (long long) stats->min, (long long) avg, (long long) stats->max, (long long) stats->variance); } preempt_enable_no_resched(); _stp_stat_del (g_refresh_timing); preempt_disable(); } _stp_printf("----- module init report:\n"); if (likely (g_module_init_timing)) { struct stat_data *stats = _stp_stat_get (g_module_init_timing, 0); if (stats->count) { int64_t avg = _stp_div64 (NULL, stats->sum, stats->count); _stp_printf ("hits: %lld, " #ifdef STP_TIMING_NSECS "nsecs" #else "cycles" #endif ": %lldmin/%lldavg/%lldmax, variance: %lld\n", (long long) stats->count, (long long) stats->min, (long long) avg, (long long) stats->max, (long long) stats->variance); } preempt_enable_no_resched(); _stp_stat_del (g_module_init_timing); preempt_disable(); } #elif defined(STP_TIMING) if (likely (g_refresh_timing)) { preempt_enable_no_resched(); _stp_stat_del (g_refresh_timing); preempt_disable(); } if (likely (g_module_init_timing)) { preempt_enable_no_resched(); _stp_stat_del (g_module_init_timing); preempt_disable(); } #endif _stp_print_flush(); #endif #ifdef STP_TIMING { int ctr; } _stp_print_flush(); #endif if (atomic_read (skipped_count()) || atomic_read (error_count()) || atomic_read (skipped_count_reentrant())) { _stp_warn ("Number of errors: %d, skipped probes: %d\n", (int) atomic_read (error_count()), (int) atomic_read (skipped_count())); #ifdef STP_TIMING { int ctr; ctr = atomic_read (skipped_count_lowstack()); if (ctr) _stp_warn ("Skipped due to low stack: %d\n", ctr); ctr = atomic_read (skipped_count_reentrant()); if (ctr) _stp_warn ("Skipped due to reentrancy: %d\n", ctr); ctr = atomic_read (skipped_count_uprobe_reg()); if (ctr) _stp_warn ("Skipped due to uprobe register failure: %d\n", ctr); ctr = atomic_read (skipped_count_uprobe_unreg()); if (ctr) _stp_warn ("Skipped due to uprobe unregister failure: %d\n", ctr); } #endif _stp_print_flush(); } preempt_enable_no_resched(); } static int systemtap_kernel_module_init (void) { int rc = 0; int i=0, j=0; if (rc) { goto out; } out: return rc; } static void systemtap_kernel_module_exit (void) { int i=0, j=0; } MODULE_DESCRIPTION("systemtap-generated probe"); MODULE_LICENSE("GPL");