Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/warp/warp.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1998-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* time related system call intercept
26
* the env var WARP controls the seconds offset added to each time_t
27
* and the time progression factor
28
*/
29
30
static const char id[] = "\n@(#)$Id: warp (AT&T Research) 2012-06-22 $\0\n";
31
32
#if defined(_SCO_C_DIALECT) || defined(_SCO_ELF) || defined(_SCO_XPG_VERS)
33
#define _NO_STATIC 1
34
#define _WARP_stat32 1
35
#endif
36
37
#if defined(__STDPP__directive) && defined(__STDPP__hide)
38
__STDPP__directive pragma pp:hide alarm _alarm __alarm clock_gettime _clock_gettime __clock_gettime gettimeofday _gettimeofday __gettimeofday getitimer _getitimer __getitimer poll _poll __poll select _select __select setitimer _setitimer __setitimer time times utime _utime __utime utimensat _utimensat __utimensat utimes _utimes __utimes utimets _utimets __utimets fstat64 lstat64
39
__STDPP__directive pragma pp:hide execlp _execlp __execlp execve _execve __execve execvp _execvp __execvp execvpe _execvpe __execvpe
40
#else
41
#define alarm ______alarm
42
#define _alarm _______alarm
43
#define __alarm ________alarm
44
#define clock_gettime ______clock_gettime
45
#define _clock_gettime _______clock_gettime
46
#define __clock_gettime ________clock_gettime
47
#define gettimeofday ______gettimeofday
48
#define _gettimeofday _______gettimeofday
49
#define __gettimeofday ________gettimeofday
50
#define getitimer ______getitimer
51
#define _getitimer _______getitimer
52
#define __getitimer ________getitimer
53
#define poll ______poll
54
#define _poll _______poll
55
#define __poll ________poll
56
#define select ______select
57
#define _select _______select
58
#define __select ________select
59
#define setitimer ______setitimer
60
#define _setitimer _______setitimer
61
#define __setitimer ________setitimer
62
#define time ______time
63
#define times ______times
64
#define utime ______utime
65
#define _utime _______utime
66
#define __utime ________utime
67
#define utimes ______utimes
68
#define _utimes _______utimes
69
#define __utimes ________utimes
70
#define utimensat ______utimensat
71
#define _utimensat _______utimensat
72
#define __utimensat ________utimensat
73
#define utimets ______utimets
74
#define _utimets _______utimets
75
#define __utimets ________utimets
76
#define fstat64 ______fstat64
77
#define lstat64 ______lstat64
78
#define execlp ______execlp
79
#define _execlp _______execlp
80
#define __execlp ________execlp
81
#define execve ______execve
82
#define _execve _______execve
83
#define __execve ________execve
84
#define execvp ______execvp
85
#define _execvp _______execvp
86
#define __execvp ________execvp
87
#define execvpe ______execvpe
88
#define _execvpe _______execvpe
89
#define __execvpe ________execvpe
90
#endif
91
92
#ifdef __EXPORT__
93
#define extern __EXPORT__
94
#include <sys/types.h>
95
#include <sys/stat.h>
96
#include <sys/time.h>
97
#undef extern
98
#endif
99
100
#include <ast.h>
101
#include <dlldefs.h>
102
#include <ls.h>
103
#include <times.h>
104
105
#include "FEATURE/lib"
106
107
#if _hdr_utime
108
#include <utime.h>
109
#else
110
struct utimbuf
111
{
112
time_t actime;
113
time_t modtime;
114
};
115
#endif
116
117
#if !_typ_struct_timespec
118
struct timespec
119
{
120
time_t tv_sec;
121
time_t tv_nsec;
122
};
123
#endif
124
125
#if defined(__STDPP__directive) && defined(__STDPP__hide)
126
__STDPP__directive pragma pp:nohide alarm _alarm __alarm clock_gettime _clock_gettime __clock_gettime gettimeofday _gettimeofday __gettimeofday getitimer _getitimer __getitimer poll _poll __poll select _select __select setitimer _setitimer __setitimer time times utime _utime __utime utimensat _utimensat __utimensat utimes _utimes __utimes utimets _utimets __utimets fstat64 lstat64
127
__STDPP__directive pragma pp:nohide execlp _execlp __execlp execve _execve __execve execvp _execvp __execvp execvpe _execvpe __execvpe
128
#else
129
#undef alarm
130
#undef _alarm
131
#undef __alarm
132
#undef clock_gettime
133
#undef _clock_gettime
134
#undef __clock_gettime
135
#undef gettimeofday
136
#undef _gettimeofday
137
#undef __gettimeofday
138
#undef getitimer
139
#undef _getitimer
140
#undef __getitimer
141
#undef poll
142
#undef _poll
143
#undef __poll
144
#undef select
145
#undef _select
146
#undef __select
147
#undef setitimer
148
#undef _setitimer
149
#undef __setitimer
150
#undef time
151
#undef times
152
#undef utime
153
#undef _utime
154
#undef __utime
155
#undef utimensat
156
#undef _utimensat
157
#undef __utimensat
158
#undef utimes
159
#undef _utimes
160
#undef __utimes
161
#undef fstat64
162
#undef lstat64
163
#undef execlp
164
#undef _execlp
165
#undef __execlp
166
#undef execve
167
#undef _execve
168
#undef __execve
169
#undef execvp
170
#undef _execvp
171
#undef __execvp
172
#undef execvpe
173
#undef _execvpe
174
#undef __execvpe
175
#endif
176
177
#ifdef __EXPORT__
178
#define extern __EXPORT__
179
#endif
180
181
#if defined(LINUX_STAT_VERSION) && !defined(_STAT_VER)
182
#define _STAT_VER LINUX_STAT_VERSION
183
#endif
184
185
#undef fstat
186
#undef lstat
187
#undef stat
188
189
typedef void* (*Syscall_f)(void*);
190
191
typedef unsigned int (*Alarm_f)(unsigned int);
192
typedef int (*Gettimeofday_f)(struct timeval*, void*);
193
typedef int (*Poll_f)(void*, int, int);
194
typedef int (*Select_f)(int, void*, void*, void*, const struct timeval*);
195
typedef time_t (*Time_f)(time_t*);
196
typedef clock_t (*Times_f)(struct tms*);
197
typedef int (*Utime_f)(const char*, const struct utimbuf*);
198
typedef int (*Utimensat_f)(int, const char*, const struct timespec*, int);
199
typedef int (*Utimes_f)(const char*, const struct timeval*);
200
typedef int (*Utimets_f)(const char*, const struct timespec*);
201
202
typedef int (*Close_f)(int);
203
typedef int (*Execlp_f)(const char*, const char*, ...);
204
typedef int (*Execve_f)(const char*, char* const[], char* const[]);
205
typedef int (*Execvp_f)(const char*, char* const[]);
206
typedef int (*Execvpe_f)(const char*, char* const[], char* const[]);
207
208
#if defined(_STAT_VER)
209
typedef int (*Xstat_f)(int, const char*, struct stat*);
210
typedef int (*Fxstat_f)(const int, int, struct stat*);
211
typedef int (*Lxstat_f)(const int, const char*, struct stat*);
212
#if defined(_lib__xstat64) || defined(_lib___xstat64)
213
typedef int (*Xstat64_f)(int, const char*, struct stat64*);
214
typedef int (*Fxstat64_f)(const int, int, struct stat64*);
215
typedef int (*Lxstat64_f)(const int, const char*, struct stat64*);
216
#endif
217
#else
218
typedef int (*Fstat_f)(int, struct stat*);
219
typedef int (*Lstat_f)(const char*, struct stat*);
220
typedef int (*Stat_f)(const char*, struct stat*);
221
#endif
222
223
#if defined(_lib_stat64)
224
typedef int (*Fstat64_f)(int, struct stat64*);
225
typedef int (*Lstat64_f)(const char*, struct stat64*);
226
typedef int (*Stat64_f)(const char*, struct stat64*);
227
#endif
228
229
#if _lib_clock_gettime
230
typedef int (*Clock_gettime_f)(int, struct timespec*);
231
#endif
232
233
#if _lib_getitimer
234
typedef int (*Getitimer_f)(int, struct itimerval*);
235
#endif
236
237
#if _lib_setitimer
238
typedef int (*Setitimer_f)(int, const struct itimerval*, struct itimerval*);
239
#endif
240
241
#define WARP_ABS(t) ((t)+=(t)?(state.warp+(state.factor?mix((t)-state.base):0)):0)
242
#define UNWARP_ABS(t) ((t)=(t)?(((t)-state.warp)/(state.factor+1)+state.base/(state.factor+1)*state.factor):0)
243
244
#define WARP_REL(t) ((t)=(t)?(state.factor?mix(t):(t)):0)
245
#define UNWARP_REL(t) ((t)=(t)?(state.factor?((t)/state.factor):(t)):0)
246
247
typedef struct
248
{
249
const char* name;
250
const char* mangled;
251
Syscall_f call;
252
int warped;
253
unsigned long level;
254
} Call_t;
255
256
static struct
257
{
258
long base;
259
void* dll;
260
long factor;
261
unsigned long level;
262
unsigned long mix;
263
int trace;
264
long warp;
265
char* env[32];
266
} state;
267
268
#ifndef environ
269
extern char** environ;
270
#endif
271
272
/*
273
* synthesize the low order seconds in s
274
* under the influence of a warp factor
275
*/
276
277
static unsigned long
278
mix(unsigned long s)
279
{
280
state.mix = state.mix * 0x63c63cd9L + 0x9c39c33dL;
281
return s * state.factor + state.mix % state.factor;
282
}
283
284
/*
285
* initialize the warp environment
286
* and intercept call p
287
*/
288
289
static void
290
intercept(register Call_t* p)
291
{
292
register int c;
293
register char* s;
294
register long n;
295
register int v;
296
char* o;
297
298
static const char msg[] = "warp: panic: dllnext() failed\n";
299
300
if (p->warped)
301
return;
302
if (!state.dll)
303
{
304
#ifdef __EXPORT__
305
o = getenv("WARP");
306
#else
307
register char** e;
308
register char** p;
309
register char** x;
310
char* t;
311
312
e = environ;
313
if (!e) { s = "warp: AHA: no env\n"; write(2, s, strlen(s)); }
314
p = state.env;
315
x = &state.env[elementsof(state.env) - 1];
316
o = 0;
317
while (s = *e++)
318
{
319
switch (s[0])
320
{
321
case 'L':
322
if (s[1] != 'D' || s[2] != '_' || s[3] != 'P' || s[4] != 'R' || s[5] != 'E' || s[6] != 'L' || s[7] != 'O' || s[8] != 'A' || s[9] != 'D' || s[10] != '=')
323
continue;
324
break;
325
case 'W':
326
if (s[1] != 'A' || s[2] != 'R' || s[3] != 'P' || s[4] != '=')
327
continue;
328
o = s + 5;
329
break;
330
case '_':
331
if (s[1] != 'R' || s[2] != 'L' || s[3] != 'D' || s[4] != '_' && s[4] != 'N')
332
continue;
333
break;
334
default:
335
continue;
336
}
337
if (p >= x)
338
break;
339
if (!(t = malloc(strlen(s) + 1)))
340
{
341
s = "warp: out of space [env]\n";
342
write(2, s, strlen(s));
343
_exit(125);
344
}
345
*p++ = strcpy(t, s);
346
}
347
#endif
348
if (s = o)
349
{
350
v = 'w';
351
for (;;)
352
{
353
switch (*s++)
354
{
355
case 0:
356
break;
357
case ' ':
358
case '\t':
359
case '-':
360
case '+':
361
v = 'w';
362
continue;
363
case '0':
364
case '1':
365
case '2':
366
case '3':
367
case '4':
368
case '5':
369
case '6':
370
case '7':
371
case '8':
372
case '9':
373
s--;
374
c = s > o && *(s - 1) == '-';
375
n = 0;
376
while (*s >= '0' && *s <= '9')
377
n = n * 10 + *s++ - '0';
378
if (n)
379
{
380
if (c)
381
n = -n;
382
switch (v)
383
{
384
case 'b':
385
state.base = n;
386
break;
387
case 'f':
388
state.factor = n;
389
break;
390
case 'w':
391
state.warp = n;
392
break;
393
}
394
v = 'w';
395
}
396
continue;
397
case 't':
398
state.trace = 1;
399
continue;
400
default:
401
v = *(s - 1);
402
continue;
403
}
404
break;
405
}
406
if (state.trace)
407
{
408
write(2, id + 10, strlen(id + 10));
409
write(2, " ", 1);
410
write(2, o, strlen(o));
411
write(2, "\n", 1);
412
}
413
}
414
if (state.factor == 1)
415
state.factor = 0;
416
state.mix = state.base;
417
if (!(state.dll = dllnext(RTLD_LAZY)))
418
{
419
write(2, msg, sizeof(msg) - 1);
420
exit(2);
421
}
422
}
423
if (!p->call && !(p->call = (Syscall_f)dlsym(state.dll, p->mangled)))
424
{
425
write(2, "warp: ", 6);
426
write(2, p->mangled, strlen(p->mangled));
427
write(2, ": cannot intercept\n", 1);
428
exit(2);
429
}
430
if (state.trace)
431
{
432
write(2, "warp: ", 6);
433
write(2, p->mangled, strlen(p->mangled));
434
write(2, "\n", 1);
435
}
436
p->level = ++state.level;
437
}
438
439
static unsigned int
440
warp_alarm(register Call_t* p, unsigned int s)
441
{
442
unsigned int r;
443
444
intercept(p);
445
if (p->warped || !state.factor)
446
return (*(Alarm_f)p->call)(s);
447
UNWARP_REL(s);
448
r = (*(Alarm_f)p->call)(s);
449
if (p->level != state.level)
450
p->warped = 1;
451
else
452
WARP_REL(r);
453
return r;
454
}
455
456
extern unsigned int
457
alarm(unsigned int sec)
458
{
459
static Call_t call = { "alarm", "alarm" };
460
461
return warp_alarm(&call, sec);
462
}
463
464
#ifndef __EXPORT__
465
466
extern unsigned int
467
_alarm(unsigned int sec)
468
{
469
static Call_t call = { "alarm", "_alarm" };
470
471
return warp_alarm(&call, sec);
472
}
473
474
extern unsigned int
475
__alarm(unsigned int sec)
476
{
477
static Call_t call = { "alarm", "__alarm" };
478
479
return warp_alarm(&call, sec);
480
}
481
482
extern unsigned int
483
_libc_alarm(unsigned int sec)
484
{
485
static Call_t call = { "alarm", "_libc_alarm" };
486
487
return warp_alarm(&call, sec);
488
}
489
490
extern unsigned int
491
__libc_alarm(unsigned int sec)
492
{
493
static Call_t call = { "alarm", "__libc_alarm" };
494
495
return warp_alarm(&call, sec);
496
}
497
498
#endif
499
500
static int
501
warp_gettimeofday(register Call_t* p, struct timeval* tv, void* tz)
502
{
503
int r;
504
505
intercept(p);
506
if ((r = (*(Gettimeofday_f)p->call)(tv, tz)) != -1 && !p->warped)
507
{
508
if (p->level != state.level)
509
p->warped = 1;
510
else if (tv)
511
WARP_ABS(tv->tv_sec);
512
}
513
return r;
514
}
515
516
extern int
517
gettimeofday(struct timeval* tv, void* tz)
518
{
519
static Call_t call = { "gettimeofday", "gettimeofday" };
520
521
return warp_gettimeofday(&call, tv, tz);
522
}
523
524
#ifndef __EXPORT__
525
526
extern int
527
_gettimeofday(struct timeval* tv, void* tz)
528
{
529
static Call_t call = { "gettimeofday", "_gettimeofday" };
530
531
return warp_gettimeofday(&call, tv, tz);
532
}
533
534
extern int
535
__gettimeofday(struct timeval* tv, void* tz)
536
{
537
static Call_t call = { "gettimeofday", "__gettimeofday" };
538
539
return warp_gettimeofday(&call, tv, tz);
540
}
541
542
extern int
543
_libc_gettimeofday(struct timeval* tv, void* tz)
544
{
545
static Call_t call = { "gettimeofday", "_libc_gettimeofday" };
546
547
return warp_gettimeofday(&call, tv, tz);
548
}
549
550
extern int
551
__libc_gettimeofday(struct timeval* tv, void* tz)
552
{
553
static Call_t call = { "gettimeofday", "__libc_gettimeofday" };
554
555
return warp_gettimeofday(&call, tv, tz);
556
}
557
558
#endif
559
560
static int
561
warp_poll(register Call_t* p, void* f, int n, int to)
562
{
563
int r;
564
565
intercept(p);
566
if (p->warped || !state.factor || to <= 1000)
567
return (*(Poll_f)p->call)(f, n, to);
568
to /= 1000;
569
UNWARP_REL(to);
570
to *= 1000;
571
if ((r = (*(Poll_f)p->call)(f, n, to)) != -1 && !p->warped && p->level != state.level)
572
p->warped = 1;
573
return r;
574
}
575
576
static int
577
poll(void* f, int n, int to)
578
{
579
static Call_t call = { "poll", "poll" };
580
581
return warp_poll(&call, f, n, to);
582
}
583
584
#ifndef __EXPORT__
585
586
static int
587
_poll(void* f, int n, int to)
588
{
589
static Call_t call = { "poll", "_poll" };
590
591
return warp_poll(&call, f, n, to);
592
}
593
594
static int
595
__poll(void* f, int n, int to)
596
{
597
static Call_t call = { "poll", "__poll" };
598
599
return warp_poll(&call, f, n, to);
600
}
601
602
static int
603
_libc_poll(void* f, int n, int to)
604
{
605
static Call_t call = { "poll", "_libc_poll" };
606
607
return warp_poll(&call, f, n, to);
608
}
609
610
static int
611
__libc_poll(void* f, int n, int to)
612
{
613
static Call_t call = { "poll", "__libc_poll" };
614
615
return warp_poll(&call, f, n, to);
616
}
617
618
#endif
619
620
static int
621
warp_select(register Call_t* p, int n, void* rp, void* wp, void* ep, register const struct timeval* tv)
622
{
623
int r;
624
struct timeval x;
625
626
intercept(p);
627
if (p->warped || !state.factor || !tv || !tv->tv_sec && !tv->tv_usec)
628
return (*(Select_f)p->call)(n, rp, wp, ep, tv);
629
x = *tv;
630
if (x.tv_sec)
631
{
632
UNWARP_REL(x.tv_sec);
633
if (x.tv_sec)
634
x.tv_usec = 0;
635
else if (!(x.tv_usec /= state.factor))
636
x.tv_usec = 10;
637
}
638
if ((r = (*(Select_f)p->call)(n, rp, wp, ep, &x)) != -1 && !p->warped && p->level != state.level)
639
p->warped = 1;
640
return r;
641
}
642
643
static int
644
select(int n, void* rp, void* wp, void* ep, const struct timeval* tv)
645
{
646
static Call_t call = { "select", "select" };
647
648
return warp_select(&call, n, rp, wp, ep, tv);
649
}
650
651
#ifndef __EXPORT__
652
653
static int
654
_select(int n, void* rp, void* wp, void* ep, const struct timeval* tv)
655
{
656
static Call_t call = { "select", "_select" };
657
658
return warp_select(&call, n, rp, wp, ep, tv);
659
}
660
661
static int
662
__select(int n, void* rp, void* wp, void* ep, const struct timeval* tv)
663
{
664
static Call_t call = { "select", "__select" };
665
666
return warp_select(&call, n, rp, wp, ep, tv);
667
}
668
669
static int
670
_libc_select(int n, void* rp, void* wp, void* ep, const struct timeval* tv)
671
{
672
static Call_t call = { "select", "_libc_select" };
673
674
return warp_select(&call, n, rp, wp, ep, tv);
675
}
676
677
static int
678
__libc_select(int n, void* rp, void* wp, void* ep, const struct timeval* tv)
679
{
680
static Call_t call = { "select", "__libc_select" };
681
682
return warp_select(&call, n, rp, wp, ep, tv);
683
}
684
685
#endif
686
687
static time_t
688
warp_time(register Call_t* p, time_t* clock)
689
{
690
time_t t;
691
692
intercept(p);
693
if ((t = (*(Time_f)p->call)(clock)) != (time_t)(-1) && !p->warped)
694
{
695
if (p->level != state.level)
696
p->warped = 1;
697
else
698
{
699
WARP_ABS(t);
700
if (clock)
701
WARP_ABS(*clock);
702
}
703
}
704
return t;
705
}
706
707
extern time_t
708
time(time_t* clock)
709
{
710
static Call_t call = { "time", "time" };
711
712
return warp_time(&call, clock);
713
}
714
715
#ifndef __EXPORT__
716
717
extern time_t
718
_time(time_t* clock)
719
{
720
static Call_t call = { "time", "_time" };
721
722
return warp_time(&call, clock);
723
}
724
725
extern time_t
726
__time(time_t* clock)
727
{
728
static Call_t call = { "time", "__time" };
729
730
return warp_time(&call, clock);
731
}
732
733
extern time_t
734
_libc_time(time_t* clock)
735
{
736
static Call_t call = { "time", "_libc_time" };
737
738
return warp_time(&call, clock);
739
}
740
741
extern time_t
742
__libc_time(time_t* clock)
743
{
744
static Call_t call = { "time", "__libc_time" };
745
746
return warp_time(&call, clock);
747
}
748
749
#endif
750
751
static clock_t
752
warp_times(register Call_t* p, struct tms* tv)
753
{
754
clock_t t;
755
756
intercept(p);
757
if ((t = (*(Times_f)p->call)(tv)) != (clock_t)(-1) && !p->warped)
758
{
759
if (p->level != state.level)
760
p->warped = 1;
761
else
762
WARP_REL(t);
763
}
764
return t;
765
}
766
767
extern clock_t
768
times(struct tms* tv)
769
{
770
static Call_t call = { "times", "times" };
771
772
return warp_times(&call, tv);
773
}
774
775
#ifndef __EXPORT__
776
777
extern clock_t
778
_times(struct tms* tv)
779
{
780
static Call_t call = { "times", "_times" };
781
782
return warp_times(&call, tv);
783
}
784
785
extern clock_t
786
__times(struct tms* tv)
787
{
788
static Call_t call = { "times", "__times" };
789
790
return warp_times(&call, tv);
791
}
792
793
extern clock_t
794
_libc_times(struct tms* tv)
795
{
796
static Call_t call = { "times", "_libc_times" };
797
798
return warp_times(&call, tv);
799
}
800
801
extern clock_t
802
__libc_times(struct tms* tv)
803
{
804
static Call_t call = { "times", "__libc_times" };
805
806
return warp_times(&call, tv);
807
}
808
809
#endif
810
811
static int
812
warp_utime(register Call_t* p, const char* path, const struct utimbuf* tv)
813
{
814
int r;
815
struct utimbuf tb;
816
817
intercept(p);
818
if (!tv || p->warped)
819
return (*(Utime_f)p->call)(path, tv);
820
tb = *tv;
821
UNWARP_ABS(tb.actime);
822
UNWARP_ABS(tb.modtime);
823
r = (*(Utime_f)p->call)(path, &tb);
824
if (p->level != state.level)
825
{
826
p->warped = 1;
827
r = (*(Utime_f)p->call)(path, tv);
828
}
829
return r;
830
}
831
832
extern int
833
utime(const char* path, const struct utimbuf* tv)
834
{
835
static Call_t call = { "utime", "utime" };
836
837
return warp_utime(&call, path, tv);
838
}
839
840
#ifndef __EXPORT__
841
842
extern int
843
_utime(const char* path, const struct utimbuf* tv)
844
{
845
static Call_t call = { "utime", "_utime" };
846
847
return warp_utime(&call, path, tv);
848
}
849
850
extern int
851
__utime(const char* path, const struct utimbuf* tv)
852
{
853
static Call_t call = { "utime", "__utime" };
854
855
return warp_utime(&call, path, tv);
856
}
857
858
extern int
859
_libc_utime(const char* path, const struct utimbuf* tv)
860
{
861
static Call_t call = { "utime", "_libc_utime" };
862
863
return warp_utime(&call, path, tv);
864
}
865
866
extern int
867
__libc_utime(const char* path, const struct utimbuf* tv)
868
{
869
static Call_t call = { "utime", "__libc_utime" };
870
871
return warp_utime(&call, path, tv);
872
}
873
874
#endif
875
876
static int
877
warp_utimensat(int dirfd, register Call_t* p, const char* path, const struct timespec* tv, int flags)
878
{
879
int r;
880
register int i;
881
struct timespec tb[2];
882
883
intercept(p);
884
if (!tv || p->warped)
885
return (*(Utimensat_f)p->call)(dirfd, path, tv, flags);
886
for (i = 0; i < elementsof(tb); i++)
887
{
888
tb[i] = tv[i];
889
UNWARP_ABS(tb[i].tv_sec);
890
}
891
r = (*(Utimensat_f)p->call)(dirfd, path, tb, flags);
892
if (p->level != state.level)
893
{
894
p->warped = 1;
895
r = (*(Utimensat_f)p->call)(dirfd, path, tv, flags);
896
}
897
return r;
898
}
899
900
extern int
901
utimensat(int dirfd, const char* path, const struct timespec* tv, int flags)
902
{
903
static Call_t call = { "utimensat", "utimensat" };
904
905
return warp_utimensat(dirfd, &call, path, tv, flags);
906
}
907
908
#ifndef __EXPORT__
909
910
extern int
911
_utimensat(int dirfd, const char* path, const struct timespec* tv, int flags)
912
{
913
static Call_t call = { "utimensat", "_utimensat" };
914
915
return warp_utimensat(dirfd, &call, path, tv, flags);
916
}
917
918
extern int
919
__utimensat(int dirfd, const char* path, const struct timespec* tv, int flags)
920
{
921
static Call_t call = { "utimensat", "__utimensat" };
922
923
return warp_utimensat(dirfd, &call, path, tv, flags);
924
}
925
926
extern int
927
_libc_utimensat(int dirfd, const char* path, const struct timespec* tv, int flags)
928
{
929
static Call_t call = { "utimensat", "_libc_utimensat" };
930
931
return warp_utimensat(dirfd, &call, path, tv, flags);
932
}
933
934
extern int
935
__libc_utimensat(int dirfd, const char* path, const struct timespec* tv, int flags)
936
{
937
static Call_t call = { "utimensat", "__libc_utimensat" };
938
939
return warp_utimensat(dirfd, &call, path, tv, flags);
940
}
941
942
#endif
943
944
static int
945
warp_utimes(register Call_t* p, const char* path, const struct timeval* tv)
946
{
947
int r;
948
register int i;
949
struct timeval tb[2];
950
951
intercept(p);
952
if (!tv || p->warped)
953
return (*(Utimes_f)p->call)(path, tv);
954
for (i = 0; i < elementsof(tb); i++)
955
{
956
tb[i] = tv[i];
957
UNWARP_ABS(tb[i].tv_sec);
958
}
959
r = (*(Utimes_f)p->call)(path, tb);
960
if (p->level != state.level)
961
{
962
p->warped = 1;
963
r = (*(Utimes_f)p->call)(path, tv);
964
}
965
return r;
966
}
967
968
extern int
969
utimes(const char* path, const struct timeval* tv)
970
{
971
static Call_t call = { "utimes", "utimes" };
972
973
return warp_utimes(&call, path, tv);
974
}
975
976
#ifndef __EXPORT__
977
978
extern int
979
_utimes(const char* path, const struct timeval* tv)
980
{
981
static Call_t call = { "utimes", "_utimes" };
982
983
return warp_utimes(&call, path, tv);
984
}
985
986
extern int
987
__utimes(const char* path, const struct timeval* tv)
988
{
989
static Call_t call = { "utimes", "__utimes" };
990
991
return warp_utimes(&call, path, tv);
992
}
993
994
extern int
995
_libc_utimes(const char* path, const struct timeval* tv)
996
{
997
static Call_t call = { "utimes", "_libc_utimes" };
998
999
return warp_utimes(&call, path, tv);
1000
}
1001
1002
extern int
1003
__libc_utimes(const char* path, const struct timeval* tv)
1004
{
1005
static Call_t call = { "utimes", "__libc_utimes" };
1006
1007
return warp_utimes(&call, path, tv);
1008
}
1009
1010
#endif
1011
1012
static int
1013
warp_utimets(register Call_t* p, const char* path, const struct timespec* tv)
1014
{
1015
int r;
1016
register int i;
1017
struct timespec tb[2];
1018
1019
intercept(p);
1020
if (!tv || p->warped)
1021
return (*(Utimets_f)p->call)(path, tv);
1022
for (i = 0; i < elementsof(tb); i++)
1023
{
1024
tb[i] = tv[i];
1025
UNWARP_ABS(tb[i].tv_sec);
1026
}
1027
r = (*(Utimets_f)p->call)(path, tb);
1028
if (p->level != state.level)
1029
{
1030
p->warped = 1;
1031
r = (*(Utimets_f)p->call)(path, tv);
1032
}
1033
return r;
1034
}
1035
1036
extern int
1037
utimets(const char* path, const struct timespec* tv)
1038
{
1039
static Call_t call = { "utimets", "utimets" };
1040
1041
return warp_utimets(&call, path, tv);
1042
}
1043
1044
#ifndef __EXPORT__
1045
1046
extern int
1047
_utimets(const char* path, const struct timespec* tv)
1048
{
1049
static Call_t call = { "utimets", "_utimets" };
1050
1051
return warp_utimets(&call, path, tv);
1052
}
1053
1054
extern int
1055
__utimets(const char* path, const struct timespec* tv)
1056
{
1057
static Call_t call = { "utimets", "__utimets" };
1058
1059
return warp_utimets(&call, path, tv);
1060
}
1061
1062
extern int
1063
_libc_utimets(const char* path, const struct timespec* tv)
1064
{
1065
static Call_t call = { "utimets", "_libc_utimets" };
1066
1067
return warp_utimets(&call, path, tv);
1068
}
1069
1070
extern int
1071
__libc_utimets(const char* path, const struct timespec* tv)
1072
{
1073
static Call_t call = { "utimets", "__libc_utimets" };
1074
1075
return warp_utimets(&call, path, tv);
1076
}
1077
1078
#endif
1079
1080
#if defined(_STAT_VER)
1081
1082
static void
1083
warp_xst(register Call_t* p, const int ver, register struct stat* st)
1084
{
1085
static const char msg[] = "warp: _STAT_VER\n";
1086
1087
if (!p->warped)
1088
{
1089
if (p->level != state.level)
1090
p->warped = 1;
1091
#if defined(_STAT64_VER)
1092
else if (ver >= _STAT64_VER)
1093
{
1094
register struct stat64* st64 = (struct stat64*)st;
1095
static const char msg64[] = "warp: _STAT64_VER\n";
1096
1097
if (state.trace)
1098
write(2, msg64, sizeof(msg64) - 1);
1099
WARP_ABS(st64->st_atime);
1100
WARP_ABS(st64->st_ctime);
1101
WARP_ABS(st64->st_mtime);
1102
}
1103
#endif
1104
else if (ver == _STAT_VER)
1105
{
1106
if (state.trace)
1107
write(2, msg, sizeof(msg) - 1);
1108
WARP_ABS(st->st_atime);
1109
WARP_ABS(st->st_ctime);
1110
WARP_ABS(st->st_mtime);
1111
}
1112
else if (state.trace)
1113
{
1114
static char msg[] = "warp: stat version 0\n";
1115
1116
msg[19] = '0' + ver;
1117
write(2, msg, sizeof(msg) - 1);
1118
}
1119
}
1120
}
1121
1122
extern int
1123
_fxstat(const int ver, int fd, struct stat* st)
1124
{
1125
int r;
1126
1127
static Call_t call = { "_fxstat", "_fxstat" };
1128
1129
intercept(&call);
1130
if ((r = (*(Fxstat_f)call.call)(ver, fd, st)) != -1)
1131
warp_xst(&call, ver, st);
1132
return r;
1133
}
1134
1135
extern int
1136
__fxstat(const int ver, int fd, struct stat* st)
1137
{
1138
int r;
1139
1140
static Call_t call = { "_fxstat", "__fxstat" };
1141
1142
intercept(&call);
1143
if ((r = (*(Fxstat_f)call.call)(ver, fd, st)) != -1)
1144
warp_xst(&call, ver, st);
1145
return r;
1146
}
1147
1148
extern int
1149
_lxstat(const int ver, const char* path, struct stat* st)
1150
{
1151
int r;
1152
1153
static Call_t call = { "_lxstat", "_lxstat" };
1154
1155
intercept(&call);
1156
if ((r = (*(Lxstat_f)call.call)(ver, path, st)) != -1)
1157
warp_xst(&call, ver, st);
1158
return r;
1159
}
1160
1161
extern int
1162
__lxstat(const int ver, const char* path, struct stat* st)
1163
{
1164
int r;
1165
1166
static Call_t call = { "_lxstat", "__lxstat" };
1167
1168
intercept(&call);
1169
if ((r = (*(Lxstat_f)call.call)(ver, path, st)) != -1)
1170
warp_xst(&call, ver, st);
1171
return r;
1172
}
1173
1174
extern int
1175
_xstat(const int ver, const char* path, struct stat* st)
1176
{
1177
int r;
1178
1179
static Call_t call = { "_xstat", "_xstat" };
1180
1181
intercept(&call);
1182
if ((r = (*(Xstat_f)call.call)(ver, path, st)) != -1)
1183
warp_xst(&call, ver, st);
1184
return r;
1185
}
1186
1187
extern int
1188
__xstat(const int ver, const char* path, struct stat* st)
1189
{
1190
int r;
1191
1192
static Call_t call = { "_xstat", "__xstat" };
1193
1194
intercept(&call);
1195
if ((r = (*(Xstat_f)call.call)(ver, path, st)) != -1)
1196
warp_xst(&call, ver, st);
1197
return r;
1198
}
1199
1200
#if defined(_lib__xstat64) || defined(_lib___xstat64)
1201
1202
static void
1203
warp_xst64(register Call_t* p, const int ver, register struct stat64* st)
1204
{
1205
static const char msg[] = "warp: _STAT_VER\n";
1206
1207
if (!p->warped)
1208
{
1209
if (p->level != state.level)
1210
p->warped = 1;
1211
#if defined(_STAT64_VER)
1212
else if (ver >= _STAT64_VER)
1213
{
1214
register struct stat64* st64 = (struct stat64*)st;
1215
static const char msg64[] = "warp: _STAT64_VER\n";
1216
1217
if (state.trace)
1218
write(2, msg64, sizeof(msg64) - 1);
1219
WARP_ABS(st64->st_atime);
1220
WARP_ABS(st64->st_ctime);
1221
WARP_ABS(st64->st_mtime);
1222
}
1223
#endif
1224
else if (ver == _STAT_VER)
1225
{
1226
if (state.trace)
1227
write(2, msg, sizeof(msg) - 1);
1228
WARP_ABS(st->st_atime);
1229
WARP_ABS(st->st_ctime);
1230
WARP_ABS(st->st_mtime);
1231
}
1232
else if (state.trace)
1233
{
1234
static char msg[] = "warp: stat version 0\n";
1235
1236
msg[19] = '0' + ver;
1237
write(2, msg, sizeof(msg) - 1);
1238
}
1239
}
1240
}
1241
1242
extern int
1243
_fxstat64(const int ver, int fd, struct stat64* st)
1244
{
1245
int r;
1246
1247
static Call_t call = { "_fxstat64", "_fxstat64" };
1248
1249
intercept(&call);
1250
if ((r = (*(Fxstat64_f)call.call)(ver, fd, st)) != -1)
1251
warp_xst64(&call, ver, st);
1252
return r;
1253
}
1254
1255
extern int
1256
__fxstat64(const int ver, int fd, struct stat64* st)
1257
{
1258
int r;
1259
1260
static Call_t call = { "_fxstat64", "__fxstat64" };
1261
1262
intercept(&call);
1263
if ((r = (*(Fxstat64_f)call.call)(ver, fd, st)) != -1)
1264
warp_xst64(&call, ver, st);
1265
return r;
1266
}
1267
1268
extern int
1269
_lxstat64(const int ver, const char* path, struct stat64* st)
1270
{
1271
int r;
1272
1273
static Call_t call = { "_lxstat64", "_lxstat64" };
1274
1275
intercept(&call);
1276
if ((r = (*(Lxstat64_f)call.call)(ver, path, st)) != -1)
1277
warp_xst64(&call, ver, st);
1278
return r;
1279
}
1280
1281
extern int
1282
__lxstat64(const int ver, const char* path, struct stat64* st)
1283
{
1284
int r;
1285
1286
static Call_t call = { "_lxstat64", "__lxstat64" };
1287
1288
intercept(&call);
1289
if ((r = (*(Lxstat64_f)call.call)(ver, path, st)) != -1)
1290
warp_xst64(&call, ver, st);
1291
return r;
1292
}
1293
1294
extern int
1295
_xstat64(const int ver, const char* path, struct stat64* st)
1296
{
1297
int r;
1298
1299
static Call_t call = { "_xstat64", "_xstat64" };
1300
1301
intercept(&call);
1302
if ((r = (*(Xstat64_f)call.call)(ver, path, st)) != -1)
1303
warp_xst64(&call, ver, st);
1304
return r;
1305
}
1306
1307
extern int
1308
__xstat64(const int ver, const char* path, struct stat64* st)
1309
{
1310
int r;
1311
1312
static Call_t call = { "_xstat64", "__xstat64" };
1313
1314
intercept(&call);
1315
if ((r = (*(Xstat64_f)call.call)(ver, path, st)) != -1)
1316
warp_xst64(&call, ver, st);
1317
return r;
1318
}
1319
1320
#endif
1321
#else
1322
1323
static void
1324
warp_st(register Call_t* p, register struct stat* st)
1325
{
1326
if (!p->warped)
1327
{
1328
if (p->level != state.level)
1329
p->warped = 1;
1330
else
1331
{
1332
WARP_ABS(st->st_atime);
1333
WARP_ABS(st->st_ctime);
1334
WARP_ABS(st->st_mtime);
1335
}
1336
}
1337
}
1338
1339
static int
1340
warp_fstat(register Call_t* p, int fd, struct stat* st)
1341
{
1342
int r;
1343
1344
intercept(p);
1345
if ((r = (*(Fstat_f)p->call)(fd, st)) != -1)
1346
warp_st(p, st);
1347
return r;
1348
}
1349
1350
extern int
1351
fstat(int fd, struct stat* st)
1352
{
1353
static Call_t call = { "fstat", "fstat" };
1354
1355
return warp_fstat(&call, fd, st);
1356
}
1357
1358
#ifndef __EXPORT__
1359
1360
extern int
1361
_fstat(int fd, struct stat* st)
1362
{
1363
static Call_t call = { "fstat", "_fstat" };
1364
1365
return warp_fstat(&call, fd, st);
1366
}
1367
1368
extern int
1369
__fstat(int fd, struct stat* st)
1370
{
1371
static Call_t call = { "fstat", "__fstat" };
1372
1373
return warp_fstat(&call, fd, st);
1374
}
1375
1376
extern int
1377
_libc_fstat(int fd, struct stat* st)
1378
{
1379
static Call_t call = { "fstat", "_libc_fstat" };
1380
1381
return warp_fstat(&call, fd, st);
1382
}
1383
1384
extern int
1385
__libc_fstat(int fd, struct stat* st)
1386
{
1387
static Call_t call = { "fstat", "__libc_fstat" };
1388
1389
return warp_fstat(&call, fd, st);
1390
}
1391
1392
#if _WARP_stat32
1393
1394
extern int
1395
__fstat32(int fd, struct stat* st)
1396
{
1397
static Call_t call = { "__fstat32", "__fstat32" };
1398
1399
return warp_fstat(&call, fd, st);
1400
}
1401
1402
#endif
1403
1404
#endif
1405
1406
static int
1407
warp_lstat(register Call_t* p, const char* path, struct stat* st)
1408
{
1409
int r;
1410
1411
intercept(p);
1412
if ((r = (*(Lstat_f)p->call)(path, st)) != -1)
1413
warp_st(p, st);
1414
return r;
1415
}
1416
1417
extern int
1418
lstat(const char* path, struct stat* st)
1419
{
1420
static Call_t call = { "lstat", "lstat" };
1421
1422
return warp_lstat(&call, path, st);
1423
}
1424
1425
#ifndef __EXPORT__
1426
1427
extern int
1428
_lstat(const char* path, struct stat* st)
1429
{
1430
static Call_t call = { "lstat", "_lstat" };
1431
1432
return warp_lstat(&call, path, st);
1433
}
1434
1435
extern int
1436
__lstat(const char* path, struct stat* st)
1437
{
1438
static Call_t call = { "lstat", "__lstat" };
1439
1440
return warp_lstat(&call, path, st);
1441
}
1442
1443
extern int
1444
_libc_lstat(const char* path, struct stat* st)
1445
{
1446
static Call_t call = { "lstat", "_libc_lstat" };
1447
1448
return warp_lstat(&call, path, st);
1449
}
1450
1451
extern int
1452
__libc_lstat(const char* path, struct stat* st)
1453
{
1454
static Call_t call = { "lstat", "__libc_lstat" };
1455
1456
return warp_lstat(&call, path, st);
1457
}
1458
1459
#if _WARP_stat32
1460
1461
extern int
1462
__lstat32(const char* path, struct stat* st)
1463
{
1464
static Call_t call = { "__lstat32", "__lstat32" };
1465
1466
return warp_lstat(&call, path, st);
1467
}
1468
1469
extern int
1470
__statlstat32(const char* path, struct stat* st)
1471
{
1472
static Call_t call = { "__statlstat32", "__statlstat32" };
1473
1474
return warp_lstat(&call, path, st);
1475
}
1476
1477
#endif
1478
1479
#endif
1480
1481
static int
1482
warp_stat(register Call_t* p, const char* path, struct stat* st)
1483
{
1484
int r;
1485
1486
intercept(p);
1487
if ((r = (*(Lstat_f)p->call)(path, st)) != -1)
1488
warp_st(p, st);
1489
return r;
1490
}
1491
1492
extern int
1493
stat(const char* path, struct stat* st)
1494
{
1495
static Call_t call = { "stat", "stat" };
1496
1497
return warp_stat(&call, path, st);
1498
}
1499
1500
#ifndef __EXPORT__
1501
1502
extern int
1503
_stat(const char* path, struct stat* st)
1504
{
1505
static Call_t call = { "stat", "_stat" };
1506
1507
return warp_stat(&call, path, st);
1508
}
1509
1510
extern int
1511
__stat(const char* path, struct stat* st)
1512
{
1513
static Call_t call = { "stat", "__stat" };
1514
1515
return warp_stat(&call, path, st);
1516
}
1517
1518
extern int
1519
_libc_stat(const char* path, struct stat* st)
1520
{
1521
static Call_t call = { "stat", "_libc_stat" };
1522
1523
return warp_stat(&call, path, st);
1524
}
1525
1526
extern int
1527
__libc_stat(const char* path, struct stat* st)
1528
{
1529
static Call_t call = { "stat", "__libc_stat" };
1530
1531
return warp_stat(&call, path, st);
1532
}
1533
1534
#if _WARP_stat32
1535
1536
extern int
1537
__stat32(const char* path, struct stat* st)
1538
{
1539
static Call_t call = { "__stat32", "__stat32" };
1540
1541
return warp_stat(&call, path, st);
1542
}
1543
1544
#endif
1545
1546
#endif
1547
1548
#endif
1549
1550
#if defined(_lib_stat64)
1551
1552
static void
1553
warp_st64(register Call_t* p, register struct stat64* st)
1554
{
1555
if (!p->warped)
1556
{
1557
if (p->level != state.level)
1558
p->warped = 1;
1559
else
1560
{
1561
WARP_ABS(st->st_atime);
1562
WARP_ABS(st->st_ctime);
1563
WARP_ABS(st->st_mtime);
1564
}
1565
}
1566
}
1567
1568
static int
1569
warp_fstat64(register Call_t* p, int fd, struct stat64* st)
1570
{
1571
int r;
1572
1573
intercept(p);
1574
if ((r = (*(Fstat64_f)p->call)(fd, st)) != -1)
1575
warp_st64(p, st);
1576
return r;
1577
}
1578
1579
extern int
1580
fstat64(int fd, struct stat64* st)
1581
{
1582
static Call_t call = { "fstat64", "fstat64" };
1583
1584
return warp_fstat64(&call, fd, st);
1585
}
1586
1587
#ifndef __EXPORT__
1588
1589
extern int
1590
_fstat64(int fd, struct stat64* st)
1591
{
1592
static Call_t call = { "fstat64", "_fstat64" };
1593
1594
return warp_fstat64(&call, fd, st);
1595
}
1596
1597
extern int
1598
__fstat64(int fd, struct stat64* st)
1599
{
1600
static Call_t call = { "fstat64", "__fstat64" };
1601
1602
return warp_fstat64(&call, fd, st);
1603
}
1604
1605
extern int
1606
_libc_fstat64(int fd, struct stat64* st)
1607
{
1608
static Call_t call = { "fstat64", "_libc_fstat64" };
1609
1610
return warp_fstat64(&call, fd, st);
1611
}
1612
1613
extern int
1614
__libc_fstat64(int fd, struct stat64* st)
1615
{
1616
static Call_t call = { "fstat64", "__libc_fstat64" };
1617
1618
return warp_fstat64(&call, fd, st);
1619
}
1620
1621
#endif
1622
1623
static int
1624
warp_lstat64(register Call_t* p, const char* path, struct stat64* st)
1625
{
1626
int r;
1627
1628
intercept(p);
1629
if ((r = (*(Lstat64_f)p->call)(path, st)) != -1)
1630
warp_st64(p, st);
1631
return r;
1632
}
1633
1634
extern int
1635
lstat64(const char* path, struct stat64* st)
1636
{
1637
static Call_t call = { "lstat64", "lstat64" };
1638
1639
return warp_lstat64(&call, path, st);
1640
}
1641
1642
#ifndef __EXPORT__
1643
1644
extern int
1645
_lstat64(const char* path, struct stat64* st)
1646
{
1647
static Call_t call = { "lstat64", "_lstat64" };
1648
1649
return warp_lstat64(&call, path, st);
1650
}
1651
1652
extern int
1653
__lstat64(const char* path, struct stat64* st)
1654
{
1655
static Call_t call = { "lstat64", "__lstat64" };
1656
1657
return warp_lstat64(&call, path, st);
1658
}
1659
1660
extern int
1661
_libc_lstat64(const char* path, struct stat64* st)
1662
{
1663
static Call_t call = { "lstat64", "_libc_lstat64" };
1664
1665
return warp_lstat64(&call, path, st);
1666
}
1667
1668
extern int
1669
__libc_lstat64(const char* path, struct stat64* st)
1670
{
1671
static Call_t call = { "lstat64", "__libc_lstat64" };
1672
1673
return warp_lstat64(&call, path, st);
1674
}
1675
1676
#endif
1677
1678
static int
1679
warp_stat64(register Call_t* p, const char* path, struct stat64* st)
1680
{
1681
int r;
1682
1683
intercept(p);
1684
if ((r = (*(Stat64_f)p->call)(path, st)) != -1)
1685
warp_st64(p, st);
1686
return r;
1687
}
1688
1689
extern int
1690
stat64(const char* path, struct stat64* st)
1691
{
1692
static Call_t call = { "stat64", "stat64" };
1693
1694
return warp_stat64(&call, path, st);
1695
}
1696
1697
#ifndef __EXPORT__
1698
1699
extern int
1700
_stat64(const char* path, struct stat64* st)
1701
{
1702
static Call_t call = { "stat64", "_stat64" };
1703
1704
return warp_stat64(&call, path, st);
1705
}
1706
1707
extern int
1708
__stat64(const char* path, struct stat64* st)
1709
{
1710
static Call_t call = { "stat64", "__stat64" };
1711
1712
return warp_stat64(&call, path, st);
1713
}
1714
1715
extern int
1716
_libc_stat64(const char* path, struct stat64* st)
1717
{
1718
static Call_t call = { "stat64", "_libc_stat64" };
1719
1720
return warp_stat64(&call, path, st);
1721
}
1722
1723
extern int
1724
__libc_stat64(const char* path, struct stat64* st)
1725
{
1726
static Call_t call = { "stat64", "__libc_stat64" };
1727
1728
return warp_stat64(&call, path, st);
1729
}
1730
1731
#endif
1732
1733
#endif /* defined(_lib_stat64) */
1734
1735
#if _lib_clock_gettime && defined(CLOCK_REALTIME)
1736
1737
static int
1738
warp_clock_gettime(register Call_t* p, int clock, struct timespec* tv)
1739
{
1740
int r;
1741
1742
intercept(p);
1743
if ((r = (*(Clock_gettime_f)p->call)(clock, tv)) != -1 && !p->warped)
1744
{
1745
if (p->level != state.level)
1746
p->warped = 1;
1747
else if (tv)
1748
WARP_ABS(tv->tv_sec);
1749
}
1750
return r;
1751
}
1752
1753
extern int
1754
clock_gettime(int i, struct timespec* v)
1755
{
1756
static Call_t call = { "clock_gettime", "clock_gettime" };
1757
1758
return warp_clock_gettime(&call, i, v);
1759
}
1760
1761
#ifndef __EXPORT__
1762
1763
extern int
1764
_clock_gettime(int i, struct timespec* v)
1765
{
1766
static Call_t call = { "clock_gettime", "_clock_gettime" };
1767
1768
return warp_clock_gettime(&call, i, v);
1769
}
1770
1771
extern int
1772
__clock_gettime(int i, struct timespec* v)
1773
{
1774
static Call_t call = { "clock_gettime", "__clock_gettime" };
1775
1776
return warp_clock_gettime(&call, i, v);
1777
}
1778
1779
extern int
1780
_libc_clock_gettime(int i, struct timespec* v)
1781
{
1782
static Call_t call = { "clock_gettime", "_libc_clock_gettime" };
1783
1784
return warp_clock_gettime(&call, i, v);
1785
}
1786
1787
extern int
1788
__libc_clock_gettime(int i, struct timespec* v)
1789
{
1790
static Call_t call = { "clock_gettime", "__libc_clock_gettime" };
1791
1792
return warp_clock_gettime(&call, i, v);
1793
}
1794
1795
#endif
1796
1797
#endif /* _lib_clock_gettime */
1798
1799
#if _lib_getitimer
1800
1801
static int
1802
warp_getitimer(register Call_t* p, int i, struct itimerval* v)
1803
{
1804
int r;
1805
1806
intercept(p);
1807
if ((r = (*(Getitimer_f)p->call)(i, v)) != -1 && !p->warped && state.factor)
1808
{
1809
if (p->level != state.level)
1810
p->warped = 1;
1811
else
1812
{
1813
WARP_REL(v->it_interval.tv_sec);
1814
WARP_REL(v->it_value.tv_sec);
1815
}
1816
}
1817
return r;
1818
}
1819
1820
extern int
1821
getitimer(int i, struct itimerval* v)
1822
{
1823
static Call_t call = { "getitimer", "getitimer" };
1824
1825
return warp_getitimer(&call, i, v);
1826
}
1827
1828
#ifndef __EXPORT__
1829
1830
extern int
1831
_getitimer(int i, struct itimerval* v)
1832
{
1833
static Call_t call = { "getitimer", "_getitimer" };
1834
1835
return warp_getitimer(&call, i, v);
1836
}
1837
1838
extern int
1839
__getitimer(int i, struct itimerval* v)
1840
{
1841
static Call_t call = { "getitimer", "__getitimer" };
1842
1843
return warp_getitimer(&call, i, v);
1844
}
1845
1846
extern int
1847
_libc_getitimer(int i, struct itimerval* v)
1848
{
1849
static Call_t call = { "getitimer", "_libc_getitimer" };
1850
1851
return warp_getitimer(&call, i, v);
1852
}
1853
1854
extern int
1855
__libc_getitimer(int i, struct itimerval* v)
1856
{
1857
static Call_t call = { "getitimer", "__libc_getitimer" };
1858
1859
return warp_getitimer(&call, i, v);
1860
}
1861
1862
#endif
1863
1864
#endif /* _lib_getitimer */
1865
1866
#if _lib_setitimer
1867
1868
static int
1869
warp_setitimer(register Call_t* p, int i, const struct itimerval* v, struct itimerval* o)
1870
{
1871
int r;
1872
struct itimerval x;
1873
1874
intercept(p);
1875
if (p->warped || !state.factor)
1876
return (*(Setitimer_f)p->call)(i, v, o);
1877
x = *v;
1878
if (x.it_interval.tv_sec)
1879
{
1880
UNWARP_REL(x.it_interval.tv_sec);
1881
if (x.it_interval.tv_sec)
1882
x.it_interval.tv_usec = 0;
1883
else if (!(x.it_interval.tv_usec /= state.factor))
1884
x.it_interval.tv_usec = 10;
1885
}
1886
if (x.it_value.tv_sec)
1887
{
1888
UNWARP_REL(x.it_value.tv_sec);
1889
if (x.it_value.tv_sec)
1890
x.it_value.tv_usec = 0;
1891
else if (!(x.it_value.tv_usec /= state.factor))
1892
x.it_value.tv_usec = 10;
1893
}
1894
if ((r = (*(Setitimer_f)p->call)(i, &x, o)) != -1 && !p->warped)
1895
{
1896
if (p->level != state.level)
1897
p->warped = 1;
1898
else if (o)
1899
{
1900
WARP_REL(o->it_interval.tv_sec);
1901
WARP_REL(o->it_value.tv_sec);
1902
}
1903
}
1904
return r;
1905
}
1906
1907
extern int
1908
setitimer(int i, const struct itimerval* v, struct itimerval* o)
1909
{
1910
static Call_t call = { "setitimer", "setitimer" };
1911
1912
return warp_setitimer(&call, i, v, o);
1913
}
1914
1915
#ifndef __EXPORT__
1916
1917
extern int
1918
_setitimer(int i, const struct itimerval* v, struct itimerval* o)
1919
{
1920
static Call_t call = { "setitimer", "_setitimer" };
1921
1922
return warp_setitimer(&call, i, v, o);
1923
}
1924
1925
extern int
1926
__setitimer(int i, const struct itimerval* v, struct itimerval* o)
1927
{
1928
static Call_t call = { "setitimer", "__setitimer" };
1929
1930
return warp_setitimer(&call, i, v, o);
1931
}
1932
1933
extern int
1934
_libc_setitimer(int i, const struct itimerval* v, struct itimerval* o)
1935
{
1936
static Call_t call = { "setitimer", "_libc_setitimer" };
1937
1938
return warp_setitimer(&call, i, v, o);
1939
}
1940
1941
extern int
1942
__libc_setitimer(int i, const struct itimerval* v, struct itimerval* o)
1943
{
1944
static Call_t call = { "setitimer", "__libc_setitimer" };
1945
1946
return warp_setitimer(&call, i, v, o);
1947
}
1948
1949
#endif
1950
1951
#endif /* _lib_setitimer */
1952
1953
#ifndef __EXPORT__
1954
1955
static char**
1956
warp_env(char* const arge[])
1957
{
1958
register char** e;
1959
register char** x;
1960
register char* s;
1961
register char* t;
1962
register char* u;
1963
char** z;
1964
char** env;
1965
int n;
1966
1967
env = (char**)arge;
1968
if (*state.env)
1969
{
1970
if (e = env)
1971
{
1972
while (s = *e++)
1973
{
1974
x = state.env;
1975
while (t = *x++)
1976
{
1977
u = s;
1978
while (*t++ == *u++)
1979
if (!*t)
1980
goto found;
1981
}
1982
goto missing;
1983
found:
1984
;
1985
}
1986
}
1987
else
1988
s = *state.env;
1989
missing:
1990
if (s)
1991
{
1992
if (state.trace)
1993
{
1994
s = "warp: execve env missing\n";
1995
write(2, s, strlen(s));
1996
}
1997
if (e = env)
1998
{
1999
while (*e++);
2000
n = e - env;
2001
}
2002
else
2003
n = 1;
2004
e = state.env;
2005
while (*e++);
2006
n += (e - state.env) - 1;
2007
if (!(z = (char**)malloc(n * sizeof(char**))))
2008
{
2009
s = "warp: execve env malloc error\n";
2010
write(2, s, strlen(s));
2011
_exit(125);
2012
}
2013
e = env;
2014
env = z;
2015
x = state.env;
2016
while (*z = *x++)
2017
z++;
2018
if (e)
2019
while (*z++ = *e++);
2020
if (state.trace)
2021
{
2022
z = env;
2023
while (t = *z++)
2024
{
2025
s = "warp: execve new env ";
2026
write(2, s, strlen(s));
2027
write(2, t, strlen(t));
2028
write(2, "\n", 1);
2029
}
2030
}
2031
}
2032
else if (state.trace)
2033
{
2034
s = "warp: execve env ok\n";
2035
write(2, s, strlen(s));
2036
}
2037
}
2038
else if (state.trace)
2039
{
2040
s = "warp: execve skip check\n";
2041
write(2, s, strlen(s));
2042
}
2043
return env;
2044
}
2045
2046
static int
2047
warp_execve(register Call_t* p, const char* path, char* const argv[], char* const arge[])
2048
{
2049
int n;
2050
char** env;
2051
2052
static int level;
2053
2054
intercept(p);
2055
env = (!p->warped && !level) ? warp_env(arge) : (char**)arge;
2056
p->warped++;
2057
level++;
2058
n = (*(Execve_f)p->call)(path, argv, env);
2059
level--;
2060
p->warped--;
2061
return n;
2062
}
2063
2064
static int
2065
warp_execvpe(register Call_t* p, const char* path, char* const argv[], char* const arge[])
2066
{
2067
int n;
2068
char** env;
2069
2070
static int level;
2071
2072
intercept(p);
2073
env = (!p->warped && !level) ? warp_env(arge) : (char**)arge;
2074
p->warped++;
2075
level++;
2076
n = (*(Execvpe_f)p->call)(path, argv, env);
2077
level--;
2078
p->warped--;
2079
return n;
2080
}
2081
2082
extern int
2083
execve(const char* path, char* const argv[], char* const arge[])
2084
{
2085
static Call_t call = { "execve", "execve" };
2086
2087
return warp_execve(&call, path, argv, arge);
2088
}
2089
2090
extern int
2091
_execve(const char* path, char* const argv[], char* const arge[])
2092
{
2093
static Call_t call = { "execve", "_execve" };
2094
2095
return warp_execve(&call, path, argv, arge);
2096
}
2097
2098
extern int
2099
__execve(const char* path, char* const argv[], char* const arge[])
2100
{
2101
static Call_t call = { "execve", "__execve" };
2102
2103
return warp_execve(&call, path, argv, arge);
2104
}
2105
2106
extern int
2107
_libc_execve(const char* path, char* const argv[], char* const arge[])
2108
{
2109
static Call_t call = { "execve", "_libc_execve" };
2110
2111
return warp_execve(&call, path, argv, arge);
2112
}
2113
2114
extern int
2115
__libc_execve(const char* path, char* const argv[], char* const arge[])
2116
{
2117
static Call_t call = { "execve", "__libc_execve" };
2118
2119
return warp_execve(&call, path, argv, arge);
2120
}
2121
2122
extern int
2123
execv(const char* path, char* const argv[])
2124
{
2125
static Call_t call = { "execv", "execv" };
2126
2127
return warp_execve(&call, path, argv, environ);
2128
}
2129
2130
extern int
2131
_execv(const char* path, char* const argv[])
2132
{
2133
static Call_t call = { "execv", "_execv" };
2134
2135
return warp_execve(&call, path, argv, environ);
2136
}
2137
2138
extern int
2139
__execv(const char* path, char* const argv[])
2140
{
2141
static Call_t call = { "execv", "__execv" };
2142
2143
return warp_execve(&call, path, argv, environ);
2144
}
2145
2146
extern int
2147
_libc_execv(const char* path, char* const argv[])
2148
{
2149
static Call_t call = { "execv", "_libc_execv" };
2150
2151
return warp_execve(&call, path, argv, environ);
2152
}
2153
2154
extern int
2155
__libc_execv(const char* path, char* const argv[])
2156
{
2157
static Call_t call = { "execv", "__libc_execv" };
2158
2159
return warp_execve(&call, path, argv, environ);
2160
}
2161
2162
extern int
2163
execvp(const char* path, char* const argv[])
2164
{
2165
static Call_t call = { "execvp", "execvp" };
2166
2167
return warp_execvpe(&call, path, argv, environ);
2168
}
2169
2170
extern int
2171
_execvp(const char* path, char* const argv[])
2172
{
2173
static Call_t call = { "execvp", "_execvp" };
2174
2175
return warp_execvpe(&call, path, argv, environ);
2176
}
2177
2178
extern int
2179
__execvp(const char* path, char* const argv[])
2180
{
2181
static Call_t call = { "execvp", "__execvp" };
2182
2183
return warp_execvpe(&call, path, argv, environ);
2184
}
2185
2186
extern int
2187
_libc_execvp(const char* path, char* const argv[])
2188
{
2189
static Call_t call = { "execvp", "_libc_execvp" };
2190
2191
return warp_execvpe(&call, path, argv, environ);
2192
}
2193
2194
extern int
2195
__libc_execvp(const char* path, char* const argv[])
2196
{
2197
static Call_t call = { "execvp", "__libc_execvp" };
2198
2199
return warp_execvpe(&call, path, argv, environ);
2200
}
2201
2202
extern int
2203
execvpe(const char* path, char* const argv[], char* const arge[])
2204
{
2205
static Call_t call = { "execvpe", "execvpe" };
2206
2207
return warp_execvpe(&call, path, argv, arge);
2208
}
2209
2210
extern int
2211
_execvpe(const char* path, char* const argv[], char* const arge[])
2212
{
2213
static Call_t call = { "execvpe", "_execvpe" };
2214
2215
return warp_execvpe(&call, path, argv, arge);
2216
}
2217
2218
extern int
2219
__execvpe(const char* path, char* const argv[], char* const arge[])
2220
{
2221
static Call_t call = { "execvpe", "__execvpe" };
2222
2223
return warp_execvpe(&call, path, argv, arge);
2224
}
2225
2226
extern int
2227
_libc_execvpe(const char* path, char* const argv[], char* const arge[])
2228
{
2229
static Call_t call = { "execvpe", "_libc_execvpe" };
2230
2231
return warp_execvpe(&call, path, argv, arge);
2232
}
2233
2234
extern int
2235
__libc_execvpe(const char* path, char* const argv[], char* const arge[])
2236
{
2237
static Call_t call = { "execvpe", "__libc_execvpe" };
2238
2239
return warp_execvpe(&call, path, argv, arge);
2240
}
2241
2242
extern int
2243
execl(const char* path, const char* arg, ...)
2244
{
2245
static Call_t call = { "execl", "execl" };
2246
2247
return warp_execve(&call, path, (char* const*)&arg, environ);
2248
}
2249
2250
extern int
2251
_execl(const char* path, const char* arg, ...)
2252
{
2253
static Call_t call = { "execl", "_execl" };
2254
2255
return warp_execve(&call, path, (char* const*)&arg, environ);
2256
}
2257
2258
extern int
2259
__execl(const char* path, const char* arg, ...)
2260
{
2261
static Call_t call = { "execl", "__execl" };
2262
2263
return warp_execve(&call, path, (char* const*)&arg, environ);
2264
}
2265
2266
extern int
2267
_libc_execl(const char* path, const char* arg, ...)
2268
{
2269
static Call_t call = { "execl", "_libc_execl" };
2270
2271
return warp_execve(&call, path, (char* const*)&arg, environ);
2272
}
2273
2274
extern int
2275
__libc_execl(const char* path, const char* arg, ...)
2276
{
2277
static Call_t call = { "execl", "__libc_execl" };
2278
2279
return warp_execve(&call, path, (char* const*)&arg, environ);
2280
}
2281
2282
extern int
2283
execlp(const char* path, const char* arg, ...)
2284
{
2285
static Call_t call = { "execlp", "execlp" };
2286
2287
return warp_execvpe(&call, path, (char* const*)&arg, environ);
2288
}
2289
2290
extern int
2291
_execlp(const char* path, const char* arg, ...)
2292
{
2293
static Call_t call = { "execlp", "_execlp" };
2294
2295
return warp_execvpe(&call, path, (char* const*)&arg, environ);
2296
}
2297
2298
extern int
2299
__execlp(const char* path, const char* arg, ...)
2300
{
2301
static Call_t call = { "execlp", "__execlp" };
2302
2303
return warp_execvpe(&call, path, (char* const*)&arg, environ);
2304
}
2305
2306
extern int
2307
_libc_execlp(const char* path, const char* arg, ...)
2308
{
2309
static Call_t call = { "execlp", "_libc_execlp" };
2310
2311
return warp_execvpe(&call, path, (char* const*)&arg, environ);
2312
}
2313
2314
extern int
2315
__libc_execlp(const char* path, const char* arg, ...)
2316
{
2317
static Call_t call = { "execlp", "__libc_execlp" };
2318
2319
return warp_execvpe(&call, path, (char* const*)&arg, environ);
2320
}
2321
2322
#endif
2323
2324