forked from dtrace4linux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing.c
More file actions
110 lines (100 loc) · 2.74 KB
/
missing.c
File metadata and controls
110 lines (100 loc) · 2.74 KB
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
/**********************************************************************/
/* Functions which are not there in the older kernels. */
/* Open Source */
/* Author: P D Fox */
/* $Header: Last edited: 26-Jul-2012 1.6 $ */
/**********************************************************************/
#include "dtrace_linux.h"
# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 21)
# define toupper(x) ((x) >= 'a' && (x) <= 'z' ? (x) - 0x20 : (x))
# define tolower(x) ((x) >= 'A' && (x) <= 'Z' ? (x) + 0x20 : (x))
int
strcasecmp(const char *s1, const char *s2)
{
while (*s1 && *s2) {
int ch1 = *s1++;
int ch2 = *s2++;
int n = toupper(ch1) - toupper(ch2);
if (n)
return n < 0 ? -1 : 1;
}
if (*s1)
return 1;
if (*s2)
return -1;
return 0;
}
# endif
/**********************************************************************/
/* Make sure we never use the kernels string functions here, in */
/* case we are probing them. */
/**********************************************************************/
#if !defined(__HAVE_ARCH_STRLEN)
size_t
strlen(const char *str)
{
const char *str1 = str;
while (*str1)
str1++;
return str1 - str;
}
#endif
#if !defined(__HAVE_ARCH_STRCMP)
int
strncmp(const char *s1, const char *s2, size_t len)
{
while (len-- > 0) {
int c1 = *s1++;
int c2 = *s2++;
if (c1 == c2 && c1 == 0)
return 0;
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
}
return 0;
}
#endif
# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
struct task_struct *
find_task_by_vpid(int n)
{
# if defined(PIDTYPE_PID)
return find_task_by_pid_type(PIDTYPE_PID, n);
# else
return find_task_by_pid(n);
# endif
}
# endif
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16)
/**********************************************************************/
/* Simple bubble sort replacement for old kernels. Called by */
/* fasttrap_isa.c */
/**********************************************************************/
void sort(void *base, size_t num, size_t size,
int (*cmp)(const void *, const void *),
void (*swap)(void *, void *, int))
{ int i, j;
for (i = 0; i < num; i++) {
for (j = i + 1; j < num; j++) {
int r = cmp(&base[i * size], &base[j * size]);
if (r > 0)
swap(&base[i * size], &base[j * size], size);
}
}
}
#endif
# if defined(FUNC_SMP_CALL_FUNCTION_SINGLE_MISSING)
/**********************************************************************/
/* If only one cpu, then it must be us who gets called. */
/**********************************************************************/
int
smp_call_function_single(int cpuid, void (*func)(void *), void *info, int wait)
{
local_irq_disable();
(*func)(info);
local_irq_enable();
return 0;
}
# endif