13cab2bb3Spatrick //===-- tsan_fd.h -----------------------------------------------*- C++ -*-===// 23cab2bb3Spatrick // 33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information. 53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63cab2bb3Spatrick // 73cab2bb3Spatrick //===----------------------------------------------------------------------===// 83cab2bb3Spatrick // 93cab2bb3Spatrick // This file is a part of ThreadSanitizer (TSan), a race detector. 103cab2bb3Spatrick // 113cab2bb3Spatrick // This file handles synchronization via IO. 123cab2bb3Spatrick // People use IO for synchronization along the lines of: 133cab2bb3Spatrick // 143cab2bb3Spatrick // int X; 153cab2bb3Spatrick // int client_socket; // initialized elsewhere 163cab2bb3Spatrick // int server_socket; // initialized elsewhere 173cab2bb3Spatrick // 183cab2bb3Spatrick // Thread 1: 193cab2bb3Spatrick // X = 42; 203cab2bb3Spatrick // send(client_socket, ...); 213cab2bb3Spatrick // 223cab2bb3Spatrick // Thread 2: 233cab2bb3Spatrick // if (recv(server_socket, ...) > 0) 243cab2bb3Spatrick // assert(X == 42); 253cab2bb3Spatrick // 263cab2bb3Spatrick // This file determines the scope of the file descriptor (pipe, socket, 273cab2bb3Spatrick // all local files, etc) and executes acquire and release operations on 283cab2bb3Spatrick // the scope as necessary. Some scopes are very fine grained (e.g. pipe 293cab2bb3Spatrick // operations synchronize only with operations on the same pipe), while 303cab2bb3Spatrick // others are corse-grained (e.g. all operations on local files synchronize 313cab2bb3Spatrick // with each other). 323cab2bb3Spatrick //===----------------------------------------------------------------------===// 333cab2bb3Spatrick #ifndef TSAN_FD_H 343cab2bb3Spatrick #define TSAN_FD_H 353cab2bb3Spatrick 363cab2bb3Spatrick #include "tsan_rtl.h" 373cab2bb3Spatrick 383cab2bb3Spatrick namespace __tsan { 393cab2bb3Spatrick 403cab2bb3Spatrick void FdInit(); 413cab2bb3Spatrick void FdAcquire(ThreadState *thr, uptr pc, int fd); 423cab2bb3Spatrick void FdRelease(ThreadState *thr, uptr pc, int fd); 433cab2bb3Spatrick void FdAccess(ThreadState *thr, uptr pc, int fd); 443cab2bb3Spatrick void FdClose(ThreadState *thr, uptr pc, int fd, bool write = true); 453cab2bb3Spatrick void FdFileCreate(ThreadState *thr, uptr pc, int fd); 463cab2bb3Spatrick void FdDup(ThreadState *thr, uptr pc, int oldfd, int newfd, bool write); 473cab2bb3Spatrick void FdPipeCreate(ThreadState *thr, uptr pc, int rfd, int wfd); 483cab2bb3Spatrick void FdEventCreate(ThreadState *thr, uptr pc, int fd); 493cab2bb3Spatrick void FdSignalCreate(ThreadState *thr, uptr pc, int fd); 503cab2bb3Spatrick void FdInotifyCreate(ThreadState *thr, uptr pc, int fd); 513cab2bb3Spatrick void FdPollCreate(ThreadState *thr, uptr pc, int fd); 52*810390e3Srobert void FdPollAdd(ThreadState *thr, uptr pc, int epfd, int fd); 533cab2bb3Spatrick void FdSocketCreate(ThreadState *thr, uptr pc, int fd); 543cab2bb3Spatrick void FdSocketAccept(ThreadState *thr, uptr pc, int fd, int newfd); 553cab2bb3Spatrick void FdSocketConnecting(ThreadState *thr, uptr pc, int fd); 563cab2bb3Spatrick void FdSocketConnect(ThreadState *thr, uptr pc, int fd); 57*810390e3Srobert bool FdLocation(uptr addr, int *fd, Tid *tid, StackID *stack, bool *closed); 583cab2bb3Spatrick void FdOnFork(ThreadState *thr, uptr pc); 593cab2bb3Spatrick 603cab2bb3Spatrick uptr File2addr(const char *path); 613cab2bb3Spatrick uptr Dir2addr(const char *path); 623cab2bb3Spatrick 633cab2bb3Spatrick } // namespace __tsan 643cab2bb3Spatrick 653cab2bb3Spatrick #endif // TSAN_INTERFACE_H 66