| 1 |
//===-- tsan_fd.h -----------------------------------------------*- C++ -*-===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file is a part of ThreadSanitizer (TSan), a race detector. |
| 10 |
// |
| 11 |
// This file handles synchronization via IO. |
| 12 |
// People use IO for synchronization along the lines of: |
| 13 |
// |
| 14 |
// int X; |
| 15 |
// int client_socket; // initialized elsewhere |
| 16 |
// int server_socket; // initialized elsewhere |
| 17 |
// |
| 18 |
// Thread 1: |
| 19 |
// X = 42; |
| 20 |
// send(client_socket, ...); |
| 21 |
// |
| 22 |
// Thread 2: |
| 23 |
// if (recv(server_socket, ...) > 0) |
| 24 |
// assert(X == 42); |
| 25 |
// |
| 26 |
// This file determines the scope of the file descriptor (pipe, socket, |
| 27 |
// all local files, etc) and executes acquire and release operations on |
| 28 |
// the scope as necessary. Some scopes are very fine grained (e.g. pipe |
| 29 |
// operations synchronize only with operations on the same pipe), while |
| 30 |
// others are corse-grained (e.g. all operations on local files synchronize |
| 31 |
// with each other). |
| 32 |
//===----------------------------------------------------------------------===// |
| 33 |
#ifndef TSAN_FD_H |
| 34 |
#define TSAN_FD_H |
| 35 |
|
| 36 |
#include "tsan_rtl.h" |
| 37 |
|
| 38 |
namespace __tsan { |
| 39 |
|
| 40 |
void FdInit(); |
| 41 |
void FdAcquire(ThreadState *thr, uptr pc, int fd); |
| 42 |
void FdRelease(ThreadState *thr, uptr pc, int fd); |
| 43 |
void FdAccess(ThreadState *thr, uptr pc, int fd); |
| 44 |
void FdClose(ThreadState *thr, uptr pc, int fd, bool write = true); |
| 45 |
void FdFileCreate(ThreadState *thr, uptr pc, int fd); |
| 46 |
void FdDup(ThreadState *thr, uptr pc, int oldfd, int newfd, bool write); |
| 47 |
void FdPipeCreate(ThreadState *thr, uptr pc, int rfd, int wfd); |
| 48 |
void FdEventCreate(ThreadState *thr, uptr pc, int fd); |
| 49 |
void FdSignalCreate(ThreadState *thr, uptr pc, int fd); |
| 50 |
void FdInotifyCreate(ThreadState *thr, uptr pc, int fd); |
| 51 |
void FdPollCreate(ThreadState *thr, uptr pc, int fd); |
| 52 |
void FdPollAdd(ThreadState *thr, uptr pc, int epfd, int fd); |
| 53 |
void FdSocketCreate(ThreadState *thr, uptr pc, int fd); |
| 54 |
void FdSocketAccept(ThreadState *thr, uptr pc, int fd, int newfd); |
| 55 |
void FdSocketConnecting(ThreadState *thr, uptr pc, int fd); |
| 56 |
void FdSocketConnect(ThreadState *thr, uptr pc, int fd); |
| 57 |
bool FdLocation(uptr addr, int *fd, Tid *tid, StackID *stack, bool *closed); |
| 58 |
void FdOnFork(ThreadState *thr, uptr pc); |
| 59 |
|
| 60 |
uptr File2addr(const char *path); |
| 61 |
uptr Dir2addr(const char *path); |
| 62 |
|
| 63 |
} // namespace __tsan |
| 64 |
|
| 65 |
#endif // TSAN_INTERFACE_H |