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-19 16:52:02 +08:00
|
|
|
// ----------- ATTENTION -------------
|
|
|
|
// This header should NOT include any other headers from sanitizer runtime.
|
2013-01-30 21:12:08 +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-10-15 23:34:41 +08:00
|
|
|
void *internal_memmove(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-08-21 17:26:26 +08:00
|
|
|
uptr internal_strcspn(const char *s, const char *reject);
|
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-18 22:34:59 +08:00
|
|
|
int internal_strncmp(const char *s1, const char *s2, 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);
|
2013-02-20 21:54:32 +08:00
|
|
|
int internal_snprintf(char *buffer, uptr length, const char *format, ...);
|
2012-06-04 18:30:16 +08:00
|
|
|
|
2012-12-28 23:24:16 +08:00
|
|
|
// Return true if all bytes in [mem, mem+size) are zero.
|
|
|
|
// Optimized for the case when the result is true.
|
|
|
|
bool mem_is_zero(const char *mem, uptr size);
|
|
|
|
|
|
|
|
|
2012-06-05 17:49:25 +08:00
|
|
|
// Memory
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_mmap(void *addr, uptr length, int prot, int flags,
|
|
|
|
int fd, u64 offset);
|
|
|
|
uptr 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 16:32:53 +08:00
|
|
|
const fd_t kInvalidFd = -1;
|
2012-11-02 17:38:47 +08:00
|
|
|
const fd_t kStdinFd = 0;
|
|
|
|
const fd_t kStdoutFd = 1;
|
|
|
|
const fd_t kStderrFd = 2;
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_close(fd_t fd);
|
2012-11-02 23:18:34 +08:00
|
|
|
int internal_isatty(fd_t fd);
|
2013-02-01 23:58:46 +08:00
|
|
|
|
|
|
|
// Use __sanitizer::OpenFile() instead.
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_open(const char *filename, int flags);
|
|
|
|
uptr internal_open(const char *filename, int flags, u32 mode);
|
2013-02-01 23:58:46 +08:00
|
|
|
|
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);
|
2013-02-20 21:54:32 +08:00
|
|
|
|
|
|
|
// OS
|
2012-06-06 15:30:33 +08:00
|
|
|
uptr internal_filesize(fd_t fd); // -1 on error.
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_stat(const char *path, void *buf);
|
|
|
|
uptr internal_lstat(const char *path, void *buf);
|
|
|
|
uptr internal_fstat(fd_t fd, void *buf);
|
|
|
|
uptr internal_dup2(int oldfd, int newfd);
|
2012-09-05 22:48:24 +08:00
|
|
|
uptr internal_readlink(const char *path, char *buf, uptr bufsize);
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_unlink(const char *path);
|
2013-02-20 21:54:32 +08:00
|
|
|
void NORETURN internal__exit(int exitcode);
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
|
2013-02-27 19:22:40 +08:00
|
|
|
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_ptrace(int request, int pid, void *addr, void *data);
|
|
|
|
uptr internal_waitpid(int pid, int *status, int options);
|
2013-05-18 00:56:53 +08:00
|
|
|
uptr internal_getpid();
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_getppid();
|
2012-06-04 22:27:50 +08:00
|
|
|
|
2012-06-18 16:44:30 +08:00
|
|
|
// Threading
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_sched_yield();
|
|
|
|
|
|
|
|
// Error handling
|
|
|
|
bool internal_iserror(uptr retval, int *rverrno = 0);
|
2012-06-18 16:44:30 +08:00
|
|
|
|
2012-05-29 20:18:18 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
#endif // SANITIZER_LIBC_H
|