1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_BASE_APPLE_GUARDED_FD_H_ 6 #define NET_BASE_APPLE_GUARDED_FD_H_ 7 8 #include <stdint.h> 9 10 // "Guarded" file descriptors are a macOS SPI allowing a guard value to be 11 // assigned to a file descriptor, so as to prevent unwanted interference with 12 // its operation. 13 // 14 // Declarations from 15 // https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/sys/guarded.h 16 17 extern "C" { 18 19 using guardid_t = uint64_t; 20 21 const unsigned int GUARD_CLOSE = 1u << 0; 22 const unsigned int GUARD_DUP = 1u << 1; 23 24 int guarded_close_np(int fd, // in: file descriptor 25 const guardid_t* guard); // in: current guard value 26 int change_fdguard_np(int fd, // in: file descriptor 27 const guardid_t* guard, // in: current guard value 28 unsigned int guardflags, // in: current guard flags 29 const guardid_t* nguard, // in: new guard value 30 unsigned int nguardflags, // in: new guard flags 31 int* fdflagsp); // in/out: fd flags (fcntl:F_SETFD) 32 33 } // extern "C" 34 35 #endif // NET_BASE_APPLE_GUARDED_FD_H_ 36