1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// conversions tapset
// Copyright (C) 2005, 2006 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.
function hexstring:string (num:long) %{ /* pure */
snprintf (THIS->__retvalue, MAXSTRINGLEN, "0x%llx", (long long) THIS->num);
%}
function string:string (num:long) %{ /* pure */
snprintf (THIS->__retvalue, MAXSTRINGLEN, "%lld", (long long) THIS->num);
%}
function kernel_string:string (addr:long) %{ /* pure */
char *destination = THIS->__retvalue;
deref_string (destination, THIS->addr, MAXSTRINGLEN);
goto success;
deref_fault: /* branched to from deref() */
{
static char errmsg[40];
snprintf (errmsg, 40, "kernel string copy fault at 0x%p",
(void *) (uintptr_t) THIS->addr);
CONTEXT->last_error = errmsg;
}
success: ;
%}
# NB: accessing user space is hazardous from certain kernel contexts.
# Errors should be returned when this is detected.
function user_string:string (addr:long) %{ /* pure */
long rc = _stp_strncpy_from_user (THIS->__retvalue,
(const char __user*) (uintptr_t) THIS->addr,
MAXSTRINGLEN);
if (rc < 0)
{
static char errmsg[40];
snprintf (errmsg, 40, "user string copy fault at 0x%p",
(void *) (uintptr_t) THIS->addr);
CONTEXT->last_error = errmsg;
}
%}
|