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