This allows the compositor to avoid having to setup and teardown a SIGBUS signal handler whenever it needs to read from this surface, as it knows we won’t be able to shrink the file and so doesn’t have to protect against that. Only enabled on Linux, since only Linux has memfd_create()
52 lines
1.1 KiB
C
Vendored
52 lines
1.1 KiB
C
Vendored
/*
|
|
* Copyright (C) 2018 Kovid Goyal <kovid at kovidgoyal.net>
|
|
*
|
|
* Distributed under terms of the GPL3 license.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#if defined(__linux__)
|
|
|
|
#define _GNU_SOURCE
|
|
#include <unistd.h>
|
|
#include <sys/syscall.h>
|
|
static inline int memfd_create(const char *name, unsigned int flags) {
|
|
return syscall(__NR_memfd_create, name, flags);
|
|
}
|
|
|
|
#ifndef F_LINUX_SPECIFIC_BASE
|
|
#define F_LINUX_SPECIFIC_BASE 1024
|
|
#endif
|
|
|
|
#ifndef F_ADD_SEALS
|
|
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
|
|
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
|
|
|
|
#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
|
|
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
|
|
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
|
|
#define F_SEAL_WRITE 0x0008 /* prevent writes */
|
|
#endif
|
|
|
|
#ifndef MFD_CLOEXEC
|
|
#define MFD_CLOEXEC 0x0001U
|
|
#define MFD_ALLOW_SEALING 0x0002U
|
|
#endif
|
|
|
|
#else
|
|
|
|
static inline int
|
|
createTmpfileCloexec(char* tmpname)
|
|
{
|
|
int fd;
|
|
|
|
fd = mkostemp(tmpname, O_CLOEXEC);
|
|
if (fd >= 0)
|
|
unlink(tmpname);
|
|
|
|
return fd;
|
|
}
|
|
|
|
#endif
|