2012-11-12 16:53:47 +01:00
|
|
|
//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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.
|
2015-10-21 09:32:45 +02:00
|
|
|
// FIXME: Some of functions declared in this file are in fact POSIX, not libc.
|
2012-11-12 16:53:47 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
#ifndef SANITIZER_LIBC_H
|
|
|
|
#define SANITIZER_LIBC_H
|
|
|
|
|
|
|
|
// ----------- ATTENTION -------------
|
|
|
|
// This header should NOT include any other headers from sanitizer runtime.
|
2013-02-13 11:46:01 +01:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
// internal_X() is a custom implementation of X() for use in RTL.
|
|
|
|
|
|
|
|
// String functions
|
|
|
|
s64 internal_atoll(const char *nptr);
|
|
|
|
void *internal_memchr(const void *s, int c, uptr n);
|
2015-10-21 09:32:45 +02:00
|
|
|
void *internal_memrchr(const void *s, int c, uptr n);
|
2012-11-12 16:53:47 +01:00
|
|
|
int internal_memcmp(const void* s1, const void* s2, uptr n);
|
|
|
|
void *internal_memcpy(void *dest, const void *src, uptr n);
|
2012-11-23 15:46:25 +01:00
|
|
|
void *internal_memmove(void *dest, const void *src, uptr n);
|
2012-11-12 16:53:47 +01:00
|
|
|
// Should not be used in performance-critical places.
|
|
|
|
void *internal_memset(void *s, int c, uptr n);
|
|
|
|
char* internal_strchr(const char *s, int c);
|
2013-11-04 22:33:31 +01:00
|
|
|
char *internal_strchrnul(const char *s, int c);
|
2012-11-12 16:53:47 +01:00
|
|
|
int internal_strcmp(const char *s1, const char *s2);
|
|
|
|
uptr internal_strcspn(const char *s, const char *reject);
|
|
|
|
char *internal_strdup(const char *s);
|
|
|
|
uptr internal_strlen(const char *s);
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
|
2012-11-12 16:53:47 +01:00
|
|
|
char *internal_strncat(char *dst, const char *src, uptr n);
|
|
|
|
int internal_strncmp(const char *s1, const char *s2, uptr n);
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
|
2012-11-12 16:53:47 +01:00
|
|
|
char *internal_strncpy(char *dst, const char *src, uptr n);
|
|
|
|
uptr internal_strnlen(const char *s, uptr maxlen);
|
|
|
|
char *internal_strrchr(const char *s, int c);
|
|
|
|
char *internal_strstr(const char *haystack, const char *needle);
|
|
|
|
// Works only for base=10 and doesn't set errno.
|
2018-10-31 12:14:23 +01:00
|
|
|
s64 internal_simple_strtoll(const char *nptr, const char **endptr, int base);
|
2013-02-21 11:57:10 +01:00
|
|
|
int internal_snprintf(char *buffer, uptr length, const char *format, ...);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-01-10 13:44:08 +01: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-11-12 16:53:47 +01:00
|
|
|
// I/O
|
2016-11-08 23:04:09 +01:00
|
|
|
// Define these as macros so we can use them in linker initialized global
|
|
|
|
// structs without dynamic initialization.
|
|
|
|
#define kInvalidFd ((fd_t)-1)
|
|
|
|
#define kStdinFd ((fd_t)0)
|
|
|
|
#define kStdoutFd ((fd_t)1)
|
|
|
|
#define kStderrFd ((fd_t)2)
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
uptr internal_ftruncate(fd_t fd, uptr size);
|
2013-02-21 11:57:10 +01:00
|
|
|
|
|
|
|
// OS
|
|
|
|
void NORETURN internal__exit(int exitcode);
|
2016-11-08 23:04:09 +01:00
|
|
|
unsigned int internal_sleep(unsigned int seconds);
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
uptr internal_getpid();
|
|
|
|
uptr internal_getppid();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Threading
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr internal_sched_yield();
|
|
|
|
|
|
|
|
// Error handling
|
2015-10-21 09:32:45 +02:00
|
|
|
bool internal_iserror(uptr retval, int *rverrno = nullptr);
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __sanitizer
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif // SANITIZER_LIBC_H
|