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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
//===-- stubs.c -----------------------------------------------------------===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifdef __FreeBSD__
#include "FreeBSD.h"
#endif
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#ifndef __FreeBSD__
#include <utmp.h>
#endif
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "klee/Config/config.h"
void klee_warning(const char*);
void klee_warning_once(const char*);
/* Silent ignore */
int __syscall_rt_sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact, size_t _something)
__attribute__((weak));
int __syscall_rt_sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact, size_t _something) {
klee_warning_once("silently ignoring");
return 0;
}
int sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact) __attribute__((weak));
int sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact) {
klee_warning_once("silently ignoring");
return 0;
}
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
__attribute__((weak));
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
klee_warning_once("silently ignoring");
return 0;
}
/* Not even worth warning about these */
int fdatasync(int fd) __attribute__((weak));
int fdatasync(int fd) {
return 0;
}
/* Not even worth warning about this */
void sync(void) __attribute__((weak));
void sync(void) {
}
/* Error ignore */
extern int __fgetc_unlocked(FILE *f);
extern int __fputc_unlocked(int c, FILE *f);
int __socketcall(int type, int *args) __attribute__((weak));
int __socketcall(int type, int *args) {
klee_warning("ignoring (EAFNOSUPPORT)");
errno = EAFNOSUPPORT;
return -1;
}
int _IO_getc(FILE *f) __attribute__((weak));
int _IO_getc(FILE *f) {
return __fgetc_unlocked(f);
}
int _IO_putc(int c, FILE *f) __attribute__((weak));
int _IO_putc(int c, FILE *f) {
return __fputc_unlocked(c, f);
}
int mkdir(const char *pathname, mode_t mode) __attribute__((weak));
int mkdir(const char *pathname, mode_t mode) {
klee_warning("ignoring (EIO)");
errno = EIO;
return -1;
}
int mkfifo(const char *pathname, mode_t mode) __attribute__((weak));
int mkfifo(const char *pathname, mode_t mode) {
klee_warning("ignoring (EIO)");
errno = EIO;
return -1;
}
int mknod(const char *pathname, mode_t mode, dev_t dev) __attribute__((weak));
int mknod(const char *pathname, mode_t mode, dev_t dev) {
klee_warning("ignoring (EIO)");
errno = EIO;
return -1;
}
int pipe(int filedes[2]) __attribute__((weak));
int pipe(int filedes[2]) {
klee_warning("ignoring (ENFILE)");
errno = ENFILE;
return -1;
}
int link(const char *oldpath, const char *newpath) __attribute__((weak));
int link(const char *oldpath, const char *newpath) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int symlink(const char *oldpath, const char *newpath) __attribute__((weak));
int symlink(const char *oldpath, const char *newpath) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int rename(const char *oldpath, const char *newpath) __attribute__((weak));
int rename(const char *oldpath, const char *newpath) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int nanosleep(const struct timespec *req, struct timespec *rem) __attribute__((weak));
int nanosleep(const struct timespec *req, struct timespec *rem) {
return 0;
}
/* XXX why can't I call this internally? */
int clock_gettime(clockid_t clk_id, struct timespec *res) __attribute__((weak));
int clock_gettime(clockid_t clk_id, struct timespec *res) {
/* Fake */
struct timeval tv;
gettimeofday(&tv, NULL);
res->tv_sec = tv.tv_sec;
res->tv_nsec = tv.tv_usec * 1000;
return 0;
}
int clock_settime(clockid_t clk_id, const struct timespec *res) __attribute__((weak));
int clock_settime(clockid_t clk_id, const struct timespec *res) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
time_t time(time_t *t) {
struct timeval tv;
gettimeofday(&tv, NULL);
if (t)
*t = tv.tv_sec;
return tv.tv_sec;
}
clock_t times(struct tms *buf) {
/* Fake */
if (!buf)
klee_warning("returning 0\n");
else {
klee_warning("setting all times to 0 and returning 0\n");
buf->tms_utime = 0;
buf->tms_stime = 0;
buf->tms_cutime = 0;
buf->tms_cstime = 0;
}
return 0;
}
#ifndef __FreeBSD__
struct utmpx *getutxent(void) __attribute__((weak));
struct utmpx *getutxent(void) {
return (struct utmpx*) getutent();
}
void setutxent(void) __attribute__((weak));
void setutxent(void) {
setutent();
}
void endutxent(void) __attribute__((weak));
void endutxent(void) {
endutent();
}
int utmpxname(const char *file) __attribute__((weak));
int utmpxname(const char *file) {
utmpname(file);
return 0;
}
#endif
int euidaccess(const char *pathname, int mode) __attribute__((weak));
int euidaccess(const char *pathname, int mode) {
return access(pathname, mode);
}
int eaccess(const char *pathname, int mode) __attribute__((weak));
int eaccess(const char *pathname, int mode) {
return euidaccess(pathname, mode);
}
int group_member (gid_t __gid) __attribute__((weak));
int group_member (gid_t __gid) {
return ((__gid == getgid ()) || (__gid == getegid ()));
}
int utime(const char *filename, const struct utimbuf *buf) __attribute__((weak));
int utime(const char *filename, const struct utimbuf *buf) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int futimes(int fd, const struct timeval times[2]) __attribute__((weak));
int futimes(int fd, const struct timeval times[2]) {
klee_warning("ignoring (EBADF)");
errno = EBADF;
return -1;
}
int strverscmp (__const char *__s1, __const char *__s2) {
return strcmp(__s1, __s2); /* XXX no doubt this is bad */
}
#if __GLIBC_PREREQ(2, 25)
#define gnu_dev_type dev_t
#else
#define gnu_dev_type unsigned long long int
#endif
unsigned int gnu_dev_major(gnu_dev_type __dev) __attribute__((weak));
unsigned int gnu_dev_major(gnu_dev_type __dev) {
return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
}
unsigned int gnu_dev_minor(gnu_dev_type __dev) __attribute__((weak));
unsigned int gnu_dev_minor(gnu_dev_type __dev) {
return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
}
gnu_dev_type gnu_dev_makedev(unsigned int __major, unsigned int __minor) __attribute__((weak));
gnu_dev_type gnu_dev_makedev(unsigned int __major, unsigned int __minor) {
return ((__minor & 0xff) | ((__major & 0xfff) << 8)
| (((gnu_dev_type) (__minor & ~0xff)) << 12)
| (((gnu_dev_type) (__major & ~0xfff)) << 32));
}
char *canonicalize_file_name (const char *name) __attribute__((weak));
char *canonicalize_file_name (const char *name) {
// Although many C libraries allocate resolved_name in realpath() if it is NULL,
// this behaviour is implementation-defined (POSIX) and not implemented in uclibc.
char * resolved_name = malloc(PATH_MAX);
if (!resolved_name) return NULL;
if (!realpath(name, resolved_name)) {
free(resolved_name);
return NULL;
}
return resolved_name;
}
int getloadavg(double loadavg[], int nelem) __attribute__((weak));
int getloadavg(double loadavg[], int nelem) {
klee_warning("ignoring (-1 result)");
return -1;
}
pid_t wait(int *status) __attribute__((weak));
pid_t wait(int *status) {
klee_warning("ignoring (ECHILD)");
errno = ECHILD;
return -1;
}
pid_t wait3(int *status, int options, struct rusage *rusage) __attribute__((weak));
pid_t wait3(int *status, int options, struct rusage *rusage) {
klee_warning("ignoring (ECHILD)");
errno = ECHILD;
return -1;
}
pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) __attribute__((weak));
pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) {
klee_warning("ignoring (ECHILD)");
errno = ECHILD;
return -1;
}
pid_t waitpid(pid_t pid, int *status, int options) __attribute__((weak));
pid_t waitpid(pid_t pid, int *status, int options) {
klee_warning("ignoring (ECHILD)");
errno = ECHILD;
return -1;
}
pid_t waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) __attribute__((weak));
pid_t waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
klee_warning("ignoring (ECHILD)");
errno = ECHILD;
return -1;
}
/* ACL */
/* FIXME: We need autoconf magic for this. */
#ifdef HAVE_SYS_ACL_H
#include <sys/acl.h>
int acl_delete_def_file(const char *path_p) __attribute__((weak));
int acl_delete_def_file(const char *path_p) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int acl_extended_file(const char path_p) __attribute__((weak));
int acl_extended_file(const char path_p) {
klee_warning("ignoring (ENOENT)");
errno = ENOENT;
return -1;
}
int acl_entries(acl_t acl) __attribute__((weak));
int acl_entries(acl_t acl) {
klee_warning("ignoring (EINVAL)");
errno = EINVAL;
return -1;
}
acl_t acl_from_mode(mode_t mode) __attribute__((weak));
acl_t acl_from_mode(mode_t mode) {
klee_warning("ignoring (ENOMEM)");
errno = ENOMEM;
return NULL;
}
acl_t acl_get_fd(int fd) __attribute__((weak));
acl_t acl_get_fd(int fd) {
klee_warning("ignoring (ENOMEM)");
errno = ENOMEM;
return NULL;
}
acl_t acl_get_file(const char *pathname, acl_type_t type) __attribute__((weak));
acl_t acl_get_file(const char *pathname, acl_type_t type) {
klee_warning("ignoring (ENONMEM)");
errno = ENOMEM;
return NULL;
}
int acl_set_fd(int fd, acl_t acl) __attribute__((weak));
int acl_set_fd(int fd, acl_t acl) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int acl_set_file(const char *path_p, acl_type_t type, acl_t acl) __attribute__((weak));
int acl_set_file(const char *path_p, acl_type_t type, acl_t acl) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int acl_free(void *obj_p) __attribute__((weak));
int acl_free(void *obj_p) {
klee_warning("ignoring (EINVAL)");
errno = EINVAL;
return -1;
}
#endif
int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data) __attribute__((weak));
int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int umount(const char *target) __attribute__((weak));
int umount(const char *target) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int umount2(const char *target, int flags) __attribute__((weak));
int umount2(const char *target, int flags) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int swapon(const char *path, int swapflags) __attribute__((weak));
int swapon(const char *path, int swapflags) {
#else
int swapon(const char *path) __attribute__((weak));
int swapon(const char *path) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int swapoff(const char *path) __attribute__((weak));
int swapoff(const char *path) {
#elif __FreeBSD__ < 13
int swapoff(const char *path) __attribute__((weak));
int swapoff(const char *path) {
#else
int swapoff(const char *path, u_int swapflags) __attribute__((weak));
int swapoff(const char *path, u_int swapflags) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int setgid(gid_t gid) __attribute__((weak));
int setgid(gid_t gid) {
klee_warning("silently ignoring (returning 0)");
return 0;
}
#ifndef __FreeBSD__
int setgroups(size_t size, const gid_t *list) __attribute__((weak));
int setgroups(size_t size, const gid_t *list) {
#else
int setgroups(int size, const gid_t *list) __attribute__((weak));
int setgroups(int size, const gid_t *list) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int sethostname(const char *name, size_t len) __attribute__((weak));
int sethostname(const char *name, size_t len) {
#else
int sethostname(const char *name, int len) __attribute__((weak));
int sethostname(const char *name, int len) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int setpgid(pid_t pid, pid_t pgid) __attribute__((weak));
int setpgid(pid_t pid, pid_t pgid) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int setpgrp(void) __attribute__((weak));
int setpgrp(void) {
#else
int setpgrp(pid_t a, pid_t b) __attribute__((weak));
int setpgrp(pid_t a, pid_t b) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int setpriority(__priority_which_t which, id_t who, int prio) __attribute__((weak));
int setpriority(__priority_which_t which, id_t who, int prio) {
#else
int setpriority(int which, int who, int prio) __attribute__((weak));
int setpriority(int which, int who, int prio) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int setresgid(gid_t rgid, gid_t egid, gid_t sgid) __attribute__((weak));
int setresgid(gid_t rgid, gid_t egid, gid_t sgid) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int setresuid(uid_t ruid, uid_t euid, uid_t suid) __attribute__((weak));
int setresuid(uid_t ruid, uid_t euid, uid_t suid) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim) __attribute__((weak));
int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim) {
#else
int setrlimit(int resource, const struct rlimit *rlp) __attribute__((weak));
int setrlimit(int resource, const struct rlimit *rlp) {
#endif
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#ifndef __FreeBSD__
int setrlimit64(__rlimit_resource_t resource, const struct rlimit64 *rlim) __attribute__((weak));
int setrlimit64(__rlimit_resource_t resource, const struct rlimit64 *rlim) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
#endif
pid_t setsid(void) __attribute__((weak));
pid_t setsid(void) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int settimeofday(const struct timeval *tv, const struct timezone *tz) __attribute__((weak));
int settimeofday(const struct timeval *tv, const struct timezone *tz) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int setuid(uid_t uid) __attribute__((weak));
int setuid(uid_t uid) {
klee_warning("silently ignoring (returning 0)");
return 0;
}
int reboot(int flag) __attribute__((weak));
int reboot(int flag) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int mlock(const void *addr, size_t len) __attribute__((weak));
int mlock(const void *addr, size_t len) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int munlock(const void *addr, size_t len) __attribute__((weak));
int munlock(const void *addr, size_t len) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
int pause(void) __attribute__((weak));
int pause(void) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
ssize_t readahead(int fd, off64_t *offset, size_t count) __attribute__((weak));
ssize_t readahead(int fd, off64_t *offset, size_t count) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) __attribute__((weak));
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return (void*) -1;
}
void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset) __attribute__((weak));
void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return (void*) -1;
}
int munmap(void*start, size_t length) __attribute__((weak));
int munmap(void*start, size_t length) {
klee_warning("ignoring (EPERM)");
errno = EPERM;
return -1;
}
|