util: Add os_create_anonymous_file support on win32
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18017>
This commit is contained in:
@@ -27,9 +27,10 @@
|
|||||||
* Based on weston shared/os-compatibility.c
|
* Based on weston shared/os-compatibility.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include "anon_file.h"
|
#include "anon_file.h"
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -112,7 +113,7 @@ create_tmpfile_cloexec(char *tmpname)
|
|||||||
* SCM_RIGHTS methods.
|
* SCM_RIGHTS methods.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
os_create_anonymous_file(off_t size, const char *debug_name)
|
os_create_anonymous_file(int64_t size, const char *debug_name)
|
||||||
{
|
{
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
#if defined(HAVE_MEMFD_CREATE)
|
#if defined(HAVE_MEMFD_CREATE)
|
||||||
@@ -155,7 +156,7 @@ os_create_anonymous_file(off_t size, const char *debug_name)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = ftruncate(fd, size);
|
ret = ftruncate(fd, (off_t)size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -163,4 +164,17 @@ os_create_anonymous_file(off_t size, const char *debug_name)
|
|||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
os_create_anonymous_file(int64_t size, const char *debug_name)
|
||||||
|
{
|
||||||
|
(void)debug_name;
|
||||||
|
HANDLE h = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
|
||||||
|
PAGE_READWRITE, (size >> 32), size & 0xFFFFFFFF, NULL);
|
||||||
|
return _open_osfhandle((intptr_t)h, 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -26,8 +26,9 @@
|
|||||||
#ifndef _ANON_FILE_H_
|
#ifndef _ANON_FILE_H_
|
||||||
#define _ANON_FILE_H_
|
#define _ANON_FILE_H_
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int os_create_anonymous_file(off_t size, const char *debug_name);
|
/* On win32, off_t is only 32 bit, so always using 64 bit size */
|
||||||
|
int os_create_anonymous_file(int64_t size, const char *debug_name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user