summaryrefslogtreecommitdiff
path: root/src/bin/evil
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
commitcd69ef4c8a66e7155967a8b661a014856979cf31 (patch)
tree4a351ae4a4ca91abf29c85254b85ea8da71f74b0 /src/bin/evil
parent59a9dfd11860888a35e96dfe51af63cea5cecfe1 (diff)
merge: add evil files
SVN revision: 76464
Diffstat (limited to 'src/bin/evil')
-rw-r--r--src/bin/evil/Makefile.am53
-rw-r--r--src/bin/evil/evil_suite.c221
-rw-r--r--src/bin/evil/evil_suite.h14
-rw-r--r--src/bin/evil/evil_test_dlfcn.c80
-rw-r--r--src/bin/evil/evil_test_dlfcn.h8
-rw-r--r--src/bin/evil/evil_test_environment.c178
-rw-r--r--src/bin/evil/evil_test_environment.h8
-rw-r--r--src/bin/evil/evil_test_gettimeofday.c51
-rw-r--r--src/bin/evil/evil_test_gettimeofday.h8
-rw-r--r--src/bin/evil/evil_test_link.c158
-rw-r--r--src/bin/evil/evil_test_link.h8
-rw-r--r--src/bin/evil/evil_test_memcpy.c145
-rw-r--r--src/bin/evil/evil_test_memcpy.h8
-rw-r--r--src/bin/evil/evil_test_mkstemp.c53
-rw-r--r--src/bin/evil/evil_test_mkstemp.h8
-rw-r--r--src/bin/evil/evil_test_pipe.c126
-rw-r--r--src/bin/evil/evil_test_pipe.h8
-rw-r--r--src/bin/evil/evil_test_print.c46
-rw-r--r--src/bin/evil/evil_test_print.h8
-rw-r--r--src/bin/evil/evil_test_realpath.c44
-rw-r--r--src/bin/evil/evil_test_realpath.h8
-rw-r--r--src/bin/evil/evil_test_util.c110
-rw-r--r--src/bin/evil/evil_test_util.h8
-rw-r--r--src/bin/evil/memcpy_glibc_arm.S231
-rwxr-xr-xsrc/bin/evil/memcpy_glibc_i686.S81
-rw-r--r--src/bin/evil/test_evil.c27
26 files changed, 1698 insertions, 0 deletions
diff --git a/src/bin/evil/Makefile.am b/src/bin/evil/Makefile.am
new file mode 100644
index 0000000000..538bbdcc69
--- /dev/null
+++ b/src/bin/evil/Makefile.am
@@ -0,0 +1,53 @@
1
2MAINTAINERCLEANFILES = Makefile.in
3
4AM_CPPFLAGS = \
5-I$(top_srcdir) \
6-I$(top_srcdir)/bin \
7-I$(top_srcdir)/src/lib \
8@EVIL_CPPFLAGS@
9
10AM_CFLAGS = @EVIL_CFLAGS@
11
12bin_PROGRAMS = evil_suite test_evil
13
14evil_suite_SOURCES = \
15evil_suite.c \
16evil_test_dlfcn.c \
17evil_test_environment.c \
18evil_test_gettimeofday.c \
19evil_test_link.c \
20evil_test_memcpy.c \
21evil_test_mkstemp.c \
22evil_test_pipe.c \
23evil_test_print.c \
24evil_test_realpath.c \
25evil_test_util.c \
26evil_suite.h \
27evil_test_dlfcn.h \
28evil_test_environment.h \
29evil_test_gettimeofday.h \
30evil_test_link.h \
31evil_test_memcpy.h \
32evil_test_mkstemp.h \
33evil_test_pipe.h \
34evil_test_print.h \
35evil_test_realpath.h \
36evil_test_util.h
37
38if EVIL_HAVE_WINCE
39
40evil_suite_SOURCES += memcpy_glibc_arm.S
41
42#else
43
44#suite_SOURCES += memcpy_glibc_i686.S
45
46endif
47
48evil_suite_LDADD = $(top_builddir)/src/lib/libdl.la $(top_builddir)/src/lib/libevil.la -lm
49evil_suite_LDFLAGS = -Wl,--enable-auto-import
50
51test_evil_SOURCES = test_evil.c
52test_evil_LDADD = $(top_builddir)/src/lib/libevil.la
53test_evil_LDFLAGS = -Wl,--enable-auto-import
diff --git a/src/bin/evil/evil_suite.c b/src/bin/evil/evil_suite.c
new file mode 100644
index 0000000000..ba928f0682
--- /dev/null
+++ b/src/bin/evil/evil_suite.c
@@ -0,0 +1,221 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#undef WIN32_LEAN_AND_MEAN
11
12#include "Evil.h"
13#include "evil_suite.h"
14#include "evil_test_dlfcn.h"
15#include "evil_test_environment.h"
16#include "evil_test_gettimeofday.h"
17#include "evil_test_link.h"
18#include "evil_test_memcpy.h"
19#include "evil_test_mkstemp.h"
20#include "evil_test_pipe.h"
21#include "evil_test_print.h"
22#include "evil_test_realpath.h"
23#include "evil_test_util.h"
24
25
26typedef int(*function)(suite *s);
27
28struct test
29{
30 const char *name;
31 function fct;
32};
33
34struct list
35{
36 void *data;
37 int succeed;
38 list *next;
39};
40
41struct suite
42{
43 LARGE_INTEGER freq;
44 LARGE_INTEGER start;
45 LARGE_INTEGER end;
46
47 list *first;
48 list *l;
49
50 int tests_count;
51 int tests_success;
52};
53
54
55static suite *
56suite_new(void)
57{
58 suite *s;
59
60 s = (suite *)malloc(sizeof(suite));
61 if (!s) return NULL;
62
63 if (!QueryPerformanceFrequency(&s->freq))
64 {
65 free(s);
66 return NULL;
67 }
68
69 s->first = NULL;
70 s->l = NULL;
71
72 s->tests_count = 0;
73 s->tests_success = 0;
74
75 return s;
76}
77
78static void
79suite_del(suite *s)
80{
81 list *l;
82 list *tmp;
83
84 if (!s) return;
85
86 l = s->first;
87 while (l)
88 {
89 tmp = l->next;
90 free(l->data);
91 free(l);
92 l = tmp;
93 }
94
95 free(s);
96}
97
98void
99suite_time_start(suite *s)
100{
101 QueryPerformanceCounter(&s->start);
102}
103
104void
105suite_time_stop(suite *s)
106{
107 QueryPerformanceCounter(&s->end);
108}
109
110double
111suite_time_get(suite *s)
112{
113 return (double)(s->end.QuadPart - s->start.QuadPart) / (double)s->freq.QuadPart;
114}
115
116static void
117suite_test_add(suite *s, const char *name, function fct)
118{
119 test *t;
120 list *l;
121
122 t = (test *)malloc(sizeof(test));
123 if (!t) return;
124
125 l = (list *)malloc(sizeof(list));
126 if (!l)
127 {
128 free(t);
129 return;
130 }
131
132 t->name = name;
133 t->fct = fct;
134
135 l->data = t;
136 l->succeed = 0;
137 l->next = NULL;
138
139 if (!s->first) s->first = l;
140
141 if (!s->l)
142 s->l = l;
143 else
144 {
145 s->l->next = l;
146 s->l =l;
147 }
148}
149
150static void
151suite_run(suite *s)
152{
153 list *l;
154
155 l = s->first;
156 while (l)
157 {
158 test *t;
159
160 t = (test *)l->data;
161 l->succeed = t->fct(s);
162 printf("%s test: %s\n", t->name, l->succeed ? "success" : "failure");
163 s->tests_count++;
164 if (l->succeed)
165 s->tests_success++;
166 l = l->next;
167 }
168}
169
170static void
171suite_show(suite *s)
172{
173 printf ("\n%d/%d tests passed (%d%%)\n",
174 s->tests_success,
175 s->tests_count,
176 (100 * s->tests_success) / s->tests_count);
177}
178
179int
180main(void)
181{
182 test tests[] = {
183 { "dlfcn ", test_dlfcn },
184 { "environment ", test_environment },
185 { "gettimeofday", test_gettimeofday },
186 { "link ", test_link },
187 { "mkstemp ", test_mkstemp },
188 { "pipe ", test_pipe },
189 { "print ", test_print },
190 { "realpath ", test_realpath },
191 { "util ", test_util },
192/* { "memcpy ", test_memcpy }, */
193 { NULL, NULL },
194 };
195 suite *s;
196 int i;
197
198 if (!evil_init())
199 return EXIT_FAILURE;
200
201 s = suite_new();
202 if (!s)
203 {
204 evil_shutdown();
205 return EXIT_FAILURE;
206 }
207
208 for (i = 0; tests[i].name; ++i)
209 {
210 suite_test_add(s, tests[i].name, tests[i].fct);
211 }
212
213 suite_run(s);
214
215 suite_show(s);
216
217 suite_del(s);
218 evil_shutdown();
219
220 return EXIT_SUCCESS;
221}
diff --git a/src/bin/evil/evil_suite.h b/src/bin/evil/evil_suite.h
new file mode 100644
index 0000000000..d3284b4fbb
--- /dev/null
+++ b/src/bin/evil/evil_suite.h
@@ -0,0 +1,14 @@
1#ifndef __EVIL_SUITE_H__
2#define __EVIL_SUITE_H__
3
4
5typedef struct test test;
6typedef struct list list;
7typedef struct suite suite;
8
9void suite_time_start(suite *s);
10void suite_time_stop(suite *s);
11double suite_time_get(suite *s);
12
13
14#endif /* __EVIL_SUITE_H__ */
diff --git a/src/bin/evil/evil_test_dlfcn.c b/src/bin/evil/evil_test_dlfcn.c
new file mode 100644
index 0000000000..fb32dd1540
--- /dev/null
+++ b/src/bin/evil/evil_test_dlfcn.c
@@ -0,0 +1,80 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6#include <dlfcn.h>
7
8#include <Evil.h>
9
10#include "evil_suite.h"
11#include "evil_test_dlfcn.h"
12
13
14typedef int (*_evil_init)(void);
15typedef int (*_evil_shutdwon)(void);
16
17
18static int
19test_dlfcn_test_dlopen(void)
20{
21 void *handle;
22
23 handle = dlopen("libevil-1.dll", 0);
24 if (!handle)
25 return 0;
26
27 if (dlclose(handle))
28 return 0;
29
30 return 1;
31}
32
33static int
34test_dlfcn_test_dlsym(void)
35{
36 void *handle;
37 _evil_init sym_init;
38 _evil_shutdwon sym_shutdown;
39
40 handle = dlopen("libevil-1.dll", 0);
41 if (!handle)
42 return 0;
43
44 sym_init = dlsym(handle, "evil_init");
45 if (!sym_init)
46 {
47 dlclose(handle);
48 return 0;
49 }
50
51 sym_shutdown = dlsym(handle, "evil_shutdown");
52 if (!sym_shutdown)
53 {
54 dlclose(handle);
55 return 0;
56 }
57
58 if (dlclose(handle))
59 return 0;
60
61 return 1;
62}
63
64static int
65test_dlfcn_tests_run(suite *s __UNUSED__)
66{
67 int res;
68
69 res = test_dlfcn_test_dlopen();
70 res &= test_dlfcn_test_dlsym();
71
72 return res;
73}
74
75int
76test_dlfcn(suite *s)
77{
78
79 return test_dlfcn_tests_run(s);
80}
diff --git a/src/bin/evil/evil_test_dlfcn.h b/src/bin/evil/evil_test_dlfcn.h
new file mode 100644
index 0000000000..0c9bce689e
--- /dev/null
+++ b/src/bin/evil/evil_test_dlfcn.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_DLFCN_H__
2#define __EVIL_TEST_DLFCN_H__
3
4
5int test_dlfcn(suite *s);
6
7
8#endif /* __EVIL_TEST_DLFCN_H__ */
diff --git a/src/bin/evil/evil_test_environment.c b/src/bin/evil/evil_test_environment.c
new file mode 100644
index 0000000000..3048a40124
--- /dev/null
+++ b/src/bin/evil/evil_test_environment.c
@@ -0,0 +1,178 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_environment.h"
11
12
13static int
14test_env_test_setenv_NULL(void)
15{
16 char *val;
17 int res;
18
19 res = setenv("EVIL_TEST_ENV", NULL, 1);
20 if (res < 0)
21 return 0;
22
23 val = getenv("EVIL_TEST_ENV");
24
25 return val ? 0 : 1;
26}
27
28static int
29test_env_test_setenv_NULL_after_set(void)
30{
31 char *val;
32 int res;
33
34 res = setenv("EVIL_TEST_ENV", "val", 1);
35 if (res < 0)
36 return 0;
37
38 val = getenv("EVIL_TEST_ENV");
39 if (!val)
40 return 0;
41
42 if (strcmp(val, "val"))
43 return 0;
44
45 res = setenv("EVIL_TEST_ENV", NULL, 1);
46 if (res < 0)
47 return 0;
48
49 val = getenv("EVIL_TEST_ENV");
50
51 return val ? 0 : 1;
52}
53
54static int
55test_env_test_getenv_one(void)
56{
57 char *val;
58 int res;
59
60 res = setenv("EVIL_TEST_ENV", "val", 1);
61 if (res < 0)
62 return 0;
63
64 val = getenv("EVIL_TEST_ENV");
65 if (!val)
66 return 0;
67
68 if (strcmp(val, "val"))
69 return 0;
70
71 return 1;
72}
73
74static int
75test_env_test_getenv_two(void)
76{
77 char *val;
78 int res;
79
80 res = setenv("EVIL_TEST_ENV1", "val1", 1);
81 if (res < 0)
82 return 0;
83
84 res = setenv("EVIL_TEST_ENV2", "val2", 1);
85 if (res < 0)
86 return 0;
87
88 val = getenv("EVIL_TEST_ENV1");
89 if (!val)
90 return 0;
91 if (strcmp(val, "val1"))
92 return 0;
93
94 val = getenv("EVIL_TEST_ENV2");
95 if (!val)
96 return 0;
97
98 if (strcmp(val, "val2"))
99 return 0;
100
101 return 1;
102}
103
104static int
105test_env_test_getenv_two_swapped(void)
106{
107 char *val;
108 int res;
109
110 res = setenv("EVIL_TEST_ENV1", "val1", 1);
111 if (res < 0)
112 return 0;
113
114 res = setenv("EVIL_TEST_ENV2", "val2", 1);
115 if (res < 0)
116 return 0;
117
118 val = getenv("EVIL_TEST_ENV2");
119 if (!val)
120 return 0;
121 if (strcmp(val, "val2"))
122 return 0;
123
124 val = getenv("EVIL_TEST_ENV1");
125 if (!val)
126 return 0;
127
128 if (strcmp(val, "val1"))
129 return 0;
130
131 return 1;
132}
133
134static int
135test_env_test_unsetenv(void)
136{
137 char *val;
138 int res;
139
140 res = setenv("EVIL_TEST_ENV", "val", 1);
141 if (res < 0)
142 return 0;
143
144 val = getenv("EVIL_TEST_ENV");
145 if (!val)
146 return 0;
147
148 if (unsetenv("EVIL_TEST_ENV") != 0)
149 return 0;
150
151 val = getenv("EVIL_TEST_ENV");
152 if (val)
153 return 0;
154
155 return 1;
156}
157
158static int
159test_env_tests_run(suite *s __UNUSED__)
160{
161 int res;
162
163 res = test_env_test_setenv_NULL();
164 res &= test_env_test_setenv_NULL_after_set();
165 res &= test_env_test_getenv_one();
166 res &= test_env_test_getenv_two();
167 res &= test_env_test_getenv_two_swapped();
168 res &= test_env_test_unsetenv();
169
170 return res;
171}
172
173int
174test_environment(suite *s)
175{
176
177 return test_env_tests_run(s);
178}
diff --git a/src/bin/evil/evil_test_environment.h b/src/bin/evil/evil_test_environment.h
new file mode 100644
index 0000000000..763ee401b1
--- /dev/null
+++ b/src/bin/evil/evil_test_environment.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_ENVIRONMENT_H__
2#define __EVIL_TEST_ENVIRONMENT_H__
3
4
5int test_environment(suite *s);
6
7
8#endif /* __EVIL_TEST_ENVIRONMENT_H__ */
diff --git a/src/bin/evil/evil_test_gettimeofday.c b/src/bin/evil/evil_test_gettimeofday.c
new file mode 100644
index 0000000000..49742eb5d3
--- /dev/null
+++ b/src/bin/evil/evil_test_gettimeofday.c
@@ -0,0 +1,51 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6#include <math.h>
7#include <sys/time.h>
8
9#include <Evil.h>
10
11#include "evil_suite.h"
12#include "evil_test_gettimeofday.h"
13
14static int
15test_time_test_gettimeofday(void)
16{
17 struct timeval tp1;
18 struct timeval tp2;
19 double delta;
20
21 gettimeofday (&tp1, NULL);
22
23 Sleep(1000);
24
25 gettimeofday (&tp2, NULL);
26
27 delta = (double)(tp2.tv_sec - tp1.tv_sec) + (double)(tp2.tv_usec - tp1.tv_usec) / 1000000.0;
28 if (fabs(delta - 1) > 0.005)
29 {
30 return 0;
31 }
32
33 return 1;
34}
35
36static int
37test_time_tests_run(suite *s __UNUSED__)
38{
39 int res;
40
41 res = test_time_test_gettimeofday();
42
43 return res;
44}
45
46int
47test_gettimeofday(suite *s)
48{
49
50 return test_time_tests_run(s);
51}
diff --git a/src/bin/evil/evil_test_gettimeofday.h b/src/bin/evil/evil_test_gettimeofday.h
new file mode 100644
index 0000000000..ad3155b146
--- /dev/null
+++ b/src/bin/evil/evil_test_gettimeofday.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_GETTIMEOFDAY_H__
2#define __EVIL_TEST_GETTIMEOFDAY_H__
3
4
5int test_gettimeofday(suite *s);
6
7
8#endif /* __EVIL_TEST_GETTIMEOFDAY_H__ */
diff --git a/src/bin/evil/evil_test_link.c b/src/bin/evil/evil_test_link.c
new file mode 100644
index 0000000000..cf4cd931ae
--- /dev/null
+++ b/src/bin/evil/evil_test_link.c
@@ -0,0 +1,158 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_link.h"
11
12static int
13test_link_test_file_create(const char *name, const char *data)
14{
15 FILE *f;
16 size_t length;
17 size_t res;
18
19 f = fopen(name, "wb");
20 if (!f)
21 return 0;
22
23 length = strlen(data) + 1;
24 res = fwrite(data, 1, length, f);
25 if (res < length)
26 {
27 fclose(f);
28 return 0;
29 }
30
31 fclose(f);
32
33 return 1;
34}
35
36static int
37test_link_test_symlink(void)
38{
39#ifdef _WIN32_WCE
40 const char *old_name = "\\efl\\evil_test_link.dat";
41 const char *new_name = "\\efl\\evil_test_link.lnk";
42#else
43 const char *old_name = "evil_test_link.dat";
44 const char *new_name = "evil_test_link.lnk";
45#endif
46
47 if (!test_link_test_file_create(old_name,
48 "evil_test_link symlink data\n"))
49 return 0;
50
51 if (symlink(old_name, new_name) < 0)
52 {
53 unlink(old_name);
54 return 0;
55 }
56
57 if (unlink(new_name) < 0)
58 {
59 unlink(old_name);
60 return 0;
61 }
62
63 if (unlink(old_name) < 0)
64 return 0;
65
66 return 1;
67}
68
69static int
70test_link_test_readlink(void)
71{
72 char buf[1024];
73#ifdef _WIN32_WCE
74 const char *old_name = "\\efl\\evil_test_link.dat";
75 const char *new_name = "\\efl\\evil_test_link.lnk";
76#else
77 const char *old_name = "evil_test_link.dat";
78 const char *new_name = "evil_test_link.lnk";
79#endif
80 const char *data = "evil_test_link symlink data\n";
81 FILE *f;
82 ssize_t s1;
83 size_t s2;
84 int l;
85
86 if (!test_link_test_file_create(old_name, data))
87 return 0;
88
89 if (symlink(old_name, new_name) < 0)
90 return 0;
91
92 if ((s1 = readlink(new_name, buf, 1023)) < 0)
93 {
94 unlink(old_name);
95 unlink(new_name);
96 return 0;
97 }
98
99 buf[s1] = '\0';
100
101 f = fopen(buf, "rb");
102 if (!f)
103 {
104 unlink(old_name);
105 unlink(new_name);
106 return 0;
107 }
108
109 l = strlen(data);
110 s2 = fread(buf, 1, l + 1, f);
111
112 if ((int)s2 != (l + 1))
113 {
114 fclose(f);
115 unlink(old_name);
116 unlink(new_name);
117 return 0;
118 }
119
120 if (strcmp(buf, data))
121 {
122 fclose(f);
123 unlink(old_name);
124 unlink(new_name);
125 return 0;
126 }
127
128 fclose(f);
129
130 if (unlink(new_name) < 0)
131 {
132 unlink(old_name);
133 return 0;
134 }
135
136 if (unlink(old_name) < 0)
137 return 0;
138
139 return 1;
140}
141
142static int
143test_link_tests_run(suite *s __UNUSED__)
144{
145 int res;
146
147 res = test_link_test_symlink();
148 res &= test_link_test_readlink();
149
150 return res;
151}
152
153int
154test_link(suite *s)
155{
156
157 return test_link_tests_run(s);
158}
diff --git a/src/bin/evil/evil_test_link.h b/src/bin/evil/evil_test_link.h
new file mode 100644
index 0000000000..6f8bfa2328
--- /dev/null
+++ b/src/bin/evil/evil_test_link.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_LINK_H__
2#define __EVIL_TEST_LINK_H__
3
4
5int test_link(suite *s);
6
7
8#endif /* __EVIL_TEST_LINK_H__ */
diff --git a/src/bin/evil/evil_test_memcpy.c b/src/bin/evil/evil_test_memcpy.c
new file mode 100644
index 0000000000..0adfe373f0
--- /dev/null
+++ b/src/bin/evil/evil_test_memcpy.c
@@ -0,0 +1,145 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#undef WIN32_LEAN_AND_MEAN
11
12#include "evil_suite.h"
13#include "evil_test_memcpy.h"
14
15
16typedef void *(*memcpy_decl)(void *dest, const void *src, size_t n);
17
18void *memcpy_glibc(void *dest, const void *src, size_t n);
19
20
21static unsigned char *buf1 = NULL;
22static unsigned char *buf2 = NULL;
23static size_t page_size = 0;
24
25
26#if defined (__MINGW32CE__) || defined (_MSC_VER)
27static int
28getpagesize()
29{
30 return 1024;
31}
32#endif /* __MINGW32CE__ || _MSC_VER */
33
34
35static void
36test_memcpy_test_run(suite *s, memcpy_decl fct, char *dst, const char *src, size_t len)
37{
38 double best;
39 int i;
40
41 best = 1000000000.0;
42
43 for (i = 0; i < 128; ++i)
44 {
45 double time;
46
47 suite_time_start(s);
48 fct(dst, src, len);
49 suite_time_stop(s);
50 time = suite_time_get(s);
51 if (time < best) best = time;
52 }
53
54 printf (" %e", best);
55}
56
57static void
58test_memcpy_tests_run(suite *s, size_t align1, size_t align2, size_t len)
59{
60 size_t i, j;
61 char *s1, *s2;
62
63 printf ("running test..\n");
64
65/* align1 &= 63; */
66/* if (align1 + len >= page_size) */
67/* return; */
68
69/* align2 &= 63; */
70/* if (align2 + len >= page_size) */
71/* return; */
72
73 s1 = (char *) (buf1 + align1);
74 s2 = (char *) (buf2 + align2);
75
76 for (i = 0, j = 1; i < len; i++, j += 23)
77 s1[i] = j;
78
79 printf ("length: %6d, align %2d/%2d:", (int)len, align1, align2);
80
81 test_memcpy_test_run(s, memcpy, s2, s1, len);
82#ifdef _WIN32_WCE
83 test_memcpy_test_run(s, memcpy_glibc, s2, s1, len);
84#endif /* _WIN32_WCE */
85
86 printf ("\n");
87}
88
89int
90test_memcpy(suite *s)
91{
92 size_t i;
93
94 page_size = 2 * 1024;
95
96 buf1 = (unsigned char *)malloc(16 * getpagesize());
97 if (!buf1) return 0;
98
99 buf2 = (unsigned char *)malloc(16 * getpagesize());
100 if (!buf2)
101 {
102 free(buf1);
103 return 0;
104 }
105
106 memset (buf1, 0xa5, page_size);
107 memset (buf2, 0x5a, page_size);
108
109 for (i = 0; i < 5; ++i)
110 {
111 test_memcpy_tests_run(s, 0, 0, 1 << i);
112 test_memcpy_tests_run(s, i, 0, 1 << i);
113 test_memcpy_tests_run(s, 0, i, 1 << i);
114 test_memcpy_tests_run(s, i, i, 1 << i);
115 }
116
117 for (i = 0; i < 32; ++i)
118 {
119 test_memcpy_tests_run(s, 0, 0, i);
120 test_memcpy_tests_run(s, i, 0, i);
121 test_memcpy_tests_run(s, 0, i, i);
122 test_memcpy_tests_run(s, i, i, i);
123 }
124
125 for (i = 3; i < 32; ++i)
126 {
127 if ((i & (i - 1)) == 0)
128 continue;
129 test_memcpy_tests_run(s, 0, 0, 16 * i);
130 test_memcpy_tests_run(s, i, 0, 16 * i);
131 test_memcpy_tests_run(s, 0, i, 16 * i);
132 test_memcpy_tests_run(s, i, i, 16 * i);
133 }
134
135 test_memcpy_tests_run(s, 0, 0, getpagesize ());
136 test_memcpy_tests_run(s, 0, 0, 2 * getpagesize ());
137 test_memcpy_tests_run(s, 0, 0, 4 * getpagesize ());
138 test_memcpy_tests_run(s, 0, 0, 8 * getpagesize ());
139 test_memcpy_tests_run(s, 0, 0, 16 * getpagesize ());
140
141 free(buf2);
142 free(buf1);
143
144 return 1;
145}
diff --git a/src/bin/evil/evil_test_memcpy.h b/src/bin/evil/evil_test_memcpy.h
new file mode 100644
index 0000000000..808dd09f37
--- /dev/null
+++ b/src/bin/evil/evil_test_memcpy.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_MEMCPY__
2#define __EVIL_TEST_MEMCPY__
3
4
5int test_memcpy(suite *s);
6
7
8#endif /* __EVIL_TEST_MEMCPY__ */
diff --git a/src/bin/evil/evil_test_mkstemp.c b/src/bin/evil/evil_test_mkstemp.c
new file mode 100644
index 0000000000..dc8c4e64f5
--- /dev/null
+++ b/src/bin/evil/evil_test_mkstemp.c
@@ -0,0 +1,53 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_mkstemp.h"
11
12
13static int
14test_mkstemp_test(void)
15{
16 char _template[PATH_MAX];
17#ifdef _WIN32_WCE
18 char cwd[PATH_MAX];
19#endif
20 int fd;
21
22#ifdef _WIN32_WCE
23 if (!getcwd(cwd, PATH_MAX))
24 return 0;
25 _snprintf(_template, PATH_MAX, "%s\\%s", cwd, "file_XXXXXX");
26#else
27 _snprintf(_template, PATH_MAX, "%s", "file_XXXXXX");
28#endif
29
30 fd = mkstemp(_template);
31
32 if (fd < 0)
33 return 0;
34
35 return 1;
36}
37
38static int
39test_mkstemp_run(suite *s __UNUSED__)
40{
41 int res;
42
43 res = test_mkstemp_test();
44
45 return res;
46}
47
48int
49test_mkstemp(suite *s)
50{
51
52 return test_mkstemp_run(s);
53}
diff --git a/src/bin/evil/evil_test_mkstemp.h b/src/bin/evil/evil_test_mkstemp.h
new file mode 100644
index 0000000000..f5bb0c4270
--- /dev/null
+++ b/src/bin/evil/evil_test_mkstemp.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_MKSTEMP_H__
2#define __EVIL_TEST_MKSTEMP_H__
3
4
5int test_mkstemp(suite *s);
6
7
8#endif /* __EVIL_TEST_MKSTEMP_H__ */
diff --git a/src/bin/evil/evil_test_pipe.c b/src/bin/evil/evil_test_pipe.c
new file mode 100644
index 0000000000..2fc530d545
--- /dev/null
+++ b/src/bin/evil/evil_test_pipe.c
@@ -0,0 +1,126 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8# define WIN32_LEAN_AND_MEAN
9# include <winsock2.h>
10# undef WIN32_LEAN_AND_MEAN
11
12#include <Evil.h>
13
14#include "evil_suite.h"
15#include "evil_test_pipe.h"
16
17
18#define FDREAD 0
19#define FDWRITE 1
20
21typedef struct
22{
23 int val;
24 int fd_write;
25} data;
26
27
28static DWORD WINAPI
29thread (void *param)
30{
31 data *d;
32 void *buf[1];
33
34 Sleep (2 * 1000);
35 d = (data *)param;
36 buf[0] = d;
37 send(d->fd_write, (char *)buf, sizeof(buf), 0);
38
39 return 0;
40}
41
42static int
43test_pipe_test(void)
44{
45 int sockets[2];
46 struct timeval t;
47 fd_set rfds;
48 int ret;
49 data *d;
50 DWORD thread_id;
51 HANDLE h;
52
53 FD_ZERO(&rfds);
54
55 t.tv_sec = 5;
56 t.tv_usec = 0;
57
58 if (pipe(sockets) < 0)
59 return 0;
60
61 FD_SET(sockets[FDREAD], &rfds);
62 fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK);
63
64 d = (data *)malloc(sizeof (data));
65 if (!d)
66 return 0;
67
68 d->val = 14;
69 d->fd_write = sockets[FDWRITE];
70
71 h = CreateThread(NULL, 0, thread, d, 0, &thread_id);
72 if (!h)
73
74 ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
75
76 if (ret < 0)
77 goto free_d;
78 else if (ret == 0)
79 goto close_h;
80 else /* ret > 0 */
81 {
82 void *buf[1];
83 data *d2 = NULL;
84 int len;
85
86 while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
87 {
88 if (len == sizeof(buf))
89 {
90 d2 = (data *)buf[0];
91 break;
92 }
93 }
94 if (d2 && (d2->val == d->val))
95 ret = 1;
96 else
97 ret = 0;
98 }
99
100 CloseHandle(h);
101 free(d);
102
103 return ret;
104
105 close_h:
106 CloseHandle(h);
107 free_d:
108 free(d);
109 return 0;
110}
111
112static int
113test_pipe_run(suite *s __UNUSED__)
114{
115 int res;
116
117 res = test_pipe_test();
118
119 return res;
120}
121
122int
123test_pipe(suite *s)
124{
125 return test_pipe_run(s);
126}
diff --git a/src/bin/evil/evil_test_pipe.h b/src/bin/evil/evil_test_pipe.h
new file mode 100644
index 0000000000..ff8041f716
--- /dev/null
+++ b/src/bin/evil/evil_test_pipe.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_PIPE_H__
2#define __EVIL_TEST_PIPE_H__
3
4
5int test_pipe(suite *s);
6
7
8#endif /* __EVIL_TEST_PIPE_H__ */
diff --git a/src/bin/evil/evil_test_print.c b/src/bin/evil/evil_test_print.c
new file mode 100644
index 0000000000..b930a538f4
--- /dev/null
+++ b/src/bin/evil/evil_test_print.c
@@ -0,0 +1,46 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include <Evil.h>
9
10#include "evil_suite.h"
11#include "evil_test_print.h"
12
13static int
14test_print_test(void)
15{
16 char buf[16];
17 int i1 = 1;
18 size_t i2 = 123456;
19 int res;
20
21 res = printf("%02hhd\n", i1);
22 if (res != 3)
23 return 0;
24
25 res = snprintf(buf, sizeof(buf), "%zu", i2);
26 if (res != 6)
27 return 0;
28
29 return 1;
30}
31
32static int
33test_print_run(suite *s __UNUSED__)
34{
35 int res;
36
37 res = test_print_test();
38
39 return res;
40}
41
42int
43test_print(suite *s)
44{
45 return test_print_run(s);
46}
diff --git a/src/bin/evil/evil_test_print.h b/src/bin/evil/evil_test_print.h
new file mode 100644
index 0000000000..2bbf43904f
--- /dev/null
+++ b/src/bin/evil/evil_test_print.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_PRINT_H__
2#define __EVIL_TEST_PRINT_H__
3
4
5int test_print(suite *s);
6
7
8#endif /* __EVIL_TEST_PRINT_H__ */
diff --git a/src/bin/evil/evil_test_realpath.c b/src/bin/evil/evil_test_realpath.c
new file mode 100644
index 0000000000..f9a48cb977
--- /dev/null
+++ b/src/bin/evil/evil_test_realpath.c
@@ -0,0 +1,44 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_realpath.h"
11
12
13static int
14test_realpath_test(void)
15{
16 char buf[PATH_MAX];
17 char *filename;
18 char *result;
19
20 filename = "evil_suite.exe";
21
22 if (!(result = realpath(filename, buf)))
23 return 0;
24
25 printf ("res : %s\n", buf);
26
27 return 1;
28}
29
30static int
31test_realpath_run(suite *s __UNUSED__)
32{
33 int res;
34
35 res = test_realpath_test();
36
37 return res;
38}
39
40int
41test_realpath(suite *s)
42{
43 return test_realpath_run(s);
44}
diff --git a/src/bin/evil/evil_test_realpath.h b/src/bin/evil/evil_test_realpath.h
new file mode 100644
index 0000000000..0205aad149
--- /dev/null
+++ b/src/bin/evil/evil_test_realpath.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_REALPATH_H__
2#define __EVIL_TEST_REALPATH_H__
3
4
5int test_realpath(suite *s);
6
7
8#endif /* __EVIL_TEST_REALPATH_H__ */
diff --git a/src/bin/evil/evil_test_util.c b/src/bin/evil/evil_test_util.c
new file mode 100644
index 0000000000..6226ceb040
--- /dev/null
+++ b/src/bin/evil/evil_test_util.c
@@ -0,0 +1,110 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_util.h"
11
12
13static int test_path_absolute_test_1(void)
14{
15 char *path;
16 int result;
17
18 path = NULL;
19 result = evil_path_is_absolute(path);
20 if (result != 0)
21 return 0;
22
23 return 1;
24}
25
26static int test_path_absolute_test_2(void)
27{
28 char *path;
29 int result;
30
31 path = "1";
32 result = evil_path_is_absolute(path);
33 if (result != 0)
34 return 0;
35
36 return 1;
37}
38
39static int test_path_absolute_test_3(void)
40{
41 char *path;
42 int result;
43
44 path = "1:\\";
45 result = evil_path_is_absolute(path);
46 if (result != 0)
47 return 0;
48
49 return 1;
50}
51
52static int test_path_absolute_test_4(void)
53{
54 char *path;
55 int result;
56
57 path = "1/\\";
58 result = evil_path_is_absolute(path);
59 if (result != 0)
60 return 0;
61
62 return 1;
63}
64
65static int test_path_absolute_test_5(void)
66{
67 char *path;
68 int result;
69
70 path = "F:/foo";
71 result = evil_path_is_absolute(path);
72 if (result == 0)
73 return 0;
74
75 return 1;
76}
77
78static int test_path_absolute_test_6(void)
79{
80 char *path;
81 int result;
82
83 path = "C:\\foo";
84 result = evil_path_is_absolute(path);
85 if (result == 0)
86 return 0;
87
88 return 1;
89}
90
91static int
92test_path_absolute_run(suite *s __UNUSED__)
93{
94 int res;
95
96 res = test_path_absolute_test_1();
97 res &= test_path_absolute_test_2();
98 res &= test_path_absolute_test_3();
99 res &= test_path_absolute_test_4();
100 res &= test_path_absolute_test_5();
101 res &= test_path_absolute_test_6();
102
103 return res;
104}
105
106int
107test_util(suite *s)
108{
109 return test_path_absolute_run(s);
110}
diff --git a/src/bin/evil/evil_test_util.h b/src/bin/evil/evil_test_util.h
new file mode 100644
index 0000000000..bee5c7a164
--- /dev/null
+++ b/src/bin/evil/evil_test_util.h
@@ -0,0 +1,8 @@
1#ifndef __EVIL_TEST_UTIL_H__
2#define __EVIL_TEST_UTIL_H__
3
4
5int test_util(suite *s);
6
7
8#endif /* __EVIL_TEST_UTIL_H__ */
diff --git a/src/bin/evil/memcpy_glibc_arm.S b/src/bin/evil/memcpy_glibc_arm.S
new file mode 100644
index 0000000000..7c42898647
--- /dev/null
+++ b/src/bin/evil/memcpy_glibc_arm.S
@@ -0,0 +1,231 @@
1/* Copyright (C) 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 Contributed by MontaVista Software, Inc. (written by Nicolas Pitre)
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21/* Copyright (C) 2008 Vincent Torri
22 modification of the name and of the entry / end declaration
23 */
24
25/*
26 * Data preload for architectures that support it (ARM V5TE and above)
27 */
28#if (!defined (__ARM_ARCH_2__) && !defined (__ARM_ARCH_3__) \
29 && !defined (__ARM_ARCH_3M__) && !defined (__ARM_ARCH_4__) \
30 && !defined (__ARM_ARCH_4T__) && !defined (__ARM_ARCH_5__) \
31 && !defined (__ARM_ARCH_5T__))
32#define PLD(code...) code
33#else
34#define PLD(code...)
35#endif
36
37/*
38 * This can be used to enable code to cacheline align the source pointer.
39 * Experiments on tested architectures (StrongARM and XScale) didn't show
40 * this a worthwhile thing to do. That might be different in the future.
41 */
42//#define CALGN(code...) code
43#define CALGN(code...)
44
45/*
46 * Endian independent macros for shifting bytes within registers.
47 */
48#ifndef __ARMEB__
49#define pull lsr
50#define push lsl
51#else
52#define pull lsl
53#define push lsr
54#endif
55
56 .text
57
58/* Prototype: void *memcpy_glibc(void *dest, const void *src, size_t n); */
59
60 .align
61 .global memcpy_glibc
62 .func memcpy_glibc
63memcpy_glibc:
64
65 stmfd sp!, {r0, r4, lr}
66
67 subs r2, r2, #4
68 blt 8f
69 ands ip, r0, #3
70 PLD( pld [r1, #0] )
71 bne 9f
72 ands ip, r1, #3
73 bne 10f
74
751: subs r2, r2, #(28)
76 stmfd sp!, {r5 - r8}
77 blt 5f
78
79 CALGN( ands ip, r1, #31 )
80 CALGN( rsb r3, ip, #32 )
81 CALGN( sbcnes r4, r3, r2 ) @ C is always set here
82 CALGN( bcs 2f )
83 CALGN( adr r4, 6f )
84 CALGN( subs r2, r2, r3 ) @ C gets set
85 CALGN( add pc, r4, ip )
86
87 PLD( pld [r1, #0] )
882: PLD( subs r2, r2, #96 )
89 PLD( pld [r1, #28] )
90 PLD( blt 4f )
91 PLD( pld [r1, #60] )
92 PLD( pld [r1, #92] )
93
943: PLD( pld [r1, #124] )
954: ldmia r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
96 subs r2, r2, #32
97 stmia r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
98 bge 3b
99 PLD( cmn r2, #96 )
100 PLD( bge 4b )
101
1025: ands ip, r2, #28
103 rsb ip, ip, #32
104 addne pc, pc, ip @ C is always clear here
105 b 7f
1066: nop
107 ldr r3, [r1], #4
108 ldr r4, [r1], #4
109 ldr r5, [r1], #4
110 ldr r6, [r1], #4
111 ldr r7, [r1], #4
112 ldr r8, [r1], #4
113 ldr lr, [r1], #4
114
115 add pc, pc, ip
116 nop
117 nop
118 str r3, [r0], #4
119 str r4, [r0], #4
120 str r5, [r0], #4
121 str r6, [r0], #4
122 str r7, [r0], #4
123 str r8, [r0], #4
124 str lr, [r0], #4
125
126 CALGN( bcs 2b )
127
1287: ldmfd sp!, {r5 - r8}
129
1308: movs r2, r2, lsl #31
131 ldrneb r3, [r1], #1
132 ldrcsb r4, [r1], #1
133 ldrcsb ip, [r1]
134 strneb r3, [r0], #1
135 strcsb r4, [r0], #1
136 strcsb ip, [r0]
137
138 ldmfd sp!, {r0, r4, pc}
139
1409: rsb ip, ip, #4
141 cmp ip, #2
142 ldrgtb r3, [r1], #1
143 ldrgeb r4, [r1], #1
144 ldrb lr, [r1], #1
145 strgtb r3, [r0], #1
146 strgeb r4, [r0], #1
147 subs r2, r2, ip
148 strb lr, [r0], #1
149 blt 8b
150 ands ip, r1, #3
151 beq 1b
152
15310: bic r1, r1, #3
154 cmp ip, #2
155 ldr lr, [r1], #4
156 beq 17f
157 bgt 18f
158
159
160 .macro forward_copy_shift pull push
161
162 subs r2, r2, #28
163 blt 14f
164
165 CALGN( ands ip, r1, #31 )
166 CALGN( rsb ip, ip, #32 )
167 CALGN( sbcnes r4, ip, r2 ) @ C is always set here
168 CALGN( subcc r2, r2, ip )
169 CALGN( bcc 15f )
170
17111: stmfd sp!, {r5 - r9}
172
173 PLD( pld [r1, #0] )
174 PLD( subs r2, r2, #96 )
175 PLD( pld [r1, #28] )
176 PLD( blt 13f )
177 PLD( pld [r1, #60] )
178 PLD( pld [r1, #92] )
179
18012: PLD( pld [r1, #124] )
18113: ldmia r1!, {r4, r5, r6, r7}
182 mov r3, lr, pull #\pull
183 subs r2, r2, #32
184 ldmia r1!, {r8, r9, ip, lr}
185 orr r3, r3, r4, push #\push
186 mov r4, r4, pull #\pull
187 orr r4, r4, r5, push #\push
188 mov r5, r5, pull #\pull
189 orr r5, r5, r6, push #\push
190 mov r6, r6, pull #\pull
191 orr r6, r6, r7, push #\push
192 mov r7, r7, pull #\pull
193 orr r7, r7, r8, push #\push
194 mov r8, r8, pull #\pull
195 orr r8, r8, r9, push #\push
196 mov r9, r9, pull #\pull
197 orr r9, r9, ip, push #\push
198 mov ip, ip, pull #\pull
199 orr ip, ip, lr, push #\push
200 stmia r0!, {r3, r4, r5, r6, r7, r8, r9, ip}
201 bge 12b
202 PLD( cmn r2, #96 )
203 PLD( bge 13b )
204
205 ldmfd sp!, {r5 - r9}
206
20714: ands ip, r2, #28
208 beq 16f
209
21015: mov r3, lr, pull #\pull
211 ldr lr, [r1], #4
212 subs ip, ip, #4
213 orr r3, r3, lr, push #\push
214 str r3, [r0], #4
215 bgt 15b
216 CALGN( cmp r2, #0 )
217 CALGN( bge 11b )
218
21916: sub r1, r1, #(\push / 8)
220 b 8b
221
222 .endm
223
224
225 forward_copy_shift pull=8 push=24
226
22717: forward_copy_shift pull=16 push=16
228
22918: forward_copy_shift pull=24 push=8
230
231.endfunc
diff --git a/src/bin/evil/memcpy_glibc_i686.S b/src/bin/evil/memcpy_glibc_i686.S
new file mode 100755
index 0000000000..72da118cf0
--- /dev/null
+++ b/src/bin/evil/memcpy_glibc_i686.S
@@ -0,0 +1,81 @@
1/* Copy memory block and return pointer to beginning of destination block
2 For Intel 80x86, x>=6.
3 This file is part of the GNU C Library.
4 Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
21
22# define CHECK_BOUNDS_BOTH_WIDE(VAL_REG, BP_MEM, LENGTH) \
23 CHECK_BOUNDS_LOW(VAL_REG, BP_MEM); \
24 addl LENGTH, VAL_REG; \
25 cmpl 8+BP_MEM, VAL_REG; \
26 jbe 0f; /* continue if value <= high */ \
27 BOUNDS_VIOLATED; \
28 0: subl LENGTH, VAL_REG /* restore value */
29
30# define RETURN_BOUNDED_POINTER(BP_MEM) \
31 movl RTN(%esp), %edx; \
32 movl %eax, 0(%edx); \
33 movl 4+BP_MEM, %eax; \
34 movl %eax, 4(%edx); \
35 movl 8+BP_MEM, %eax; \
36 movl %eax, 8(%edx)
37
38#define PTR_SIZE 12
39#define RTN_SIZE 4
40#define LINKAGE 8
41
42#define PARMS LINKAGE /* no space for saved regs */
43#define RTN PARMS
44#define DEST RTN+RTN_SIZE
45#define SRC DEST+PTR_SIZE
46#define LEN SRC+PTR_SIZE
47
48 .text
49
50 .align
51 .global memcpy_glibc
52 .func memcpy_glibc
53memcpy_glibc:
54
55 pushl %ebp
56 movl %esp, %ebp
57
58 movl LEN(%esp), %ecx
59 movl %edi, %eax
60 movl DEST(%esp), %edi
61 movl %esi, %edx
62 movl SRC(%esp), %esi
63
64 cld
65 shrl $1, %ecx
66 jnc 1f
67 movsb
681: shrl $1, %ecx
69 jnc 2f
70 movsw
712: rep
72 movsl
73 movl %eax, %edi
74 movl %edx, %esi
75 movl DEST(%esp), %eax
76 RETURN_BOUNDED_POINTER (DEST(%esp))
77
78 movl %ebp, %esp
79 popl %ebp
80
81.endfunc
diff --git a/src/bin/evil/test_evil.c b/src/bin/evil/test_evil.c
new file mode 100644
index 0000000000..5b91172cb3
--- /dev/null
+++ b/src/bin/evil/test_evil.c
@@ -0,0 +1,27 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <sys/time.h>
4
5#include <windows.h>
6
7
8
9int
10main()
11{
12 struct timeval tv;
13 double t1 = 0.0;
14 double t2 = 0.0;
15
16 if (gettimeofday(&tv, NULL) == 0)
17 t1 = tv.tv_sec + tv.tv_usec / 1000000.0;
18
19 Sleep(3000);
20
21 if (gettimeofday(&tv, NULL) == 0)
22 t2 = tv.tv_sec + tv.tv_usec / 1000000.0;
23
24 printf ("3 seconds ? %f\n", t2 - t1);
25
26 return EXIT_SUCCESS;
27}