sanitizer_libc.h revision f1673e61768cb08d488a75584b61bfdf24ffdac1
1//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===// 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 shared between AddressSanitizer and ThreadSanitizer 11// run-time libraries. 12// These tools can not use some of the libc functions directly because those 13// functions are intercepted. Instead, we implement a tiny subset of libc here. 14// NOTE: This file may be included into user code. 15//===----------------------------------------------------------------------===// 16#ifndef SANITIZER_LIBC_H 17#define SANITIZER_LIBC_H 18 19// ----------- ATTENTION ------------- 20// This header should NOT include any other headers from sanitizer runtime. 21#include "sanitizer/common_interface_defs.h" 22 23namespace __sanitizer { 24 25// internal_X() is a custom implementation of X() for use in RTL. 26 27// String functions 28s64 internal_atoll(const char *nptr); 29void *internal_memchr(const void *s, int c, uptr n); 30int internal_memcmp(const void* s1, const void* s2, uptr n); 31void *internal_memcpy(void *dest, const void *src, uptr n); 32void *internal_memmove(void *dest, const void *src, uptr n); 33// Should not be used in performance-critical places. 34void *internal_memset(void *s, int c, uptr n); 35char* internal_strchr(const char *s, int c); 36int internal_strcmp(const char *s1, const char *s2); 37uptr internal_strcspn(const char *s, const char *reject); 38char *internal_strdup(const char *s); 39uptr internal_strlen(const char *s); 40char *internal_strncat(char *dst, const char *src, uptr n); 41int internal_strncmp(const char *s1, const char *s2, uptr n); 42char *internal_strncpy(char *dst, const char *src, uptr n); 43uptr internal_strnlen(const char *s, uptr maxlen); 44char *internal_strrchr(const char *s, int c); 45// This is O(N^2), but we are not using it in hot places. 46char *internal_strstr(const char *haystack, const char *needle); 47// Works only for base=10 and doesn't set errno. 48s64 internal_simple_strtoll(const char *nptr, char **endptr, int base); 49 50// Memory 51void *internal_mmap(void *addr, uptr length, int prot, int flags, 52 int fd, u64 offset); 53int internal_munmap(void *addr, uptr length); 54 55// I/O 56typedef int fd_t; 57const fd_t kInvalidFd = -1; 58int internal_close(fd_t fd); 59fd_t internal_open(const char *filename, bool write); 60uptr internal_read(fd_t fd, void *buf, uptr count); 61uptr internal_write(fd_t fd, const void *buf, uptr count); 62uptr internal_filesize(fd_t fd); // -1 on error. 63int internal_dup2(int oldfd, int newfd); 64uptr internal_readlink(const char *path, char *buf, uptr bufsize); 65int internal_snprintf(char *buffer, uptr length, const char *format, ...); 66 67// Threading 68int internal_sched_yield(); 69 70} // namespace __sanitizer 71 72#endif // SANITIZER_LIBC_H 73