CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / test_out_file.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* test_out_file.h: create a test output file (receipt JSON, kernel dump, saved probe data, fake fixture) with mode 0600. |
| 3 | * |
| 4 | * fopen(path, "w") asks for 0666 and leaves the rest to the umask, so under umask 0 every receipt is world-writable |
| 5 | * and anyone on the host can rewrite a result before it is filed (CodeQL cpp/world-writable-file-creation). The user |
| 6 | * who runs a test is the user who reads its output: the chip scripts (tools/c5/chip.sh and friends) write and file the |
| 7 | * receipts as themselves, and no runner reads them as another user. Otherwise the same as fopen "w": create or |
| 8 | * truncate, the path taken as given. */ |
| 9 | #ifndef TEST_OUT_FILE_H |
| 10 | #define TEST_OUT_FILE_H |
| 11 | #include <fcntl.h> |
| 12 | #include <stdio.h> |
| 13 | #include <unistd.h> |
| 14 | |
| 15 | static inline FILE *test_out_open(const char *path) { |
| 16 | int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600); |
| 17 | if (fd < 0) return NULL; |
| 18 | FILE *f = fdopen(fd, "w"); |
| 19 | if (!f) close(fd); |
| 20 | return f; |
| 21 | } |
| 22 | #endif |