diff options
author | Josh Stone <jistone@redhat.com> | 2010-04-01 15:18:01 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2010-04-01 15:21:05 -0700 |
commit | b70cb5c663255b46ece13e6758a5cb3e58d9a95c (patch) | |
tree | be609dbec8fccba9febc5e988dd467962edc3b75 | |
parent | cba1d02def7a84d79dc8b40506b661db0973ccf5 (diff) | |
download | systemtap-steved-b70cb5c663255b46ece13e6758a5cb3e58d9a95c.tar.gz systemtap-steved-b70cb5c663255b46ece13e6758a5cb3e58d9a95c.tar.xz systemtap-steved-b70cb5c663255b46ece13e6758a5cb3e58d9a95c.zip |
Add kernel-writing functions for guru only
* runtime/loc2c-runtime.h (store_deref_string): New.
* tapset/conversions-guru.stp (set_kernel_*): New guru functions.
-rw-r--r-- | runtime/loc2c-runtime.h | 11 | ||||
-rw-r--r-- | tapset/conversions-guru.stp | 117 |
2 files changed, 128 insertions, 0 deletions
diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index c75639ee..bd1faa51 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -1011,6 +1011,17 @@ extern void __store_deref_bad(void); (dst); \ }) +#define store_deref_string(src, addr, maxbytes) \ + ({ \ + uintptr_t _addr; \ + size_t _len; \ + char *_s = (src); \ + for (_len = (maxbytes), _addr = (uintptr_t)(addr); \ + _len > 1 && _s && *_s != '\0'; --_len, ++_addr) \ + store_deref(1, _addr, *_s++); \ + store_deref(1, _addr, '\0'); \ + }) + #define CATCH_DEREF_FAULT() \ if (0) { \ deref_fault: ; \ diff --git a/tapset/conversions-guru.stp b/tapset/conversions-guru.stp new file mode 100644 index 00000000..f914bb31 --- /dev/null +++ b/tapset/conversions-guru.stp @@ -0,0 +1,117 @@ +// guru-mode conversions tapset +// Copyright (C) 2010 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +/** + * sfunction set_kernel_string - Writes a string to kernel memory. + * @addr: The kernel address to write the string to. + * @val: The string which is to be written. + * + * Description: Writes the given string to a given kernel + * memory address. Reports an error on string copy fault. + */ +function set_kernel_string (addr:long, val:string) %{ /* guru */ + store_deref_string (THIS->val, THIS->addr, MAXSTRINGLEN); + if (0) { +deref_fault: /* branched to from store_deref_string() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel string copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} + +/** + * sfunction set_kernel_string_n - Writes a string of given length to kernel memory. + * @addr: The kernel address to write the string to. + * @n: The maximum length of the string. + * @val: The string which is to be written. + * + * Description: Writes the given string up to a maximum given length to a + * given kernel memory address. Reports an error on string copy fault. + */ +function set_kernel_string_n (addr:long, n:long, val:string) %{ /* guru */ + int64_t len = clamp_t(int64_t, THIS->n + 1, 1, MAXSTRINGLEN); + store_deref_string (THIS->val, THIS->addr, len); + if (0) { +deref_fault: /* branched to from store_deref_string() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel string copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} + +/** + * sfunction set_kernel_long - Writes a long value to kernel memory. + * @addr: The kernel address to write the long to. + * @val: The long which is to be written. + * + * Description: Writes the long value to a given kernel memory address. + * Reports an error when writing to the given address fails. + */ +function set_kernel_long (addr:long, val:long) %{ /* guru */ + kwrite((long *) (intptr_t) THIS->addr, THIS->val); + if (0) { +deref_fault: /* branched to from kwrite() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel long copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} + +/** + * sfunction set_kernel_int - Writes an int value to kernel memory. + * @addr: The kernel address to write the int to. + * @val: The int which is to be written. + * + * Description: Writes the int value to a given kernel memory address. + * Reports an error when writing to the given address fails. + */ +function set_kernel_int (addr:long, val:long) %{ /* guru */ + kwrite((int *) (intptr_t) THIS->addr, THIS->val); + if (0) { +deref_fault: /* branched to from kwrite() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel int copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} + +/** + * sfunction set_kernel_short - Writes a short value to kernel memory. + * @addr: The kernel address to write the short to. + * @val: The short which is to be written. + * + * Description: Writes the short value to a given kernel memory address. + * Reports an error when writing to the given address fails. + */ +function set_kernel_short (addr:long, val:long) %{ /* guru */ + kwrite((short *) (intptr_t) THIS->addr, THIS->val); + if (0) { +deref_fault: /* branched to from kwrite() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel short copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} + +/** + * sfunction set_kernel_char - Writes a char value to kernel memory. + * @addr: The kernel address to write the char to. + * @val: The char which is to be written. + * + * Description: Writes the char value to a given kernel memory address. + * Reports an error when writing to the given address fails. + */ +function set_kernel_char (addr:long, val:long) %{ /* guru */ + kwrite((char *) (intptr_t) THIS->addr, THIS->val); + if (0) { +deref_fault: /* branched to from kwrite() */ + snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), + "kernel char copy fault at 0x%p", (void *) (uintptr_t) THIS->addr); + CONTEXT->last_error = CONTEXT->error_buffer; + } +%} |