msan_interceptors.cc revision 4bbbe136fe6a19a8288a6d92af29075756dd8fa5
1//===-- msan_interceptors.cc ----------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of MemorySanitizer.
11//
12// Interceptors for standard library functions.
13//
14// FIXME: move as many interceptors as possible into
15// sanitizer_common/sanitizer_common_interceptors.h
16//===----------------------------------------------------------------------===//
17
18#include "interception/interception.h"
19#include "msan.h"
20#include "sanitizer_common/sanitizer_platform_limits_posix.h"
21#include "sanitizer_common/sanitizer_allocator.h"
22#include "sanitizer_common/sanitizer_common.h"
23#include "sanitizer_common/sanitizer_stackdepot.h"
24#include "sanitizer_common/sanitizer_libc.h"
25#include "sanitizer_common/sanitizer_linux.h"
26
27#include <stdarg.h>
28// ACHTUNG! No other system header includes in this file.
29// Ideally, we should get rid of stdarg.h as well.
30
31using namespace __msan;
32
33// True if this is a nested interceptor.
34static THREADLOCAL int in_interceptor_scope;
35
36struct InterceptorScope {
37  InterceptorScope() { ++in_interceptor_scope; }
38  ~InterceptorScope() { --in_interceptor_scope; }
39};
40
41bool IsInInterceptorScope() {
42  return in_interceptor_scope;
43}
44
45#define ENSURE_MSAN_INITED() do { \
46  CHECK(!msan_init_is_running); \
47  if (!msan_inited) { \
48    __msan_init(); \
49  } \
50} while (0)
51
52// Check that [x, x+n) range is unpoisoned.
53#define CHECK_UNPOISONED_0(x, n)                                             \
54  do {                                                                       \
55    sptr offset = __msan_test_shadow(x, n);                                  \
56    if (__msan::IsInSymbolizer()) break;                                     \
57    if (offset >= 0 && __msan::flags()->report_umrs) {                       \
58      GET_CALLER_PC_BP_SP;                                                   \
59      (void) sp;                                                             \
60      Printf("UMR in %s at offset %d inside [%p, +%d) \n", __FUNCTION__,     \
61             offset, x, n);                                                  \
62      __msan::PrintWarningWithOrigin(pc, bp,                                 \
63                                     __msan_get_origin((char *)x + offset)); \
64      if (!__msan::flags()->keep_going) {                                    \
65        Printf("Exiting\n");                                                 \
66        Die();                                                               \
67      }                                                                      \
68    }                                                                        \
69  } while (0)
70
71// Check that [x, x+n) range is unpoisoned unless we are in a nested
72// interceptor.
73#define CHECK_UNPOISONED(x, n)                             \
74  do {                                                     \
75    if (!IsInInterceptorScope()) CHECK_UNPOISONED_0(x, n); \
76  } while (0);
77
78static void *fast_memset(void *ptr, int c, SIZE_T n);
79static void *fast_memcpy(void *dst, const void *src, SIZE_T n);
80
81INTERCEPTOR(SIZE_T, fread, void *ptr, SIZE_T size, SIZE_T nmemb, void *file) {
82  ENSURE_MSAN_INITED();
83  SIZE_T res = REAL(fread)(ptr, size, nmemb, file);
84  if (res > 0)
85    __msan_unpoison(ptr, res *size);
86  return res;
87}
88
89INTERCEPTOR(SIZE_T, fread_unlocked, void *ptr, SIZE_T size, SIZE_T nmemb,
90            void *file) {
91  ENSURE_MSAN_INITED();
92  SIZE_T res = REAL(fread_unlocked)(ptr, size, nmemb, file);
93  if (res > 0)
94    __msan_unpoison(ptr, res *size);
95  return res;
96}
97
98INTERCEPTOR(SSIZE_T, readlink, const char *path, char *buf, SIZE_T bufsiz) {
99  ENSURE_MSAN_INITED();
100  SSIZE_T res = REAL(readlink)(path, buf, bufsiz);
101  if (res > 0)
102    __msan_unpoison(buf, res);
103  return res;
104}
105
106INTERCEPTOR(void *, memcpy, void *dest, const void *src, SIZE_T n) {
107  return __msan_memcpy(dest, src, n);
108}
109
110INTERCEPTOR(void *, memmove, void *dest, const void *src, SIZE_T n) {
111  return __msan_memmove(dest, src, n);
112}
113
114INTERCEPTOR(void *, memset, void *s, int c, SIZE_T n) {
115  return __msan_memset(s, c, n);
116}
117
118INTERCEPTOR(int, posix_memalign, void **memptr, SIZE_T alignment, SIZE_T size) {
119  GET_MALLOC_STACK_TRACE;
120  CHECK_EQ(alignment & (alignment - 1), 0);
121  CHECK_NE(memptr, 0);
122  *memptr = MsanReallocate(&stack, 0, size, alignment, false);
123  CHECK_NE(*memptr, 0);
124  __msan_unpoison(memptr, sizeof(*memptr));
125  return 0;
126}
127
128INTERCEPTOR(void, free, void *ptr) {
129  ENSURE_MSAN_INITED();
130  if (ptr == 0) return;
131  MsanDeallocate(ptr);
132}
133
134INTERCEPTOR(SIZE_T, strlen, const char *s) {
135  ENSURE_MSAN_INITED();
136  SIZE_T res = REAL(strlen)(s);
137  CHECK_UNPOISONED(s, res + 1);
138  return res;
139}
140
141INTERCEPTOR(SIZE_T, strnlen, const char *s, SIZE_T n) {
142  ENSURE_MSAN_INITED();
143  SIZE_T res = REAL(strnlen)(s, n);
144  SIZE_T scan_size = (res == n) ? res : res + 1;
145  CHECK_UNPOISONED(s, scan_size);
146  return res;
147}
148
149// FIXME: Add stricter shadow checks in str* interceptors (ex.: strcpy should
150// check the shadow of the terminating \0 byte).
151
152INTERCEPTOR(char *, strcpy, char *dest, const char *src) {  // NOLINT
153  ENSURE_MSAN_INITED();
154  SIZE_T n = REAL(strlen)(src);
155  char *res = REAL(strcpy)(dest, src);  // NOLINT
156  __msan_copy_poison(dest, src, n + 1);
157  return res;
158}
159
160INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) {  // NOLINT
161  ENSURE_MSAN_INITED();
162  SIZE_T copy_size = REAL(strnlen)(src, n);
163  if (copy_size < n)
164    copy_size++;  // trailing \0
165  char *res = REAL(strncpy)(dest, src, n);  // NOLINT
166  __msan_copy_poison(dest, src, copy_size);
167  return res;
168}
169
170INTERCEPTOR(char *, stpcpy, char *dest, const char *src) {  // NOLINT
171  ENSURE_MSAN_INITED();
172  SIZE_T n = REAL(strlen)(src);
173  char *res = REAL(stpcpy)(dest, src);  // NOLINT
174  __msan_copy_poison(dest, src, n + 1);
175  return res;
176}
177
178INTERCEPTOR(char *, strdup, char *src) {
179  ENSURE_MSAN_INITED();
180  SIZE_T n = REAL(strlen)(src);
181  char *res = REAL(strdup)(src);
182  __msan_copy_poison(res, src, n + 1);
183  return res;
184}
185
186INTERCEPTOR(char *, __strdup, char *src) {
187  ENSURE_MSAN_INITED();
188  SIZE_T n = REAL(strlen)(src);
189  char *res = REAL(__strdup)(src);
190  __msan_copy_poison(res, src, n + 1);
191  return res;
192}
193
194INTERCEPTOR(char *, strndup, char *src, SIZE_T n) {
195  ENSURE_MSAN_INITED();
196  SIZE_T copy_size = REAL(strnlen)(src, n);
197  char *res = REAL(strndup)(src, n);
198  __msan_copy_poison(res, src, copy_size);
199  __msan_unpoison(res + copy_size, 1); // \0
200  return res;
201}
202
203INTERCEPTOR(char *, __strndup, char *src, SIZE_T n) {
204  ENSURE_MSAN_INITED();
205  SIZE_T copy_size = REAL(strnlen)(src, n);
206  char *res = REAL(__strndup)(src, n);
207  __msan_copy_poison(res, src, copy_size);
208  __msan_unpoison(res + copy_size, 1); // \0
209  return res;
210}
211
212INTERCEPTOR(char *, gcvt, double number, SIZE_T ndigit, char *buf) {
213  ENSURE_MSAN_INITED();
214  char *res = REAL(gcvt)(number, ndigit, buf);
215  // DynamoRio tool will take care of unpoisoning gcvt result for us.
216  if (!__msan_has_dynamic_component()) {
217    SIZE_T n = REAL(strlen)(buf);
218    __msan_unpoison(buf, n + 1);
219  }
220  return res;
221}
222
223INTERCEPTOR(char *, strcat, char *dest, const char *src) {  // NOLINT
224  ENSURE_MSAN_INITED();
225  SIZE_T src_size = REAL(strlen)(src);
226  SIZE_T dest_size = REAL(strlen)(dest);
227  char *res = REAL(strcat)(dest, src);  // NOLINT
228  __msan_copy_poison(dest + dest_size, src, src_size + 1);
229  return res;
230}
231
232INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) {  // NOLINT
233  ENSURE_MSAN_INITED();
234  SIZE_T dest_size = REAL(strlen)(dest);
235  SIZE_T copy_size = REAL(strlen)(src);
236  if (copy_size < n)
237    copy_size++;  // trailing \0
238  char *res = REAL(strncat)(dest, src, n);  // NOLINT
239  __msan_copy_poison(dest + dest_size, src, copy_size);
240  return res;
241}
242
243INTERCEPTOR(long, strtol, const char *nptr, char **endptr,  // NOLINT
244            int base) {
245  ENSURE_MSAN_INITED();
246  long res = REAL(strtol)(nptr, endptr, base);  // NOLINT
247  if (!__msan_has_dynamic_component()) {
248    __msan_unpoison(endptr, sizeof(*endptr));
249  }
250  return res;
251}
252
253INTERCEPTOR(long long, strtoll, const char *nptr, char **endptr,  // NOLINT
254            int base) {
255  ENSURE_MSAN_INITED();
256  long res = REAL(strtoll)(nptr, endptr, base);  //NOLINT
257  if (!__msan_has_dynamic_component()) {
258    __msan_unpoison(endptr, sizeof(*endptr));
259  }
260  return res;
261}
262
263INTERCEPTOR(unsigned long, strtoul, const char *nptr, char **endptr,  // NOLINT
264            int base) {
265  ENSURE_MSAN_INITED();
266  unsigned long res = REAL(strtoul)(nptr, endptr, base);  // NOLINT
267  if (!__msan_has_dynamic_component()) {
268    __msan_unpoison(endptr, sizeof(*endptr));
269  }
270  return res;
271}
272
273INTERCEPTOR(unsigned long long, strtoull, const char *nptr,  // NOLINT
274            char **endptr, int base) {
275  ENSURE_MSAN_INITED();
276  unsigned long res = REAL(strtoull)(nptr, endptr, base);  // NOLINT
277  if (!__msan_has_dynamic_component()) {
278    __msan_unpoison(endptr, sizeof(*endptr));
279  }
280  return res;
281}
282
283INTERCEPTOR(double, strtod, const char *nptr, char **endptr) {  // NOLINT
284  ENSURE_MSAN_INITED();
285  double res = REAL(strtod)(nptr, endptr);  // NOLINT
286  if (!__msan_has_dynamic_component()) {
287    __msan_unpoison(endptr, sizeof(*endptr));
288  }
289  return res;
290}
291
292INTERCEPTOR(float, strtof, const char *nptr, char **endptr) {  // NOLINT
293  ENSURE_MSAN_INITED();
294  float res = REAL(strtof)(nptr, endptr);  // NOLINT
295  if (!__msan_has_dynamic_component()) {
296    __msan_unpoison(endptr, sizeof(*endptr));
297  }
298  return res;
299}
300
301INTERCEPTOR(long double, strtold, const char *nptr, char **endptr) {  // NOLINT
302  ENSURE_MSAN_INITED();
303  long double res = REAL(strtold)(nptr, endptr);  // NOLINT
304  if (!__msan_has_dynamic_component()) {
305    __msan_unpoison(endptr, sizeof(*endptr));
306  }
307  return res;
308}
309
310INTERCEPTOR(int, vasprintf, char **strp, const char *format, va_list ap) {
311  ENSURE_MSAN_INITED();
312  int res = REAL(vasprintf)(strp, format, ap);
313  if (res >= 0 && !__msan_has_dynamic_component()) {
314    __msan_unpoison(strp, sizeof(*strp));
315    __msan_unpoison(*strp, res + 1);
316  }
317  return res;
318}
319
320INTERCEPTOR(int, asprintf, char **strp, const char *format, ...) {  // NOLINT
321  ENSURE_MSAN_INITED();
322  va_list ap;
323  va_start(ap, format);
324  int res = vasprintf(strp, format, ap);  // NOLINT
325  va_end(ap);
326  return res;
327}
328
329INTERCEPTOR(int, vsnprintf, char *str, uptr size,
330            const char *format, va_list ap) {
331  ENSURE_MSAN_INITED();
332  int res = REAL(vsnprintf)(str, size, format, ap);
333  if (res >= 0 && !__msan_has_dynamic_component()) {
334    __msan_unpoison(str, res + 1);
335  }
336  return res;
337}
338
339INTERCEPTOR(int, vsprintf, char *str, const char *format, va_list ap) {
340  ENSURE_MSAN_INITED();
341  int res = REAL(vsprintf)(str, format, ap);
342  if (res >= 0 && !__msan_has_dynamic_component()) {
343    __msan_unpoison(str, res + 1);
344  }
345  return res;
346}
347
348INTERCEPTOR(int, vswprintf, void *str, uptr size, void *format, va_list ap) {
349  ENSURE_MSAN_INITED();
350  int res = REAL(vswprintf)(str, size, format, ap);
351  if (res >= 0 && !__msan_has_dynamic_component()) {
352    __msan_unpoison(str, 4 * (res + 1));
353  }
354  return res;
355}
356
357INTERCEPTOR(int, sprintf, char *str, const char *format, ...) {  // NOLINT
358  ENSURE_MSAN_INITED();
359  va_list ap;
360  va_start(ap, format);
361  int res = vsprintf(str, format, ap);  // NOLINT
362  va_end(ap);
363  return res;
364}
365
366INTERCEPTOR(int, snprintf, char *str, uptr size, const char *format, ...) {
367  ENSURE_MSAN_INITED();
368  va_list ap;
369  va_start(ap, format);
370  int res = vsnprintf(str, size, format, ap);
371  va_end(ap);
372  return res;
373}
374
375INTERCEPTOR(int, swprintf, void *str, uptr size, void *format, ...) {
376  ENSURE_MSAN_INITED();
377  va_list ap;
378  va_start(ap, format);
379  int res = vswprintf(str, size, format, ap);
380  va_end(ap);
381  return res;
382}
383
384// SIZE_T strftime(char *s, SIZE_T max, const char *format,const struct tm *tm);
385INTERCEPTOR(SIZE_T, strftime, char *s, SIZE_T max, const char *format,
386            void *tm) {
387  ENSURE_MSAN_INITED();
388  SIZE_T res = REAL(strftime)(s, max, format, tm);
389  if (res) __msan_unpoison(s, res + 1);
390  return res;
391}
392
393INTERCEPTOR(SIZE_T, wcstombs, void *dest, void *src, SIZE_T size) {
394  ENSURE_MSAN_INITED();
395  SIZE_T res = REAL(wcstombs)(dest, src, size);
396  if (res != (SIZE_T)-1) __msan_unpoison(dest, res + 1);
397  return res;
398}
399
400// SIZE_T mbstowcs(wchar_t *dest, const char *src, SIZE_T n);
401INTERCEPTOR(SIZE_T, mbstowcs, wchar_t *dest, const char *src, SIZE_T n) {
402  ENSURE_MSAN_INITED();
403  SIZE_T res = REAL(mbstowcs)(dest, src, n);
404  if (res != (SIZE_T)-1) __msan_unpoison(dest, (res + 1) * sizeof(wchar_t));
405  return res;
406}
407
408INTERCEPTOR(SIZE_T, wcslen, const wchar_t *s) {
409  ENSURE_MSAN_INITED();
410  SIZE_T res = REAL(wcslen)(s);
411  CHECK_UNPOISONED(s, sizeof(wchar_t) * (res + 1));
412  return res;
413}
414
415// wchar_t *wcschr(const wchar_t *wcs, wchar_t wc);
416INTERCEPTOR(wchar_t *, wcschr, void *s, wchar_t wc, void *ps) {
417  ENSURE_MSAN_INITED();
418  wchar_t *res = REAL(wcschr)(s, wc, ps);
419  return res;
420}
421
422// wchar_t *wcscpy(wchar_t *dest, const wchar_t *src);
423INTERCEPTOR(wchar_t *, wcscpy, wchar_t *dest, const wchar_t *src) {
424  ENSURE_MSAN_INITED();
425  wchar_t *res = REAL(wcscpy)(dest, src);
426  __msan_copy_poison(dest, src, sizeof(wchar_t) * (REAL(wcslen)(src) + 1));
427  return res;
428}
429
430// wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, SIZE_T n);
431INTERCEPTOR(wchar_t *, wmemcpy, wchar_t *dest, const wchar_t *src, SIZE_T n) {
432  ENSURE_MSAN_INITED();
433  wchar_t *res = REAL(wmemcpy)(dest, src, n);
434  __msan_copy_poison(dest, src, n * sizeof(wchar_t));
435  return res;
436}
437
438INTERCEPTOR(wchar_t *, wmemset, wchar_t *s, wchar_t c, SIZE_T n) {
439  CHECK(MEM_IS_APP(s));
440  ENSURE_MSAN_INITED();
441  wchar_t *res = (wchar_t *)fast_memset(s, c, n * sizeof(wchar_t));
442  __msan_unpoison(s, n * sizeof(wchar_t));
443  return res;
444}
445
446INTERCEPTOR(wchar_t *, wmemmove, wchar_t *dest, const wchar_t *src, SIZE_T n) {
447  ENSURE_MSAN_INITED();
448  wchar_t *res = REAL(wmemmove)(dest, src, n);
449  __msan_move_poison(dest, src, n * sizeof(wchar_t));
450  return res;
451}
452
453INTERCEPTOR(int, wcscmp, const wchar_t *s1, const wchar_t *s2) {
454  ENSURE_MSAN_INITED();
455  int res = REAL(wcscmp)(s1, s2);
456  return res;
457}
458
459INTERCEPTOR(double, wcstod, const wchar_t *nptr, wchar_t **endptr) {
460  ENSURE_MSAN_INITED();
461  double res = REAL(wcstod)(nptr, endptr);
462  __msan_unpoison(endptr, sizeof(*endptr));
463  return res;
464}
465
466// #define UNSUPPORTED(name) \
467//   INTERCEPTOR(void, name, void) {                     \
468//     Printf("MSAN: Unsupported %s\n", __FUNCTION__);   \
469//     Die();                                            \
470//   }
471
472// FIXME: intercept the following functions:
473// Note, they only matter when running without a dynamic tool.
474// UNSUPPORTED(wcscoll_l)
475// UNSUPPORTED(wcsnrtombs)
476// UNSUPPORTED(wcstol)
477// UNSUPPORTED(wcstoll)
478// UNSUPPORTED(wcstold)
479// UNSUPPORTED(wcstoul)
480// UNSUPPORTED(wcstoull)
481// UNSUPPORTED(wcsxfrm_l)
482// UNSUPPORTED(wcsdup)
483// UNSUPPORTED(wcsftime)
484// UNSUPPORTED(wcsstr)
485// UNSUPPORTED(wcsrchr)
486// UNSUPPORTED(wctob)
487
488INTERCEPTOR(int, gettimeofday, void *tv, void *tz) {
489  ENSURE_MSAN_INITED();
490  int res = REAL(gettimeofday)(tv, tz);
491  if (tv)
492    __msan_unpoison(tv, 16);
493  if (tz)
494    __msan_unpoison(tz, 8);
495  return res;
496}
497
498INTERCEPTOR(char *, fcvt, double x, int a, int *b, int *c) {
499  ENSURE_MSAN_INITED();
500  char *res = REAL(fcvt)(x, a, b, c);
501  if (!__msan_has_dynamic_component()) {
502    __msan_unpoison(b, sizeof(*b));
503    __msan_unpoison(c, sizeof(*c));
504  }
505  return res;
506}
507
508INTERCEPTOR(char *, getenv, char *name) {
509  ENSURE_MSAN_INITED();
510  char *res = REAL(getenv)(name);
511  if (!__msan_has_dynamic_component()) {
512    if (res)
513      __msan_unpoison(res, REAL(strlen)(res) + 1);
514  }
515  return res;
516}
517
518INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
519  ENSURE_MSAN_INITED();
520  int res = REAL(__fxstat)(magic, fd, buf);
521  if (!res)
522    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
523  return res;
524}
525
526INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
527  ENSURE_MSAN_INITED();
528  int res = REAL(__fxstat64)(magic, fd, buf);
529  if (!res)
530    __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
531  return res;
532}
533
534INTERCEPTOR(int, __xstat, int magic, char *path, void *buf) {
535  ENSURE_MSAN_INITED();
536  int res = REAL(__xstat)(magic, path, buf);
537  if (!res)
538    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
539  return res;
540}
541
542INTERCEPTOR(int, __xstat64, int magic, char *path, void *buf) {
543  ENSURE_MSAN_INITED();
544  int res = REAL(__xstat64)(magic, path, buf);
545  if (!res)
546    __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
547  return res;
548}
549
550INTERCEPTOR(int, __lxstat, int magic, char *path, void *buf) {
551  ENSURE_MSAN_INITED();
552  int res = REAL(__lxstat)(magic, path, buf);
553  if (!res)
554    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
555  return res;
556}
557
558INTERCEPTOR(int, __lxstat64, int magic, char *path, void *buf) {
559  ENSURE_MSAN_INITED();
560  int res = REAL(__lxstat64)(magic, path, buf);
561  if (!res)
562    __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
563  return res;
564}
565
566INTERCEPTOR(int, pipe, int pipefd[2]) {
567  if (msan_init_is_running)
568    return REAL(pipe)(pipefd);
569  ENSURE_MSAN_INITED();
570  int res = REAL(pipe)(pipefd);
571  if (!res)
572    __msan_unpoison(pipefd, sizeof(int[2]));
573  return res;
574}
575
576INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
577  ENSURE_MSAN_INITED();
578  int res = REAL(pipe2)(pipefd, flags);
579  if (!res)
580    __msan_unpoison(pipefd, sizeof(int[2]));
581  return res;
582}
583
584INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int sv[2]) {
585  ENSURE_MSAN_INITED();
586  int res = REAL(socketpair)(domain, type, protocol, sv);
587  if (!res)
588    __msan_unpoison(sv, sizeof(int[2]));
589  return res;
590}
591
592INTERCEPTOR(char *, fgets, char *s, int size, void *stream) {
593  ENSURE_MSAN_INITED();
594  char *res = REAL(fgets)(s, size, stream);
595  if (res)
596    __msan_unpoison(s, REAL(strlen)(s) + 1);
597  return res;
598}
599
600INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) {
601  ENSURE_MSAN_INITED();
602  char *res = REAL(fgets_unlocked)(s, size, stream);
603  if (res)
604    __msan_unpoison(s, REAL(strlen)(s) + 1);
605  return res;
606}
607
608INTERCEPTOR(char *, getcwd, char *buf, SIZE_T size) {
609  ENSURE_MSAN_INITED();
610  char *res = REAL(getcwd)(buf, size);
611  if (res)
612    __msan_unpoison(res, REAL(strlen)(res) + 1);
613  return res;
614}
615
616INTERCEPTOR(char *, realpath, char *path, char *abspath) {
617  ENSURE_MSAN_INITED();
618  char *res = REAL(realpath)(path, abspath);
619  if (res)
620    __msan_unpoison(abspath, REAL(strlen)(abspath) + 1);
621  return res;
622}
623
624INTERCEPTOR(int, getrlimit, int resource, void *rlim) {
625  if (msan_init_is_running)
626    return REAL(getrlimit)(resource, rlim);
627  ENSURE_MSAN_INITED();
628  int res = REAL(getrlimit)(resource, rlim);
629  if (!res)
630    __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz);
631  return res;
632}
633
634INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
635  if (msan_init_is_running)
636    return REAL(getrlimit64)(resource, rlim);
637  ENSURE_MSAN_INITED();
638  int res = REAL(getrlimit64)(resource, rlim);
639  if (!res)
640    __msan_unpoison(rlim, __sanitizer::struct_rlimit64_sz);
641  return res;
642}
643
644INTERCEPTOR(int, statfs, const char *s, void *buf) {
645  ENSURE_MSAN_INITED();
646  int res = REAL(statfs)(s, buf);
647  if (!res)
648    __msan_unpoison(buf, __sanitizer::struct_statfs_sz);
649  return res;
650}
651
652INTERCEPTOR(int, fstatfs, int fd, void *buf) {
653  ENSURE_MSAN_INITED();
654  int res = REAL(fstatfs)(fd, buf);
655  if (!res)
656    __msan_unpoison(buf, __sanitizer::struct_statfs_sz);
657  return res;
658}
659
660INTERCEPTOR(int, statfs64, const char *s, void *buf) {
661  ENSURE_MSAN_INITED();
662  int res = REAL(statfs64)(s, buf);
663  if (!res)
664    __msan_unpoison(buf, __sanitizer::struct_statfs64_sz);
665  return res;
666}
667
668INTERCEPTOR(int, fstatfs64, int fd, void *buf) {
669  ENSURE_MSAN_INITED();
670  int res = REAL(fstatfs64)(fd, buf);
671  if (!res)
672    __msan_unpoison(buf, __sanitizer::struct_statfs64_sz);
673  return res;
674}
675
676INTERCEPTOR(int, uname, void *utsname) {
677  ENSURE_MSAN_INITED();
678  int res = REAL(uname)(utsname);
679  if (!res) {
680    __msan_unpoison(utsname, __sanitizer::struct_utsname_sz);
681  }
682  return res;
683}
684
685INTERCEPTOR(int, gethostname, char *name, SIZE_T len) {
686  ENSURE_MSAN_INITED();
687  int res = REAL(gethostname)(name, len);
688  if (!res) {
689    SIZE_T real_len = REAL(strnlen)(name, len);
690    if (real_len < len)
691      ++real_len;
692    __msan_unpoison(name, real_len);
693  }
694  return res;
695}
696
697INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents,
698    int timeout) {
699  ENSURE_MSAN_INITED();
700  int res = REAL(epoll_wait)(epfd, events, maxevents, timeout);
701  if (res > 0) {
702    __msan_unpoison(events, __sanitizer::struct_epoll_event_sz * res);
703  }
704  return res;
705}
706
707INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents,
708    int timeout, void *sigmask) {
709  ENSURE_MSAN_INITED();
710  int res = REAL(epoll_pwait)(epfd, events, maxevents, timeout, sigmask);
711  if (res > 0) {
712    __msan_unpoison(events, __sanitizer::struct_epoll_event_sz * res);
713  }
714  return res;
715}
716
717INTERCEPTOR(SSIZE_T, recv, int fd, void *buf, SIZE_T len, int flags) {
718  ENSURE_MSAN_INITED();
719  SSIZE_T res = REAL(recv)(fd, buf, len, flags);
720  if (res > 0)
721    __msan_unpoison(buf, res);
722  return res;
723}
724
725INTERCEPTOR(SSIZE_T, recvfrom, int fd, void *buf, SIZE_T len, int flags,
726            void *srcaddr, int *addrlen) {
727  ENSURE_MSAN_INITED();
728  SIZE_T srcaddr_sz;
729  if (srcaddr) srcaddr_sz = *addrlen;
730  SSIZE_T res = REAL(recvfrom)(fd, buf, len, flags, srcaddr, addrlen);
731  if (res > 0) {
732    __msan_unpoison(buf, res);
733    if (srcaddr) {
734      SIZE_T sz = *addrlen;
735      __msan_unpoison(srcaddr, (sz < srcaddr_sz) ? sz : srcaddr_sz);
736    }
737  }
738  return res;
739}
740
741INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) {
742  if (CallocShouldReturnNullDueToOverflow(size, nmemb)) return 0;
743  GET_MALLOC_STACK_TRACE;
744  if (!msan_inited) {
745    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
746    const SIZE_T kCallocPoolSize = 1024;
747    static uptr calloc_memory_for_dlsym[kCallocPoolSize];
748    static SIZE_T allocated;
749    SIZE_T size_in_words = ((nmemb * size) + kWordSize - 1) / kWordSize;
750    void *mem = (void*)&calloc_memory_for_dlsym[allocated];
751    allocated += size_in_words;
752    CHECK(allocated < kCallocPoolSize);
753    return mem;
754  }
755  return MsanReallocate(&stack, 0, nmemb * size, sizeof(u64), true);
756}
757
758INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {
759  GET_MALLOC_STACK_TRACE;
760  return MsanReallocate(&stack, ptr, size, sizeof(u64), false);
761}
762
763INTERCEPTOR(void *, malloc, SIZE_T size) {
764  GET_MALLOC_STACK_TRACE;
765  return MsanReallocate(&stack, 0, size, sizeof(u64), false);
766}
767
768void __msan_allocated_memory(const void* data, uptr size) {
769  GET_MALLOC_STACK_TRACE;
770  if (flags()->poison_in_malloc)
771    __msan_poison(data, size);
772  if (__msan_get_track_origins()) {
773    u32 stack_id = StackDepotPut(stack.trace, stack.size);
774    CHECK(stack_id);
775    CHECK_EQ((stack_id >> 31), 0);  // Higher bit is occupied by stack origins.
776    __msan_set_origin(data, size, stack_id);
777  }
778}
779
780INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
781            int fd, OFF_T offset) {
782  ENSURE_MSAN_INITED();
783  void *res = REAL(mmap)(addr, length, prot, flags, fd, offset);
784  if (res != (void*)-1)
785    __msan_unpoison(res, RoundUpTo(length, GetPageSize()));
786  return res;
787}
788
789INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags,
790            int fd, OFF64_T offset) {
791  ENSURE_MSAN_INITED();
792  void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset);
793  if (res != (void*)-1)
794    __msan_unpoison(res, RoundUpTo(length, GetPageSize()));
795  return res;
796}
797
798struct dlinfo {
799  char *dli_fname;
800  void *dli_fbase;
801  char *dli_sname;
802  void *dli_saddr;
803};
804
805INTERCEPTOR(int, dladdr, void *addr, dlinfo *info) {
806  ENSURE_MSAN_INITED();
807  int res = REAL(dladdr)(addr, info);
808  if (res != 0) {
809    __msan_unpoison(info, sizeof(*info));
810    if (info->dli_fname)
811      __msan_unpoison(info->dli_fname, REAL(strlen)(info->dli_fname) + 1);
812    if (info->dli_sname)
813      __msan_unpoison(info->dli_sname, REAL(strlen)(info->dli_sname) + 1);
814  }
815  return res;
816}
817
818// dlopen() ultimately calls mmap() down inside the loader, which generally
819// doesn't participate in dynamic symbol resolution.  Therefore we won't
820// intercept its calls to mmap, and we have to hook it here.  The loader
821// initializes the module before returning, so without the dynamic component, we
822// won't be able to clear the shadow before the initializers.  Fixing this would
823// require putting our own initializer first to clear the shadow.
824INTERCEPTOR(void *, dlopen, const char *filename, int flag) {
825  ENSURE_MSAN_INITED();
826  EnterLoader();
827  link_map *map = (link_map *)REAL(dlopen)(filename, flag);
828  ExitLoader();
829  if (!__msan_has_dynamic_component() && map) {
830    // If msandr didn't clear the shadow before the initializers ran, we do it
831    // ourselves afterwards.
832    UnpoisonMappedDSO(map);
833  }
834  return (void *)map;
835}
836
837typedef int (*dl_iterate_phdr_cb)(__sanitizer_dl_phdr_info *info, SIZE_T size,
838                                  void *data);
839struct dl_iterate_phdr_data {
840  dl_iterate_phdr_cb callback;
841  void *data;
842};
843
844static int msan_dl_iterate_phdr_cb(__sanitizer_dl_phdr_info *info, SIZE_T size,
845                                   void *data) {
846  if (info) {
847    __msan_unpoison(info, size);
848    if (info->dlpi_name)
849      __msan_unpoison(info->dlpi_name, REAL(strlen)(info->dlpi_name) + 1);
850  }
851  dl_iterate_phdr_data *cbdata = (dl_iterate_phdr_data *)data;
852  UnpoisonParam(3);
853  return cbdata->callback(info, size, cbdata->data);
854}
855
856INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
857  ENSURE_MSAN_INITED();
858  EnterLoader();
859  dl_iterate_phdr_data cbdata;
860  cbdata.callback = callback;
861  cbdata.data = data;
862  int res = REAL(dl_iterate_phdr)(msan_dl_iterate_phdr_cb, (void *)&cbdata);
863  ExitLoader();
864  return res;
865}
866
867INTERCEPTOR(int, getrusage, int who, void *usage) {
868  ENSURE_MSAN_INITED();
869  int res = REAL(getrusage)(who, usage);
870  if (res == 0) {
871    __msan_unpoison(usage, __sanitizer::struct_rusage_sz);
872  }
873  return res;
874}
875
876const int kMaxSignals = 1024;
877static uptr sigactions[kMaxSignals];
878static StaticSpinMutex sigactions_mu;
879
880static void SignalHandler(int signo) {
881  typedef void (*signal_cb)(int x);
882  signal_cb cb = (signal_cb)sigactions[signo];
883  cb(signo);
884}
885
886static void SignalAction(int signo, void *si, void *uc) {
887  UnpoisonParam(3);
888  __msan_unpoison(si, __sanitizer::struct_sigaction_sz);
889  __msan_unpoison(uc, __sanitizer::ucontext_t_sz);
890
891  typedef void (*sigaction_cb)(int, void *, void *);
892  sigaction_cb cb = (sigaction_cb)sigactions[signo];
893  cb(signo, si, uc);
894}
895
896INTERCEPTOR(int, sigaction, int signo, const __sanitizer_sigaction *act,
897            __sanitizer_sigaction *oldact) {
898  ENSURE_MSAN_INITED();
899  // FIXME: check that *act is unpoisoned.
900  // That requires intercepting all of sigemptyset, sigfillset, etc.
901  int res;
902  if (flags()->wrap_signals) {
903    SpinMutexLock lock(&sigactions_mu);
904    CHECK_LT(signo, kMaxSignals);
905    uptr old_cb = sigactions[signo];
906    __sanitizer_sigaction new_act;
907    __sanitizer_sigaction *pnew_act = act ? &new_act : 0;
908    if (act) {
909      internal_memcpy(pnew_act, act, __sanitizer::struct_sigaction_sz);
910      uptr cb = __sanitizer::__sanitizer_get_sigaction_sa_sigaction(pnew_act);
911      uptr new_cb =
912          __sanitizer::__sanitizer_get_sigaction_sa_siginfo(pnew_act) ?
913          (uptr)SignalAction : (uptr)SignalHandler;
914      if (cb != __sanitizer::sig_ign && cb != __sanitizer::sig_dfl) {
915        sigactions[signo] = cb;
916        __sanitizer::__sanitizer_set_sigaction_sa_sigaction(pnew_act, new_cb);
917      }
918    }
919    res = REAL(sigaction)(signo, pnew_act, oldact);
920    if (res == 0 && oldact) {
921      uptr cb = __sanitizer::__sanitizer_get_sigaction_sa_sigaction(oldact);
922      if (cb != __sanitizer::sig_ign && cb != __sanitizer::sig_dfl) {
923        __sanitizer::__sanitizer_set_sigaction_sa_sigaction(oldact, old_cb);
924      }
925    }
926  } else {
927    res = REAL(sigaction)(signo, act, oldact);
928  }
929
930  if (res == 0 && oldact) {
931    __msan_unpoison(oldact, __sanitizer::struct_sigaction_sz);
932  }
933  return res;
934}
935
936INTERCEPTOR(int, signal, int signo, uptr cb) {
937  ENSURE_MSAN_INITED();
938  if (flags()->wrap_signals) {
939    CHECK_LT(signo, kMaxSignals);
940    SpinMutexLock lock(&sigactions_mu);
941    if (cb != __sanitizer::sig_ign && cb != __sanitizer::sig_dfl) {
942      sigactions[signo] = cb;
943      cb = (uptr) SignalHandler;
944    }
945    return REAL(signal)(signo, cb);
946  } else {
947    return REAL(signal)(signo, cb);
948  }
949}
950
951extern "C" int pthread_attr_init(void *attr);
952extern "C" int pthread_attr_destroy(void *attr);
953extern "C" int pthread_attr_setstacksize(void *attr, uptr stacksize);
954extern "C" int pthread_attr_getstack(void *attr, uptr *stack, uptr *stacksize);
955
956INTERCEPTOR(int, pthread_create, void *th, void *attr, void *(*callback)(void*),
957            void * param) {
958  ENSURE_MSAN_INITED(); // for GetTlsSize()
959  __sanitizer_pthread_attr_t myattr;
960  if (attr == 0) {
961    pthread_attr_init(&myattr);
962    attr = &myattr;
963  }
964
965  AdjustStackSizeLinux(attr, flags()->verbosity);
966
967  int res = REAL(pthread_create)(th, attr, callback, param);
968  if (attr == &myattr)
969    pthread_attr_destroy(&myattr);
970  if (!res) {
971    __msan_unpoison(th, __sanitizer::pthread_t_sz);
972  }
973  return res;
974}
975
976struct MSanInterceptorContext {
977  bool in_interceptor_scope;
978};
979
980// A version of CHECK_UNPOISED using a saved scope value. Used in common
981// interceptors.
982#define CHECK_UNPOISONED_CTX(ctx, x, n)                         \
983  do {                                                          \
984    if (!((MSanInterceptorContext *)ctx)->in_interceptor_scope) \
985      CHECK_UNPOISONED_0(x, n);                                 \
986  } while (0)
987
988#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \
989  __msan_unpoison(ptr, size)
990#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
991  CHECK_UNPOISONED_CTX(ctx, ptr, size)
992#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)              \
993  if (msan_init_is_running) return REAL(func)(__VA_ARGS__);   \
994  MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \
995  ctx = (void *)&msan_ctx;                                    \
996  InterceptorScope interceptor_scope;                         \
997  ENSURE_MSAN_INITED();
998#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
999  do {                                         \
1000  } while (false)
1001#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
1002  do {                                         \
1003  } while (false)
1004#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
1005  do {                                                      \
1006  } while (false)
1007#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \
1008  do {                                                \
1009  } while (false)  // FIXME
1010#include "sanitizer_common/sanitizer_common_interceptors.inc"
1011
1012#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) CHECK_UNPOISONED(p, s)
1013#define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s)
1014#define COMMON_SYSCALL_POST_READ_RANGE(p, s)
1015#define COMMON_SYSCALL_POST_WRITE_RANGE(p, s) __msan_unpoison(p, s)
1016#include "sanitizer_common/sanitizer_common_syscalls.inc"
1017
1018// static
1019void *fast_memset(void *ptr, int c, SIZE_T n) {
1020  // hack until we have a really fast internal_memset
1021  if (sizeof(uptr) == 8 &&
1022      (n % 8) == 0 &&
1023      ((uptr)ptr % 8) == 0 &&
1024      (c == 0 || c == -1)) {
1025    // Printf("memset %p %zd %x\n", ptr, n, c);
1026    uptr to_store = c ? -1L : 0L;
1027    uptr *p = (uptr*)ptr;
1028    for (SIZE_T i = 0; i < n / 8; i++)
1029      p[i] = to_store;
1030    return ptr;
1031  }
1032  return internal_memset(ptr, c, n);
1033}
1034
1035// static
1036void *fast_memcpy(void *dst, const void *src, SIZE_T n) {
1037  // Same hack as in fast_memset above.
1038  if (sizeof(uptr) == 8 &&
1039      (n % 8) == 0 &&
1040      ((uptr)dst % 8) == 0 &&
1041      ((uptr)src % 8) == 0) {
1042    uptr *d = (uptr*)dst;
1043    uptr *s = (uptr*)src;
1044    for (SIZE_T i = 0; i < n / 8; i++)
1045      d[i] = s[i];
1046    return dst;
1047  }
1048  return internal_memcpy(dst, src, n);
1049}
1050
1051// These interface functions reside here so that they can use
1052// fast_memset, etc.
1053void __msan_unpoison(const void *a, uptr size) {
1054  if (!MEM_IS_APP(a)) return;
1055  fast_memset((void*)MEM_TO_SHADOW((uptr)a), 0, size);
1056}
1057
1058void __msan_poison(const void *a, uptr size) {
1059  if (!MEM_IS_APP(a)) return;
1060  fast_memset((void*)MEM_TO_SHADOW((uptr)a),
1061              __msan::flags()->poison_heap_with_zeroes ? 0 : -1, size);
1062}
1063
1064void __msan_poison_stack(void *a, uptr size) {
1065  if (!MEM_IS_APP(a)) return;
1066  fast_memset((void*)MEM_TO_SHADOW((uptr)a),
1067              __msan::flags()->poison_stack_with_zeroes ? 0 : -1, size);
1068}
1069
1070void __msan_clear_and_unpoison(void *a, uptr size) {
1071  fast_memset(a, 0, size);
1072  fast_memset((void*)MEM_TO_SHADOW((uptr)a), 0, size);
1073}
1074
1075void __msan_copy_origin(void *dst, const void *src, uptr size) {
1076  if (!__msan_get_track_origins()) return;
1077  if (!MEM_IS_APP(dst) || !MEM_IS_APP(src)) return;
1078  uptr d = MEM_TO_ORIGIN(dst);
1079  uptr s = MEM_TO_ORIGIN(src);
1080  uptr beg = d & ~3UL;  // align down.
1081  uptr end = (d + size + 3) & ~3UL;  // align up.
1082  s = s & ~3UL;  // align down.
1083  fast_memcpy((void*)beg, (void*)s, end - beg);
1084}
1085
1086void __msan_copy_poison(void *dst, const void *src, uptr size) {
1087  if (!MEM_IS_APP(dst)) return;
1088  if (!MEM_IS_APP(src)) return;
1089  fast_memcpy((void*)MEM_TO_SHADOW((uptr)dst),
1090              (void*)MEM_TO_SHADOW((uptr)src), size);
1091  __msan_copy_origin(dst, src, size);
1092}
1093
1094void __msan_move_poison(void *dst, const void *src, uptr size) {
1095  if (!MEM_IS_APP(dst)) return;
1096  if (!MEM_IS_APP(src)) return;
1097  internal_memmove((void*)MEM_TO_SHADOW((uptr)dst),
1098         (void*)MEM_TO_SHADOW((uptr)src), size);
1099  __msan_copy_origin(dst, src, size);
1100}
1101
1102void *__msan_memcpy(void *dest, const void *src, SIZE_T n) {
1103  ENSURE_MSAN_INITED();
1104  void *res = fast_memcpy(dest, src, n);
1105  __msan_copy_poison(dest, src, n);
1106  return res;
1107}
1108
1109void *__msan_memset(void *s, int c, SIZE_T n) {
1110  ENSURE_MSAN_INITED();
1111  void *res = fast_memset(s, c, n);
1112  __msan_unpoison(s, n);
1113  return res;
1114}
1115
1116void *__msan_memmove(void *dest, const void *src, SIZE_T n) {
1117  ENSURE_MSAN_INITED();
1118  void *res = REAL(memmove)(dest, src, n);
1119  __msan_move_poison(dest, src, n);
1120  return res;
1121}
1122
1123namespace __msan {
1124void InitializeInterceptors() {
1125  static int inited = 0;
1126  CHECK_EQ(inited, 0);
1127  SANITIZER_COMMON_INTERCEPTORS_INIT;
1128
1129  INTERCEPT_FUNCTION(mmap);
1130  INTERCEPT_FUNCTION(mmap64);
1131  INTERCEPT_FUNCTION(posix_memalign);
1132  INTERCEPT_FUNCTION(malloc);
1133  INTERCEPT_FUNCTION(calloc);
1134  INTERCEPT_FUNCTION(realloc);
1135  INTERCEPT_FUNCTION(free);
1136  INTERCEPT_FUNCTION(fread);
1137  INTERCEPT_FUNCTION(fread_unlocked);
1138  INTERCEPT_FUNCTION(readlink);
1139  INTERCEPT_FUNCTION(memcpy);
1140  INTERCEPT_FUNCTION(memset);
1141  INTERCEPT_FUNCTION(memmove);
1142  INTERCEPT_FUNCTION(wmemset);
1143  INTERCEPT_FUNCTION(wmemcpy);
1144  INTERCEPT_FUNCTION(wmemmove);
1145  INTERCEPT_FUNCTION(strcpy);  // NOLINT
1146  INTERCEPT_FUNCTION(stpcpy);  // NOLINT
1147  INTERCEPT_FUNCTION(strdup);
1148  INTERCEPT_FUNCTION(__strdup);
1149  INTERCEPT_FUNCTION(strndup);
1150  INTERCEPT_FUNCTION(__strndup);
1151  INTERCEPT_FUNCTION(strncpy);  // NOLINT
1152  INTERCEPT_FUNCTION(strlen);
1153  INTERCEPT_FUNCTION(strnlen);
1154  INTERCEPT_FUNCTION(gcvt);
1155  INTERCEPT_FUNCTION(strcat);  // NOLINT
1156  INTERCEPT_FUNCTION(strncat);  // NOLINT
1157  INTERCEPT_FUNCTION(strtol);
1158  INTERCEPT_FUNCTION(strtoll);
1159  INTERCEPT_FUNCTION(strtoul);
1160  INTERCEPT_FUNCTION(strtoull);
1161  INTERCEPT_FUNCTION(strtod);
1162  INTERCEPT_FUNCTION(strtof);
1163  INTERCEPT_FUNCTION(strtold);
1164  INTERCEPT_FUNCTION(vasprintf);
1165  INTERCEPT_FUNCTION(asprintf);
1166  INTERCEPT_FUNCTION(vsprintf);
1167  INTERCEPT_FUNCTION(vsnprintf);
1168  INTERCEPT_FUNCTION(vswprintf);
1169  INTERCEPT_FUNCTION(sprintf);  // NOLINT
1170  INTERCEPT_FUNCTION(snprintf);
1171  INTERCEPT_FUNCTION(swprintf);
1172  INTERCEPT_FUNCTION(strftime);
1173  INTERCEPT_FUNCTION(wcstombs);
1174  INTERCEPT_FUNCTION(mbstowcs);
1175  INTERCEPT_FUNCTION(wcslen);
1176  INTERCEPT_FUNCTION(wcschr);
1177  INTERCEPT_FUNCTION(wcscpy);
1178  INTERCEPT_FUNCTION(wcscmp);
1179  INTERCEPT_FUNCTION(wcstod);
1180  INTERCEPT_FUNCTION(getenv);
1181  INTERCEPT_FUNCTION(gettimeofday);
1182  INTERCEPT_FUNCTION(fcvt);
1183  INTERCEPT_FUNCTION(__fxstat);
1184  INTERCEPT_FUNCTION(__xstat);
1185  INTERCEPT_FUNCTION(__lxstat);
1186  INTERCEPT_FUNCTION(__fxstat64);
1187  INTERCEPT_FUNCTION(__xstat64);
1188  INTERCEPT_FUNCTION(__lxstat64);
1189  INTERCEPT_FUNCTION(pipe);
1190  INTERCEPT_FUNCTION(pipe2);
1191  INTERCEPT_FUNCTION(socketpair);
1192  INTERCEPT_FUNCTION(fgets);
1193  INTERCEPT_FUNCTION(fgets_unlocked);
1194  INTERCEPT_FUNCTION(getcwd);
1195  INTERCEPT_FUNCTION(realpath);
1196  INTERCEPT_FUNCTION(getrlimit);
1197  INTERCEPT_FUNCTION(getrlimit64);
1198  INTERCEPT_FUNCTION(statfs);
1199  INTERCEPT_FUNCTION(fstatfs);
1200  INTERCEPT_FUNCTION(statfs64);
1201  INTERCEPT_FUNCTION(fstatfs64);
1202  INTERCEPT_FUNCTION(uname);
1203  INTERCEPT_FUNCTION(gethostname);
1204  INTERCEPT_FUNCTION(epoll_wait);
1205  INTERCEPT_FUNCTION(epoll_pwait);
1206  INTERCEPT_FUNCTION(recv);
1207  INTERCEPT_FUNCTION(recvfrom);
1208  INTERCEPT_FUNCTION(dladdr);
1209  INTERCEPT_FUNCTION(dlopen);
1210  INTERCEPT_FUNCTION(dl_iterate_phdr);
1211  INTERCEPT_FUNCTION(getrusage);
1212  INTERCEPT_FUNCTION(sigaction);
1213  INTERCEPT_FUNCTION(signal);
1214  INTERCEPT_FUNCTION(pthread_create);
1215  inited = 1;
1216}
1217}  // namespace __msan
1218