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