#include <unistd.h>
#include <limits.h>
#include <assert.h>
-#include <linux/memfd.h>
#include <sys/mman.h>
#include "anv_private.h"
#include "util/hash_table.h"
#include "util/simple_mtx.h"
+#include "util/anon_file.h"
#ifdef HAVE_VALGRIND
#define VG_NOACCESS_READ(__ptr) ({ \
#define ANV_MMAP_CLEANUP_INIT ((struct anv_mmap_cleanup){0})
-#ifndef HAVE_MEMFD_CREATE
-static inline int
-memfd_create(const char *name, unsigned int flags)
-{
- return syscall(SYS_memfd_create, name, flags);
-}
-#endif
-
static inline uint32_t
ilog2_round_up(uint32_t value)
{
table->device = device;
- table->fd = memfd_create("state table", MFD_CLOEXEC);
- if (table->fd == -1)
- return vk_error(VK_ERROR_INITIALIZATION_FAILED);
-
/* Just make it 2GB up-front. The Linux kernel won't actually back it
* with pages until we either map and fault on one of them or we use
* userptr and send a chunk of it off to the GPU.
*/
- if (ftruncate(table->fd, BLOCK_POOL_MEMFD_SIZE) == -1) {
+ table->fd = os_create_anonymous_file(BLOCK_POOL_MEMFD_SIZE, "state table");
+ if (table->fd == -1) {
result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
goto fail_fd;
}
anv_bo_init(pool->bo, 0, 0);
if (!(pool->bo_flags & EXEC_OBJECT_PINNED)) {
- pool->fd = memfd_create("block pool", MFD_CLOEXEC);
- if (pool->fd == -1)
- return vk_error(VK_ERROR_INITIALIZATION_FAILED);
-
/* Just make it 2GB up-front. The Linux kernel won't actually back it
* with pages until we either map and fault on one of them or we use
* userptr and send a chunk of it off to the GPU.
*/
- if (ftruncate(pool->fd, BLOCK_POOL_MEMFD_SIZE) == -1) {
- result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
- goto fail_fd;
- }
+ pool->fd = os_create_anonymous_file(BLOCK_POOL_MEMFD_SIZE, "block pool");
+ if (pool->fd == -1)
+ return vk_error(VK_ERROR_INITIALIZATION_FAILED);
} else {
pool->fd = -1;
}