summaryrefslogtreecommitdiffstats
path: root/tapset/s390x/syscalls.stp
blob: b1804388651b1ee5c00abfbca2211962b9bd10a2 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
%(arch == "s390x" %?

# mmap - s390x  version of the syscall.mmap probes
#
# long old_mmap(struct mmap_arg_struct __user *arg)
# long old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
#

probe syscall.mmap = kernel.function("old_mmap"),
		     kernel.function("old32_mmap")
{
	name = "mmap"

	if ( probefunc() == "old_mmap" ){
		argstr = get_mmap_args($arg);
        }else{
		argstr = get_32mmap_args($arg);
	}

}

probe syscall.mmap.return = kernel.function("old_mmap").return,
			    kernel.function("old32_mmap").return
{
        name = "mmap"
        retstr = returnstr(2)
}


# mmap2 - s390x version of the syscall.mmap2 probes
#
# long sys_mmap2(struct mmap_arg_struct __user  *arg)
# long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
#
probe syscall.mmap2 = kernel.function("sys_mmap2"),
		      kernel.function("sys32_mmap2")
{
        name = "mmap2"

	if ( probefunc() == "sys_mmap2" ){
		argstr = get_mmap_args($arg);
	}else{
		argstr = get_32mmap_args($arg);
	}

}

probe syscall.mmap2.return = kernel.function("sys_mmap2").return,
			     kernel.function("sys32_mmap2").return 
{
        name = "mmap2"
        retstr = returnstr(2)
}

function get_mmap_args:string (args:long)
%{
	struct mmap_arg_struct {
        	unsigned long addr;
        	unsigned long len;
        	unsigned long prot;
        	unsigned long flags;
        	unsigned long fd;
        	unsigned long offset;
	}a;

	char proto[60];
	char flags[256];

	if(_stp_copy_from_user((char *)&a,
		 (char *)THIS->args, sizeof(a))== 0){

		/* _mprotect_prot_str */
		proto[0] = '\0';
		if(a.prot){ 
			if(a.prot & 1) strcat (proto, "PROT_READ|");
			if(a.prot & 2) strcat (proto, "PROT_WRITE|");
			if(a.prot & 4) strcat (proto, "PROT_EXEC|");
		} else {
			strcat (proto, "PROT_NONE");
		}
		if (proto[0] != '\0') proto[strlen(proto)-1] = '\0';

		/* _mmap_flags */
		flags[0]='\0';
		if (a.flags & 1) strcat (flags, "MAP_SHARED|");
		if (a.flags & 2) strcat (flags, "MAP_PRIVATE|");
		if (a.flags & 0x10) strcat (flags, "MAP_FIXED|");
		if (a.flags & 0x20) strcat (flags, "MAP_ANONYMOUS|");
		if (a.flags & 0x100) strcat (flags, "MAP_GROWSDOWN|");
		if (a.flags & 0x800) strcat (flags, "MAP_DENYWRITE|");
		if (a.flags & 0x1000) strcat (flags, "MAP_EXECUTABLE|");
		if (a.flags & 0x2000) strcat (flags, "MAP_LOCKED|");
		if (a.flags & 0x4000) strcat (flags, "MAP_NORESERVE|");
		if (a.flags & 0x8000) strcat (flags, "MAP_POPULATE|");
		if (a.flags & 0x10000) strcat (flags, "MAP_NONBLOCK|");
		if (flags[0] != '\0') flags[strlen(flags)-1] = '\0';

		sprintf(THIS->__retvalue,"0x%lx, %ld, %s, %s, %ld, %ld",
			a.addr,
			a.len,
			proto,
			flags,
			a.fd,
			a.offset);
	}else{
		strlcpy (THIS->__retvalue, "UNKNOWN", MAXSTRINGLEN);
	}
%}

/* compat */
function get_32mmap_args:string (args:long)
%{
	struct mmap_arg_struct_emu31 {
		u32     addr;
		u32     len;
		u32     prot;
		u32     flags;
		u32     fd;
		u32     offset;
	}a;


        char proto[60];
        char flags[256];

        if(_stp_copy_from_user((char *)&a,
                 (char *)THIS->args, sizeof(a))== 0){

                /* _mprotect_prot_str */
                proto[0] = '\0';
                if(a.prot){
                        if(a.prot & 1) strcat (proto, "PROT_READ|");
                        if(a.prot & 2) strcat (proto, "PROT_WRITE|");
                        if(a.prot & 4) strcat (proto, "PROT_EXEC|");
                } else {
                        strcat (proto, "PROT_NONE");
                }
                if (proto[0] != '\0') proto[strlen(proto)-1] = '\0';

                /* _mmap_flags */
                flags[0]='\0';
                if (a.flags & 1) strcat (flags, "MAP_SHARED|");
                if (a.flags & 2) strcat (flags, "MAP_PRIVATE|");
                if (a.flags & 0x10) strcat (flags, "MAP_FIXED|");
                if (a.flags & 0x20) strcat (flags, "MAP_ANONYMOUS|");
                if (a.flags & 0x100) strcat (flags, "MAP_GROWSDOWN|");
                if (a.flags & 0x800) strcat (flags, "MAP_DENYWRITE|");
                if (a.flags & 0x1000) strcat (flags, "MAP_EXECUTABLE|");
                if (a.flags & 0x2000) strcat (flags, "MAP_LOCKED|");
                if (a.flags & 0x4000) strcat (flags, "MAP_NORESERVE|");
                if (a.flags & 0x8000) strcat (flags, "MAP_POPULATE|");
                if (a.flags & 0x10000) strcat (flags, "MAP_NONBLOCK|");
                if (flags[0] != '\0') flags[strlen(flags)-1] = '\0';

                sprintf(THIS->__retvalue,"0x%x, %d, %s, %s, %d, %d",
                        a.addr,
                        a.len,
                        proto,
                        flags,
                        a.fd,
                        a.offset);
        }else{
                strlcpy (THIS->__retvalue, "UNKNOWN", MAXSTRINGLEN);
        }
%}

%)