sanitizer_libc.h revision 4fac1482179c6bfd84fa129560caa43f341c7336
116e0075746b21ed866ec3be21ef0d1e46f0efed5Kostya Serebryany//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
2b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//
3b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//                     The LLVM Compiler Infrastructure
4b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//
5b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// This file is distributed under the University of Illinois Open Source
6b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// License. See LICENSE.TXT for details.
7b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//
8b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//===----------------------------------------------------------------------===//
9b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//
10b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// This file is shared between AddressSanitizer and ThreadSanitizer
11b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// run-time libraries.
12b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// These tools can not use some of the libc functions directly because those
13b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany// functions are intercepted. Instead, we implement a tiny subset of libc here.
14b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany//===----------------------------------------------------------------------===//
159aead37421a6e4bf43265e5195c6ac31fc519982Kostya Serebryany#ifndef SANITIZER_LIBC_H
169aead37421a6e4bf43265e5195c6ac31fc519982Kostya Serebryany#define SANITIZER_LIBC_H
17b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany
1894b5036ee6ba866e1702848855b6d687d1e70afaAlexey Samsonov#include "sanitizer_internal_defs.h"
193836ff2733d40e1182e301ef7de3eff9469777aeAlexey Samsonov
20b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryanynamespace __sanitizer {
21b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany
22b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryanyvoid MiniLibcStub();
23b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany
243836ff2733d40e1182e301ef7de3eff9469777aeAlexey Samsonov// internal_X() is a custom implementation of X() for use in RTL.
251f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonov
261f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonov// String functions
271f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonovvoid *internal_memchr(const void *s, int c, uptr n);
28f7667cc84cdd8923c0b6c7cfc92b7bd5692ce18cAlexey Samsonovvoid *internal_memcpy(void *dest, const void *src, uptr n);
294fac1482179c6bfd84fa129560caa43f341c7336Alexey Samsonov// Should not be used in performance-critical places.
304fac1482179c6bfd84fa129560caa43f341c7336Alexey Samsonovvoid *internal_memset(void *s, int c, uptr n);
31c0d78c1de1f2607c874020d27b72cf989c5ce092Alexey Samsonovint internal_strcmp(const char *s1, const char *s2);
32f7667cc84cdd8923c0b6c7cfc92b7bd5692ce18cAlexey Samsonovchar *internal_strdup(const char *s);
33230c3be6cdd094a187f48e27ba0961dbeee70344Alexey Samsonovuptr internal_strlen(const char *s);
343836ff2733d40e1182e301ef7de3eff9469777aeAlexey Samsonovchar *internal_strncpy(char *dst, const char *src, uptr n);
354fac1482179c6bfd84fa129560caa43f341c7336Alexey Samsonovchar *internal_strrchr(const char *s, int c);
363836ff2733d40e1182e301ef7de3eff9469777aeAlexey Samsonov
371f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonov// Memory
38ae4d9caa4f47fa6abcd641719e9f520622940c17Alexey Samsonovvoid *internal_mmap(void *addr, uptr length, int prot, int flags,
39ae4d9caa4f47fa6abcd641719e9f520622940c17Alexey Samsonov                    int fd, u64 offset);
401f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonovint internal_munmap(void *addr, uptr length);
41c5d465136b911bf925f2a631e2b79f1c03e8a1b0Alexey Samsonov
421f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonov// I/O
43c5d465136b911bf925f2a631e2b79f1c03e8a1b0Alexey Samsonovtypedef int fd_t;
44a56aefd2e01940fcf88d1426f9de3d5e4b1ee203Alexey Samsonovconst fd_t kInvalidFd = -1;
45a56aefd2e01940fcf88d1426f9de3d5e4b1ee203Alexey Samsonovint internal_close(fd_t fd);
46c5d465136b911bf925f2a631e2b79f1c03e8a1b0Alexey Samsonovfd_t internal_open(const char *filename, bool write);
47a56aefd2e01940fcf88d1426f9de3d5e4b1ee203Alexey Samsonovuptr internal_read(fd_t fd, void *buf, uptr count);
48a56aefd2e01940fcf88d1426f9de3d5e4b1ee203Alexey Samsonovuptr internal_write(fd_t fd, const void *buf, uptr count);
498e820fcf7aafeb8101322182d742fcf99255d972Alexey Samsonovuptr internal_filesize(fd_t fd);  // -1 on error.
508e820fcf7aafeb8101322182d742fcf99255d972Alexey Samsonovint internal_dup2(int oldfd, int newfd);
511f11d31faa5ed89b74f7d543b1182fe8de198be5Alexey Samsonovint internal_sscanf(const char *str, const char *format, ...);
52ae4d9caa4f47fa6abcd641719e9f520622940c17Alexey Samsonov
53b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany}  // namespace __sanitizer
54b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany
559aead37421a6e4bf43265e5195c6ac31fc519982Kostya Serebryany#endif  // SANITIZER_LIBC_H
56