| 1 |
// guru-mode conversions tapset |
| 2 |
// Copyright (C) 2010-2017 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 |
* sfunction set_kernel_string - Writes a string to kernel memory |
| 11 |
* @addr: The kernel address to write the string to |
| 12 |
* @val: The string which is to be written |
| 13 |
* |
| 14 |
* Description: Writes the given string to a given kernel |
| 15 |
* memory address. Reports an error on string copy fault. |
| 16 |
* Requires the use of guru mode (-g). |
| 17 |
*/ |
| 18 |
function set_kernel_string (addr:long, val:string) %{ /* guru */ |
| 19 |
__label__ deref_fault; |
| 20 |
store_kderef_string (STAP_ARG_val, STAP_ARG_addr, MAXSTRINGLEN); |
| 21 |
if (0) { |
| 22 |
deref_fault: /* branched to from store_deref_string() */ |
| 23 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 24 |
"kernel string copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 25 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 26 |
} |
| 27 |
%} |
| 28 |
|
| 29 |
/** |
| 30 |
* sfunction set_kernel_string_n - Writes a string of given length to kernel memory |
| 31 |
* @addr: The kernel address to write the string to |
| 32 |
* @n: The maximum length of the string |
| 33 |
* @val: The string which is to be written |
| 34 |
* |
| 35 |
* Description: Writes the given string up to a maximum given length to a |
| 36 |
* given kernel memory address. Reports an error on string copy fault. |
| 37 |
* Requires the use of guru mode (-g). |
| 38 |
*/ |
| 39 |
function set_kernel_string_n (addr:long, n:long, val:string) %{ /* guru */ |
| 40 |
__label__ deref_fault; |
| 41 |
int64_t len = clamp_t(int64_t, STAP_ARG_n + 1, 1, MAXSTRINGLEN); |
| 42 |
store_kderef_string (STAP_ARG_val, STAP_ARG_addr, len); |
| 43 |
if (0) { |
| 44 |
deref_fault: /* branched to from store_deref_string() */ |
| 45 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 46 |
"kernel string copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 47 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 48 |
} |
| 49 |
%} |
| 50 |
|
| 51 |
/** |
| 52 |
* sfunction set_kernel_long - Writes a long value to kernel memory |
| 53 |
* @addr: The kernel address to write the long to |
| 54 |
* @val: The long which is to be written |
| 55 |
* |
| 56 |
* Description: Writes the long value to a given kernel memory address. |
| 57 |
* Reports an error when writing to the given address fails. |
| 58 |
* Requires the use of guru mode (-g). |
| 59 |
*/ |
| 60 |
function set_kernel_long (addr:long, val:long) %{ /* guru */ |
| 61 |
__label__ deref_fault; |
| 62 |
kwrite((long *) (uintptr_t) STAP_ARG_addr, STAP_ARG_val); |
| 63 |
if (0) { |
| 64 |
deref_fault: /* branched to from kwrite() */ |
| 65 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 66 |
"kernel long copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 67 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 68 |
} |
| 69 |
%} |
| 70 |
|
| 71 |
/** |
| 72 |
* sfunction set_kernel_int - Writes an int value to kernel memory |
| 73 |
* @addr: The kernel address to write the int to |
| 74 |
* @val: The int which is to be written |
| 75 |
* |
| 76 |
* Description: Writes the int value to a given kernel memory address. |
| 77 |
* Reports an error when writing to the given address fails. |
| 78 |
* Requires the use of guru mode (-g). |
| 79 |
*/ |
| 80 |
function set_kernel_int (addr:long, val:long) %{ /* guru */ |
| 81 |
__label__ deref_fault; |
| 82 |
kwrite((int *) (uintptr_t) STAP_ARG_addr, STAP_ARG_val); |
| 83 |
if (0) { |
| 84 |
deref_fault: /* branched to from kwrite() */ |
| 85 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 86 |
"kernel int copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 87 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 88 |
} |
| 89 |
%} |
| 90 |
|
| 91 |
/** |
| 92 |
* sfunction set_kernel_short - Writes a short value to kernel memory |
| 93 |
* @addr: The kernel address to write the short to |
| 94 |
* @val: The short which is to be written |
| 95 |
* |
| 96 |
* Description: Writes the short value to a given kernel memory address. |
| 97 |
* Reports an error when writing to the given address fails. |
| 98 |
* Requires the use of guru mode (-g). |
| 99 |
*/ |
| 100 |
function set_kernel_short (addr:long, val:long) %{ /* guru */ |
| 101 |
__label__ deref_fault; |
| 102 |
kwrite((short *) (uintptr_t) STAP_ARG_addr, STAP_ARG_val); |
| 103 |
if (0) { |
| 104 |
deref_fault: /* branched to from kwrite() */ |
| 105 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 106 |
"kernel short copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 107 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 108 |
} |
| 109 |
%} |
| 110 |
|
| 111 |
/** |
| 112 |
* sfunction set_kernel_char - Writes a char value to kernel memory |
| 113 |
* @addr: The kernel address to write the char to |
| 114 |
* @val: The char which is to be written |
| 115 |
* |
| 116 |
* Description: Writes the char value to a given kernel memory address. |
| 117 |
* Reports an error when writing to the given address fails. |
| 118 |
* Requires the use of guru mode (-g). |
| 119 |
*/ |
| 120 |
function set_kernel_char (addr:long, val:long) %{ /* guru */ |
| 121 |
__label__ deref_fault; |
| 122 |
kwrite((char *) (uintptr_t) STAP_ARG_addr, STAP_ARG_val); |
| 123 |
if (0) { |
| 124 |
deref_fault: /* branched to from kwrite() */ |
| 125 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 126 |
"kernel char copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 127 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 128 |
} |
| 129 |
%} |
| 130 |
|
| 131 |
/** |
| 132 |
* sfunction set_kernel_pointer - Writes a pointer value to kernel memory. |
| 133 |
* @addr: The kernel address to write the pointer to |
| 134 |
* @val: The pointer which is to be written |
| 135 |
* |
| 136 |
* Description: Writes the pointer value to a given kernel memory address. |
| 137 |
* Reports an error when writing to the given address fails. |
| 138 |
* Requires the use of guru mode (-g). |
| 139 |
*/ |
| 140 |
function set_kernel_pointer (addr:long, val:long) %{ /* guru */ |
| 141 |
__label__ deref_fault; |
| 142 |
kwrite((void **) (uintptr_t) STAP_ARG_addr, (uintptr_t)STAP_ARG_val); |
| 143 |
if (0) { |
| 144 |
deref_fault: /* branched to from kwrite() */ |
| 145 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 146 |
"kernel pointer copy fault at 0x%p [man error::fault]", (void *) (uintptr_t) STAP_ARG_addr); |
| 147 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 148 |
} |
| 149 |
%} |