summaryrefslogtreecommitdiff
path: root/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp')
-rw-r--r--gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index d890a3a3177..e21661b42f8 100644
--- a/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -347,9 +347,17 @@ int GetNamedMappingFd(const char *name, uptr size, int *flags) {
CHECK(internal_strlen(name) < sizeof(shmname) - 10);
internal_snprintf(shmname, sizeof(shmname), "/dev/shm/%zu [%s]",
internal_getpid(), name);
+ int o_cloexec = 0;
+#if defined(O_CLOEXEC)
+ o_cloexec = O_CLOEXEC;
+#endif
int fd = ReserveStandardFds(
- internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRWXU));
+ internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | o_cloexec, S_IRWXU));
CHECK_GE(fd, 0);
+ if (!o_cloexec) {
+ int res = fcntl(fd, F_SETFD, FD_CLOEXEC);
+ CHECK_EQ(0, res);
+ }
int res = internal_ftruncate(fd, size);
CHECK_EQ(0, res);
res = internal_unlink(shmname);