From 9da5c6e0fe733593803c168ff0ae912c15b4ce57 Mon Sep 17 00:00:00 2001 From: Felix Lu Date: Thu, 10 Mar 2016 16:58:26 -0500 Subject: [PATCH] Add backwards compatible tapset functions following function overloading changes. --- tapset/ansi.stp | 11 ++++ tapset/linux/conversions.stp | 16 +++++- tapset/linux/proc_mem.stp | 77 +++++++++++++++++++++++++++ tapset/linux/task_time.stp | 20 +++++++ tapset/uconversions.stp | 100 +++++++++++++++++++++++++++++++++++ 5 files changed, 223 insertions(+), 1 deletion(-) diff --git a/tapset/ansi.stp b/tapset/ansi.stp index e6178db43..f057c4aa0 100644 --- a/tapset/ansi.stp +++ b/tapset/ansi.stp @@ -45,6 +45,11 @@ function ansi_set_color(fg:long) { function ansi_set_color(fg:long, bg:long) { printf("\033[%d;%dm", bg, fg) } +%(systemtap_v <= "3.0" %? +function ansi_set_color2(fg:long, bg:long) { + printf("\033[%d;%dm", bg, fg) +} +%) /** * sfunction ansi_set_color - Set the ansi Select Graphic Rendition mode. @@ -64,6 +69,12 @@ function ansi_set_color(fg:long, bg:long, attr:long) { attr_str = attr ? sprintf(";%dm", attr) : "m" printf("\033[%d;%d%s", bg, fg, attr_str) } +%(systemtap_v <= "3.0" %? +function ansi_set_color3(fg:long, bg:long, attr:long) { + attr_str = attr ? sprintf(";%dm", attr) : "m" + printf("\033[%d;%d%s", bg, fg, attr_str) +} +%) /** * sfunction ansi_reset_color - Resets Select Graphic Rendition mode. diff --git a/tapset/linux/conversions.stp b/tapset/linux/conversions.stp index 48fb6d097..1a88349d1 100644 --- a/tapset/linux/conversions.stp +++ b/tapset/linux/conversions.stp @@ -42,6 +42,11 @@ deref_fault: /* branched to from deref_string() */ function kernel_string:string (addr:long, err_msg:string) { try { return kernel_string(addr) } catch { return err_msg } } +%(systemtap_v <= "3.0" %? +function kernel_string2:string (addr:long, err_msg:string) { + try { return kernel_string(addr) } catch { return err_msg } +} +%) /** * sfunction kernel_string_quoted - Retrieves and quotes string from kernel memory @@ -134,7 +139,11 @@ deref_fault: /* branched to from deref_string() */ function kernel_string_utf32:string (addr:long, err_msg:string) { try { return kernel_string_utf32(addr) } catch { return err_msg } } - +%(systemtap_v <= "3.0" %? +function kernel_string2_utf32:string (addr:long, err_msg:string) { + try { return kernel_string_utf32(addr) } catch { return err_msg } +} +%) /** * sfunction kernel_string_quoted_utf32 - Quote given UTF-32 kernel string. @@ -210,6 +219,11 @@ deref_fault: /* branched to from deref_string() */ function kernel_string_utf16:string (addr:long, err_msg:string) { try { return kernel_string_utf16(addr) } catch { return err_msg } } +%(systemtap_v <= "3.0" %? +function kernel_string2_utf16:string (addr:long, err_msg:string) { + try { return kernel_string_utf16(addr) } catch { return err_msg } +} +%) /** diff --git a/tapset/linux/proc_mem.stp b/tapset/linux/proc_mem.stp index 83a5bdb87..4b7efb980 100644 --- a/tapset/linux/proc_mem.stp +++ b/tapset/linux/proc_mem.stp @@ -148,6 +148,18 @@ function proc_mem_size:long (pid:long) } return 0 } +%(systemtap_v <= "3.0" %? +function proc_mem_size_pid:long (pid:long) +{ + task = pid2task(pid) + if (_stp_valid_task(task)) { + mm = task->mm + if (mm != 0) + return mm->total_vm + } + return 0 +} +%) /** * sfunction proc_mem_rss - Program resident set size in pages @@ -188,6 +200,19 @@ function proc_mem_rss:long (pid:long) } return 0 } +%(systemtap_v <= "3.0" %? +function proc_mem_rss_pid:long (pid:long) +{ + task = pid2task(pid) + if (_stp_valid_task(task)) { + mm = task->mm + if (mm != 0) + return (_stp_get_mm_counter(mm, _MM_FILEPAGES()) + + _stp_get_mm_counter(mm, _MM_ANONPAGES())) + } + return 0 +} +%) /** * sfunction proc_mem_shr - Program shared pages (from shared mappings) @@ -226,6 +251,18 @@ function proc_mem_shr:long (pid:long) } return 0 } +%(systemtap_v <= "3.0" %? +function proc_mem_shr_pid:long (pid:long) +{ + task = pid2task(pid) + if (_stp_valid_task(task)) { + mm = task->mm + if (mm != 0) + return _stp_get_mm_counter(mm, _MM_FILEPAGES()) + } + return 0 +} +%) @__private30 function _stp_mem_txt_adjust:long (start_code:long, end_code:long) %{ /* pure */ @@ -278,6 +315,21 @@ function proc_mem_txt:long (pid:long) } return 0 } +%(systemtap_v <= "3.0" %? +function proc_mem_txt_pid:long (pid:long) +{ + task = pid2task(pid) + if (_stp_valid_task(task)) { + mm = task->mm + if (mm != 0) { + s = mm->start_code + e = mm->end_code + return _stp_mem_txt_adjust (s, e) + } + } + return 0 +} +%) /** * sfunction proc_mem_data - Program data size (data + stack) in pages @@ -320,6 +372,20 @@ function proc_mem_data:long (pid:long) } return 0 } +%(systemtap_v <= "3.0" %? +function proc_mem_data_pid:long (pid:long) +{ + task = pid2task(pid) + if (_stp_valid_task(task)) { + mm = task->mm + if (mm != 0) { + return (@defined(&@mm(0)->data_vm) ? (mm->data_vm + mm->stack_vm) + : (mm->total_vm - mm->shared_vm)) + } + } + return 0 +} +%) /** * sfunction mem_page_size - Number of bytes in a page for this architecture @@ -422,3 +488,14 @@ function proc_mem_string:string (pid:long) pages_to_string(proc_mem_txt(pid)), pages_to_string(proc_mem_data(pid))); } +%(systemtap_v <= "3.0" %? +function proc_mem_string_pid:string (pid:long) +{ + return sprintf ("size: %s, rss: %s, shr: %s, txt: %s, data: %s", + pages_to_string(proc_mem_size(pid)), + pages_to_string(proc_mem_rss(pid)), + pages_to_string(proc_mem_shr(pid)), + pages_to_string(proc_mem_txt(pid)), + pages_to_string(proc_mem_data(pid))); +} +%) diff --git a/tapset/linux/task_time.stp b/tapset/linux/task_time.stp index af854965c..f86f98412 100644 --- a/tapset/linux/task_time.stp +++ b/tapset/linux/task_time.stp @@ -71,6 +71,16 @@ function task_utime:long(tid:long) else return 0; } +%(systemtap_v <= "3.0" %? +function task_utime_tid:long(tid:long) +{ + task = pid2task(tid); + if (task != 0) + return task->utime; + else + return 0; +} +%) /** * sfunction task_stime - System time of the task @@ -102,6 +112,16 @@ function task_stime:long(tid:long) else return 0; } +%(systemtap_v <= "3.0" %? +function task_stime_tid:long(tid:long) +{ + task = pid2task(tid); + if (task != 0) + return task->stime; + else + return 0; +} +%) /** * sfunction task_start_time - Start time of the given task diff --git a/tapset/uconversions.stp b/tapset/uconversions.stp index 73898a87b..ad5cd18a1 100644 --- a/tapset/uconversions.stp +++ b/tapset/uconversions.stp @@ -57,6 +57,11 @@ function user_string:string (addr:long) { function user_string:string (addr:long, err_msg:string) { return user_string_n(addr, @MAXSTRINGLEN, err_msg) } +%(systemtap_v <= "3.0" %? +function user_string2:string (addr:long, err_msg:string) { + return user_string_n(addr, @MAXSTRINGLEN, err_msg) +} +%) /** * sfunction user_string_warn - Retrieves string from user space @@ -90,6 +95,11 @@ function user_string_warn:string (addr:long) { function user_string_warn:string (addr:long, warn_msg:string) { return user_string_n_warn(addr, @MAXSTRINGLEN, warn_msg) } +%(systemtap_v <= "3.0" %? +function user_string2_warn:string (addr:long, warn_msg:string) { + return user_string_n_warn(addr, @MAXSTRINGLEN, warn_msg) +} +%) /** * sfunction user_string_quoted - Retrieves and quotes string from user space @@ -161,6 +171,17 @@ function user_string_n:string (addr:long, n:long, err_msg:string) else STAP_RETVALUE[len - 1] = '\0'; %} +%(systemtap_v <= "3.0" %? +function user_string_n2:string (addr:long, n:long, err_msg:string) +%{ /* pure */ /* myproc-unprivileged */ /* unmodified-fnargs */ + int64_t len = clamp_t(int64_t, STAP_ARG_n + 1, 1, MAXSTRINGLEN); + if (_stp_strncpy_from_user(STAP_RETVALUE, + (char __user *) (uintptr_t) STAP_ARG_addr, len) < 0) + strlcpy(STAP_RETVALUE, STAP_ARG_err_msg, MAXSTRINGLEN); + else + STAP_RETVALUE[len - 1] = '\0'; +%} +%) /** * sfunction user_string_n_warn - Retrieves string from user space @@ -210,6 +231,25 @@ function user_string_n_warn:string (addr:long, n:long, warn_msg:string) } else STAP_RETVALUE[len - 1] = '\0'; %} +%(systemtap_v <= "3.0" %? +function user_string2_n_warn:string (addr:long, n:long, warn_msg:string) +%{ /* pure */ /* myproc-unprivileged */ /* unmodified-fnargs */ + int64_t len = clamp_t(int64_t, STAP_ARG_n + 1, 1, MAXSTRINGLEN); + long rc; + rc = _stp_strncpy_from_user(STAP_RETVALUE, + (char __user *) (uintptr_t) STAP_ARG_addr, len); + if (rc < 0) { + // NB: using error_buffer to get local space for the warning, but we're + // not aborting, so leave last_error alone. + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "user string copy fault %ld at %p [man error::fault]", rc, + (void *) (uintptr_t) STAP_ARG_addr); + _stp_warn(CONTEXT->error_buffer); + strlcpy (STAP_RETVALUE, STAP_ARG_warn_msg, MAXSTRINGLEN); + } else + STAP_RETVALUE[len - 1] = '\0'; +%} +%) /** * sfunction user_string_n_quoted - Retrieves and quotes string from user space @@ -296,7 +336,57 @@ function user_string_n_quoted:string (addr:long, inlen:long, outlen:long) %} %) +%(systemtap_v <= "3.0" %? +function user_string_n2_quoted:string (addr:long, inlen:long, outlen:long) +%( systemtap_v >= "3.0" %? + { + try + { + __str = string_quoted(user_string_n(addr, inlen)) + if (strlen(__str) > outlen-2) // room for the double-quotes plus \ldots + __str = (substr(__str,0,outlen-4) . "\"...") + return __str + } + catch + { + return sprintf("0x%x", addr) + } + } +%: + +%{ /* pure */ /* myproc-unprivileged */ + // Note the lack of STAP_ARG_n+1 as in other funcs() -- PR15617 + int64_t inlen = clamp_t(int64_t, STAP_ARG_inlen, 0, MAXSTRINGLEN); + int64_t outlen = clamp_t(int64_t, STAP_ARG_outlen, 0, MAXSTRINGLEN); + if (STAP_ARG_addr == 0) +#if STAP_COMPAT_VERSION < STAP_VERSION(2,3) // PR15044 + strlcpy(STAP_RETVALUE, "NULL", MAXSTRINGLEN); +#else + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%p", (void *)(long)STAP_ARG_addr); +#endif + else { + int rc = _stp_text_str(STAP_RETVALUE, + (char *)(uintptr_t)STAP_ARG_addr, inlen, outlen, 1, 1); + if (rc < 0) { +#if STAP_COMPAT_VERSION < STAP_VERSION(2,3) // PR15044 + strlcpy(STAP_RETVALUE, "", MAXSTRINGLEN); +#else +#ifdef CONFIG_COMPAT + if (_stp_is_compat_task()) + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%x", + (compat_long_t)STAP_ARG_addr); + else +#endif + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%p", + (void *)(long)STAP_ARG_addr); +#endif + } + } +%} +%) +%) + /** * sfunction user_string_utf32 - Retrieves UTF-32 string from user memory * @addr: The user address to retrieve the string from @@ -345,6 +435,11 @@ deref_fault: /* branched to from deref_string() */ function user_string_utf32:string (addr:long, err_msg:string) { try { return user_string_utf32(addr) } catch { return err_msg } } +%(systemtap_v <= "3.0" %? +function user_string2_utf32:string (addr:long, err_msg:string) { + try { return user_string_utf32(addr) } catch { return err_msg } +} +%) /** @@ -422,6 +517,11 @@ deref_fault: /* branched to from deref_string() */ function user_string_utf16:string (addr:long, err_msg:string) { try { return user_string_utf16(addr) } catch { return err_msg } } +%(systemtap_v <= "3.0" %? +function user_string2_utf16:string (addr:long, err_msg:string) { + try { return user_string_utf16(addr) } catch { return err_msg } +} +%) /** -- 2.43.5