[sanitizer_common] Define __sanitizer_FILE on NetBSD

Differential Revision: https://reviews.llvm.org/D56109

llvm-svn: 350882
This commit is contained in:
Michal Gorny 2019-01-10 19:56:57 +00:00
parent 5b2b63e524
commit 1765839052
4 changed files with 65 additions and 12 deletions

View File

@ -5695,9 +5695,15 @@ INTERCEPTOR(void *, tsearch, void *key, void **rootp,
void unpoison_file(__sanitizer_FILE *fp) {
#if SANITIZER_HAS_STRUCT_FILE
COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp, sizeof(*fp));
#if SANITIZER_NETBSD
if (fp->_bf._base && fp->_bf._size > 0)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_bf._base,
fp->_bf._size);
#else
if (fp->_IO_read_base && fp->_IO_read_base < fp->_IO_read_end)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(fp->_IO_read_base,
fp->_IO_read_end - fp->_IO_read_base);
#endif
#endif // SANITIZER_HAS_STRUCT_FILE
}
#endif

View File

@ -2244,6 +2244,29 @@ CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
CHECK_SIZE_AND_OFFSET(wordexp_t, we_offs);
COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
CHECK_SIZE_AND_OFFSET(FILE, _p);
CHECK_SIZE_AND_OFFSET(FILE, _r);
CHECK_SIZE_AND_OFFSET(FILE, _w);
CHECK_SIZE_AND_OFFSET(FILE, _flags);
CHECK_SIZE_AND_OFFSET(FILE, _file);
CHECK_SIZE_AND_OFFSET(FILE, _bf);
CHECK_SIZE_AND_OFFSET(FILE, _lbfsize);
CHECK_SIZE_AND_OFFSET(FILE, _cookie);
CHECK_SIZE_AND_OFFSET(FILE, _close);
CHECK_SIZE_AND_OFFSET(FILE, _read);
CHECK_SIZE_AND_OFFSET(FILE, _seek);
CHECK_SIZE_AND_OFFSET(FILE, _write);
CHECK_SIZE_AND_OFFSET(FILE, _ext);
CHECK_SIZE_AND_OFFSET(FILE, _up);
CHECK_SIZE_AND_OFFSET(FILE, _ur);
CHECK_SIZE_AND_OFFSET(FILE, _ubuf);
CHECK_SIZE_AND_OFFSET(FILE, _nbuf);
CHECK_SIZE_AND_OFFSET(FILE, _flush);
CHECK_SIZE_AND_OFFSET(FILE, _lb_unused);
CHECK_SIZE_AND_OFFSET(FILE, _blksize);
CHECK_SIZE_AND_OFFSET(FILE, _offset);
CHECK_TYPE_SIZE(tm);
CHECK_SIZE_AND_OFFSET(tm, tm_sec);
CHECK_SIZE_AND_OFFSET(tm, tm_min);

View File

@ -448,8 +448,36 @@ struct __sanitizer_wordexp_t {
uptr we_nbytes;
};
typedef char __sanitizer_FILE;
#define SANITIZER_HAS_STRUCT_FILE 0
struct __sanitizer_FILE {
unsigned char *_p;
int _r;
int _w;
unsigned short _flags;
short _file;
struct {
unsigned char *_base;
int _size;
} _bf;
int _lbfsize;
void *_cookie;
int (*_close)(void *ptr);
u64 (*_read)(void *, void *, uptr);
u64 (*_seek)(void *, u64, int);
uptr (*_write)(void *, const void *, uptr);
struct {
unsigned char *_base;
int _size;
} _ext;
unsigned char *_up;
int _ur;
unsigned char _ubuf[3];
unsigned char _nbuf[1];
int (*_flush)(void *ptr);
char _lb_unused[sizeof(uptr)];
int _blksize;
u64 _offset;
};
#define SANITIZER_HAS_STRUCT_FILE 1
extern int shmctl_ipc_stat;

View File

@ -42,16 +42,12 @@ using namespace __tsan; // NOLINT
#if SANITIZER_NETBSD
#define dirfd(dirp) (*(int *)(dirp))
#define fileno_unlocked fileno
#define fileno_unlocked(fp) \
(((__sanitizer_FILE*)fp)->_file == -1 ? -1 : \
(int)(unsigned short)(((__sanitizer_FILE*)fp)->_file)) // NOLINT
#if _LP64
#define __sF_size 152
#else
#define __sF_size 88
#endif
#define stdout ((char*)&__sF + (__sF_size * 1))
#define stderr ((char*)&__sF + (__sF_size * 2))
#define stdout ((__sanitizer_FILE*)&__sF[1])
#define stderr ((__sanitizer_FILE*)&__sF[2])
#define nanosleep __nanosleep50
#define vfork __vfork14
@ -96,8 +92,8 @@ DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr size)
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr)
extern "C" void *pthread_self();
extern "C" void _exit(int status);
extern "C" int fileno_unlocked(void *stream);
#if !SANITIZER_NETBSD
extern "C" int fileno_unlocked(void *stream);
extern "C" int dirfd(void *dirp);
#endif
#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_NETBSD