<div dir="ltr">I'm not 100% sure why but GMail has decided that every single e-mail you send to the mailing list is spam. You might want to check that out. :)<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 31, 2017 at 8:55 AM, Greg V <span dir="ltr"><<a href="mailto:greg@unrelenting.technology" target="_blank">greg@unrelenting.technology</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Use umtx for futex, and SHM_ANON for memfd.<br>
<br>
Also use temp files as memfd fallback for other OSes.<br>
<br>
Obtained from: FreeBSD ports<br>
---<br>
src/intel/vulkan/anv_<wbr>allocator.c | 56 ++++++++++++++++++++++++++++++<wbr>++++++++++<br>
1 file changed, 56 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>allocator.c b/src/intel/vulkan/anv_<wbr>allocator.c<br>
index 33bd3c68c5..c31d3d17d2 100644<br>
--- a/src/intel/vulkan/anv_<wbr>allocator.c<br>
+++ b/src/intel/vulkan/anv_<wbr>allocator.c<br>
@@ -25,7 +25,13 @@<br>
#include <unistd.h><br>
#include <limits.h><br>
#include <assert.h><br>
+#ifdef __linux__<br>
#include <linux/memfd.h><br>
+#elif __FreeBSD__<br>
+#include <errno.h><br>
+#include <fcntl.h><br>
+#include <sys/umtx.h><br>
+#endif<br>
#include <sys/mman.h><br>
<br>
#include "anv_private.h"<br>
@@ -50,6 +56,34 @@<br>
#define VG_NOACCESS_WRITE(__ptr, __val) (*(__ptr) = (__val))<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+static inline int<br>
+sys_futex(void *addr, int op, int32_t val)<br>
+{<br>
+ return _umtx_op(addr, op, (uint32_t)val, NULL, NULL) == -1 ? errno : 0;<br>
+}<br>
+<br>
+static inline int<br>
+futex_wake(uint32_t *addr, int count)<br>
+{<br>
+ return sys_futex(addr, UMTX_OP_WAKE, count);<br>
+}<br>
+<br>
+static inline int<br>
+futex_wait(uint32_t *addr, int32_t value, int32_t _)<br>
+{<br>
+ return sys_futex(addr, UMTX_OP_WAIT_UINT, value);<br>
+}<br>
+#endif<br>
+<br>
+#ifndef MAP_POPULATE<br>
+#define MAP_POPULATE 0<br>
+#endif<br>
+<br>
+#ifndef MFD_CLOEXEC<br>
+#define MFD_CLOEXEC O_CLOEXEC<br>
+#endif<br>
+<br>
/* Design goals:<br>
*<br>
* - Lock free (except when resizing underlying bos)<br>
@@ -113,7 +147,29 @@ struct anv_mmap_cleanup {<br>
static inline int<br>
memfd_create(const char *name, unsigned int flags)<br>
{<br>
+#if defined(__linux__)<br>
return syscall(SYS_memfd_create, name, flags);<br>
+#elif defined(__FreeBSD__)<br>
+ return shm_open(SHM_ANON, flags | O_RDWR | O_CREAT, 0600);<br>
+#else /* DragonFly, NetBSD, OpenBSD, Solaris */<br>
+ char template[] = "/tmp/shmfd-XXXXXX";<br>
+#ifdef HAVE_MKOSTEMP<br>
+ int fd = mkostemp(template, flags);<br>
+#else<br>
+ int fd = mkstemp(template);<br>
+ if (flags & O_CLOEXEC) {<br>
+ int flags = fcntl(fd, F_GETFD);<br>
+ if (flags != -1) {<br>
+ flags |= FD_CLOEXEC;<br>
+ (void) fcntl(fd, F_SETFD, &flags);<br>
+ }<br>
+ }<br>
+#endif /* HAVE_MKOSTEMP */<br>
+ if (fd >= 0)<br>
+ unlink(template);<br>
+<br>
+ return fd;<br>
+#endif /* __linux__ */<br>
}<br>
#endif<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.15.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div></div>