Debian Codegraph @

tapset/dyninst/context.stp

raw
1 // context tapset
2 // Copyright (C) 2012 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 // NB: functionally equivalent to linux/context.stp
10
11 %{
12 #include <sched.h>
13 #include <sys/prctl.h>
14 #include <sys/syscall.h>
15 #include <sys/types.h>
16 #include <unistd.h>
17 %}
18
19 global _stp_dyninst_remote = ""
20
21 function execname:string ()
22 %{
23 /* Need a 16-byte buffer, which will be 0-terminated only if shorter.
24 * Use 17 bytes to make sure we always have termination. */
25 char arg2[17] = {0};
26 if (prctl(PR_GET_NAME, (unsigned long)arg2, 0, 0, 0) == 0)
27 strlcpy (STAP_RETVALUE, arg2, MAXSTRINGLEN);
28 %}
29
30 function pid:long ()
31 %{ /* pure */ /* unprivileged */
32 STAP_RETVALUE = getpid();
33 %}
34
35 function tid:long ()
36 %{ /* pure */ /* unprivileged */
37 /* NB: no glibc wrapper available */
38 STAP_RETVALUE = syscall(SYS_gettid);
39 %}
40
41 function ppid:long()
42 %{ /* pure */ /* unprivileged */
43 STAP_RETVALUE = getppid();
44 %}
45
46 function pgrp:long ()
47 %{ /* pure */ /* unprivileged */
48 STAP_RETVALUE = getpgrp();
49 %}
50
51 function sid:long ()
52 %{ /* pure */ /* unprivileged */
53 STAP_RETVALUE = getsid(0);
54 %}
55
56 // TODO function pexecname:string ()
57
58 function gid:long ()
59 %{ /* pure */ /* unprivileged */
60 STAP_RETVALUE = getgid();
61 %}
62
63 function egid:long ()
64 %{ /* pure */ /* unprivileged */
65 STAP_RETVALUE = getegid();
66 %}
67
68 function uid:long ()
69 %{ /* pure */ /* unprivileged */
70 STAP_RETVALUE = getuid();
71 %}
72
73 function euid:long ()
74 %{ /* pure */ /* unprivileged */
75 STAP_RETVALUE = geteuid();
76 %}
77
78
79 // TODO function is_myproc:long ()
80 // NB: dyninst by nature is myproc-only, *except if you're root*
81
82 function cpu:long ()
83 %{ /* pure */ /* unprivileged */
84 STAP_RETVALUE = _stp_sched_getcpu();
85 %}
86
87
88 function registers_valid:long ()
89 %{ /* pure */ /* unprivileged */
90 STAP_RETVALUE = (CONTEXT->uregs != NULL);
91 %}
92
93 function user_mode:long ()
94 {
95 return 1;
96 }
97
98 function is_return:long ()
99 %{ /* pure */ /* unprivileged */
100 if (CONTEXT->probe_type == stp_probe_type_uretprobe)
101 STAP_RETVALUE = 1;
102 else
103 STAP_RETVALUE = 0;
104 %}
105
106 function target:long ()
107 %{ /* pure */ /* unprivileged */
108 STAP_RETVALUE = stp_session_attributes()->target;
109 %}
110
111 function module_name:string ()
112 %{ /* pure */ /* unprivileged */
113 strlcpy(STAP_RETVALUE, stp_session_attributes()->module_name, MAXSTRINGLEN);
114 %}
115
116 function stp_pid:long ()
117 %{ /* pure */ /* unprivileged */
118 STAP_RETVALUE = stp_session_attributes()->stp_pid;
119 %}
120
121 function remote_id:long ()
122 {
123 return strtol(substr(_stp_dyninst_remote,0,1), 10)
124 }
125
126 function remote_uri:string ()
127 {
128 return substr(_stp_dyninst_remote, 2, %{ STP_REMOTE_URI_LEN %})
129 }
130
131 // TODO function stack_size:long ()
132
133 // TODO function stack_used:long ()
134
135 // TODO function stack_unused:long ()
136
137 function addr:long ()
138 {
139 return uaddr()
140 }
141
142 function uaddr:long ()
143 %{ /* pure */ /* unprivileged */
144 STAP_RETVALUE = (intptr_t)(CONTEXT->uregs ? REG_IP(CONTEXT->uregs) : 0);
145 %}
146
147 // TODO function cmdline_args:string(n:long, m:long, delim:string)
148
149 // TODO function cmdline_arg:string(n:long)
150
151 // TODO function cmdline_str:string()