summaryrefslogtreecommitdiffstats
path: root/tapset/conversions.stp
blob: af993992aee3b01bc0a064c6ad5a0e1ff57242b7 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// conversions tapset
// Copyright (C) 2005-2007 Red Hat Inc.
// Copyright (C) 2007 Intel Corporation.
//
// 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 kernel_string:string (addr:long) %{ /* pure */
  char *destination = THIS->__retvalue;
  deref_string (destination, THIS->addr, MAXSTRINGLEN);
  if (0) {
deref_fault: /* branched to from 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;
  }
%}

function kernel_string_n:string (addr:long, n:long) %{ /* pure */
  char *destination = THIS->__retvalue;
  long len = THIS->n + 1;
  len = (len > MAXSTRINGLEN) ? MAXSTRINGLEN : len;
  deref_string (destination, THIS->addr, len);
  if (0) {
deref_fault: /* branched to from 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;
  }
%}

function kernel_long:long (addr:long) %{ /* pure */
  THIS->__retvalue = kread((long *) (intptr_t) THIS->addr);
  if (0) {
deref_fault: /* branched to from deref() */
    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;
  }
%}

function kernel_int:long (addr:long) %{ /* pure */
  THIS->__retvalue = kread((int *) (intptr_t) THIS->addr);
  if (0) {
deref_fault: /* branched to from deref() */
    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;
  }
%}

function kernel_short:long (addr:long) %{ /* pure */
  THIS->__retvalue = kread((short *) (intptr_t) THIS->addr);
  if (0) {
deref_fault: /* branched to from deref() */
    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;
  }
%}

function kernel_char:long (addr:long) %{ /* pure */
  THIS->__retvalue = kread((char *) (intptr_t) THIS->addr);
  if (0) {
deref_fault: /* branched to from deref() */
    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;
  }
%}




// On rare cases when userspace data is not accessible, 
// this function returns "<unknown>"

function user_string:string (addr:long) { return user_string2 (addr, "<unknown>") }

function user_string2:string (addr:long, err_msg:string) %{ /* pure */
  if (_stp_strncpy_from_user (THIS->__retvalue, 
        (const char __user*) (uintptr_t) THIS->addr,
        MAXSTRINGLEN) < 0)
    strlcpy (THIS->__retvalue, THIS->err_msg, MAXSTRINGLEN);
%}

function user_string_warn:string (addr:long) %{ /* pure */
  long rc = _stp_strncpy_from_user (THIS->__retvalue,
      (const char __user*) (uintptr_t) THIS->addr, MAXSTRINGLEN);
  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", rc,
        (void *) (uintptr_t) THIS->addr);
    _stp_warn(CONTEXT->error_buffer);
    strlcpy (THIS->__retvalue, "<unknown>", MAXSTRINGLEN);
  }
%}

function user_string_quoted:string (addr:long) %{ /* pure */
  if (THIS->addr == 0)	
    strlcpy (THIS->__retvalue, "NULL", MAXSTRINGLEN);
  else
    /* XXX: stp_text_str uses sleepy __get_user() => unsafe ?!  */
    _stp_text_str(THIS->__retvalue, (char *)(uintptr_t)THIS->addr,
        MAXSTRINGLEN, 1, 1);
%}