sanitizer_libc.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is shared between AddressSanitizer and ThreadSanitizer
  10. // run-time libraries.
  11. // These tools can not use some of the libc functions directly because those
  12. // functions are intercepted. Instead, we implement a tiny subset of libc here.
  13. // FIXME: Some of functions declared in this file are in fact POSIX, not libc.
  14. //===----------------------------------------------------------------------===//
  15. #ifndef SANITIZER_LIBC_H
  16. #define SANITIZER_LIBC_H
  17. // ----------- ATTENTION -------------
  18. // This header should NOT include any other headers from sanitizer runtime.
  19. #include "sanitizer_internal_defs.h"
  20. namespace __sanitizer {
  21. // internal_X() is a custom implementation of X() for use in RTL.
  22. // String functions
  23. s64 internal_atoll(const char *nptr);
  24. void *internal_memchr(const void *s, int c, uptr n);
  25. void *internal_memrchr(const void *s, int c, uptr n);
  26. int internal_memcmp(const void* s1, const void* s2, uptr n);
  27. void *internal_memcpy(void *dest, const void *src, uptr n);
  28. void *internal_memmove(void *dest, const void *src, uptr n);
  29. // Should not be used in performance-critical places.
  30. void *internal_memset(void *s, int c, uptr n);
  31. char* internal_strchr(const char *s, int c);
  32. char *internal_strchrnul(const char *s, int c);
  33. int internal_strcmp(const char *s1, const char *s2);
  34. uptr internal_strcspn(const char *s, const char *reject);
  35. char *internal_strdup(const char *s);
  36. uptr internal_strlen(const char *s);
  37. uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
  38. char *internal_strncat(char *dst, const char *src, uptr n);
  39. int internal_strncmp(const char *s1, const char *s2, uptr n);
  40. uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
  41. char *internal_strncpy(char *dst, const char *src, uptr n);
  42. uptr internal_strnlen(const char *s, uptr maxlen);
  43. char *internal_strrchr(const char *s, int c);
  44. char *internal_strstr(const char *haystack, const char *needle);
  45. // Works only for base=10 and doesn't set errno.
  46. s64 internal_simple_strtoll(const char *nptr, const char **endptr, int base);
  47. int internal_snprintf(char *buffer, uptr length, const char *format, ...)
  48. FORMAT(3, 4);
  49. uptr internal_wcslen(const wchar_t *s);
  50. uptr internal_wcsnlen(const wchar_t *s, uptr maxlen);
  51. // Return true if all bytes in [mem, mem+size) are zero.
  52. // Optimized for the case when the result is true.
  53. bool mem_is_zero(const char *mem, uptr size);
  54. // I/O
  55. // Define these as macros so we can use them in linker initialized global
  56. // structs without dynamic initialization.
  57. #define kInvalidFd ((fd_t)-1)
  58. #define kStdinFd ((fd_t)0)
  59. #define kStdoutFd ((fd_t)1)
  60. #define kStderrFd ((fd_t)2)
  61. uptr internal_ftruncate(fd_t fd, uptr size);
  62. // OS
  63. void NORETURN internal__exit(int exitcode);
  64. void internal_sleep(unsigned seconds);
  65. void internal_usleep(u64 useconds);
  66. uptr internal_getpid();
  67. uptr internal_getppid();
  68. int internal_dlinfo(void *handle, int request, void *p);
  69. // Threading
  70. uptr internal_sched_yield();
  71. // Error handling
  72. bool internal_iserror(uptr retval, int *rverrno = nullptr);
  73. } // namespace __sanitizer
  74. #endif // SANITIZER_LIBC_H