2012-05-31 21:42:53 +08:00
|
|
|
//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
|
2012-05-29 20:18:18 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-05-29 20:18:18 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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-04-09 00:03:22 +08:00
|
|
|
// FIXME: Some of functions declared in this file are in fact POSIX, not libc.
|
2012-05-29 20:18:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2015-09-30 02:23:36 +08:00
|
|
|
|
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);
|
2015-02-06 20:07:29 +08:00
|
|
|
void *internal_memrchr(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);
|
2013-09-03 21:09:28 +08:00
|
|
|
char *internal_strchrnul(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);
|
2015-11-21 02:42:05 +08:00
|
|
|
uptr internal_strlcat(char *dst, const char *src, uptr maxlen);
|
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);
|
2015-11-21 02:42:05 +08:00
|
|
|
uptr internal_strlcpy(char *dst, const char *src, uptr maxlen);
|
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
|
|
|
char *internal_strstr(const char *haystack, const char *needle);
|
|
|
|
// Works only for base=10 and doesn't set errno.
|
2018-06-17 16:41:45 +08:00
|
|
|
s64 internal_simple_strtoll(const char *nptr, const 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
|
|
|
// I/O
|
2016-07-22 02:31:01 +08: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-01 23:58:46 +08:00
|
|
|
|
2014-05-27 20:37:52 +08:00
|
|
|
uptr internal_ftruncate(fd_t fd, uptr size);
|
2013-02-20 21:54:32 +08:00
|
|
|
|
|
|
|
// OS
|
|
|
|
void NORETURN internal__exit(int exitcode);
|
2016-05-12 22:08:56 +08:00
|
|
|
unsigned int internal_sleep(unsigned int seconds);
|
2013-02-27 19:22:40 +08:00
|
|
|
|
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
|
|
|
|
[Sanitizers] Get link map on FreeBSD and NetBSD via documented API
Summary:
Instead of hand-crafting an offset into the structure returned by
dlopen(3) to get at the link map, use the documented API. This is
described in dlinfo(3): by calling it with `RTLD_DI_LINKMAP`, the
dynamic linker ensures the right address is returned.
This is a recommit of 92e267a94dc4272511be674062f8a3e8897b7083, with
dlinfo(3) expliclity being referenced only for FreeBSD, non-Android
Linux, NetBSD and Solaris. Other OSes will have to add their own
implementation.
Reviewers: devnexen, emaste, MaskRay, krytarowski
Reviewed By: krytarowski
Subscribers: krytarowski, vitalybuka, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D73990
2020-02-11 06:43:12 +08:00
|
|
|
int internal_dlinfo(void *handle, int request, void *p);
|
|
|
|
|
2012-06-18 16:44:30 +08:00
|
|
|
// Threading
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_sched_yield();
|
|
|
|
|
|
|
|
// Error handling
|
2015-09-30 02:23:36 +08:00
|
|
|
bool internal_iserror(uptr retval, int *rverrno = nullptr);
|
2012-06-18 16:44:30 +08:00
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
} // namespace __sanitizer
|
2012-05-29 20:18:18 +08:00
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
#endif // SANITIZER_LIBC_H
|