2012-05-31 21:42:53 +08:00
|
|
|
//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
|
2012-05-29 20:18:18 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
// These tools can not use some of the libc functions directly because those
|
|
|
|
// functions are intercepted. Instead, we implement a tiny subset of libc here.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-05-31 22:11:07 +08:00
|
|
|
#ifndef SANITIZER_LIBC_H
|
|
|
|
#define SANITIZER_LIBC_H
|
2012-05-29 20:18:18 +08:00
|
|
|
|
2012-06-05 22:25:27 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2012-06-04 18:30:16 +08:00
|
|
|
|
2012-05-29 20:18:18 +08:00
|
|
|
namespace __sanitizer {
|
|
|
|
|
2012-06-04 18:30:16 +08:00
|
|
|
// internal_X() is a custom implementation of X() for use in RTL.
|
2012-06-05 17:49:25 +08:00
|
|
|
|
|
|
|
// String functions
|
2012-06-15 21:09:52 +08:00
|
|
|
s64 internal_atoll(const char *nptr);
|
2012-06-05 17:49:25 +08:00
|
|
|
void *internal_memchr(const void *s, int c, uptr n);
|
2012-06-14 22:04:54 +08:00
|
|
|
int internal_memcmp(const void* s1, const void* s2, uptr n);
|
2012-06-07 19:54:08 +08:00
|
|
|
void *internal_memcpy(void *dest, const void *src, uptr n);
|
2012-06-08 22:11:12 +08:00
|
|
|
// Should not be used in performance-critical places.
|
|
|
|
void *internal_memset(void *s, int c, uptr n);
|
2012-06-15 20:24:07 +08:00
|
|
|
char* internal_strchr(const char *s, int c);
|
2012-06-04 21:27:49 +08:00
|
|
|
int internal_strcmp(const char *s1, const char *s2);
|
2012-06-07 19:54:08 +08:00
|
|
|
char *internal_strdup(const char *s);
|
2012-06-06 17:26:25 +08:00
|
|
|
uptr internal_strlen(const char *s);
|
2012-06-15 21:09:52 +08:00
|
|
|
char *internal_strncat(char *dst, const char *src, uptr n);
|
2012-06-04 18:30:16 +08:00
|
|
|
char *internal_strncpy(char *dst, const char *src, uptr n);
|
2012-06-15 21:09:52 +08:00
|
|
|
uptr internal_strnlen(const char *s, uptr maxlen);
|
2012-06-08 22:11:12 +08:00
|
|
|
char *internal_strrchr(const char *s, int c);
|
2012-06-15 21:09:52 +08:00
|
|
|
// This is O(N^2), but we are not using it in hot places.
|
|
|
|
char *internal_strstr(const char *haystack, const char *needle);
|
|
|
|
// Works only for base=10 and doesn't set errno.
|
|
|
|
s64 internal_simple_strtoll(const char *nptr, char **endptr, int base);
|
2012-06-04 18:30:16 +08:00
|
|
|
|
2012-06-05 17:49:25 +08:00
|
|
|
// Memory
|
2012-06-04 22:27:50 +08:00
|
|
|
void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
|
|
|
int fd, u64 offset);
|
2012-06-05 17:49:25 +08:00
|
|
|
int internal_munmap(void *addr, uptr length);
|
2012-06-05 15:05:10 +08:00
|
|
|
|
2012-06-05 17:49:25 +08:00
|
|
|
// I/O
|
2012-06-05 15:05:10 +08:00
|
|
|
typedef int fd_t;
|
2012-06-05 16:32:53 +08:00
|
|
|
const fd_t kInvalidFd = -1;
|
|
|
|
int internal_close(fd_t fd);
|
2012-06-05 15:05:10 +08:00
|
|
|
fd_t internal_open(const char *filename, bool write);
|
2012-06-05 16:32:53 +08:00
|
|
|
uptr internal_read(fd_t fd, void *buf, uptr count);
|
|
|
|
uptr internal_write(fd_t fd, const void *buf, uptr count);
|
2012-06-06 15:30:33 +08:00
|
|
|
uptr internal_filesize(fd_t fd); // -1 on error.
|
|
|
|
int internal_dup2(int oldfd, int newfd);
|
2012-06-05 17:49:25 +08:00
|
|
|
int internal_sscanf(const char *str, const char *format, ...);
|
2012-06-04 22:27:50 +08:00
|
|
|
|
2012-05-29 20:18:18 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
#endif // SANITIZER_LIBC_H
|