freedreno: replace all dup() with os_dupfd_cloexec()
authorEric Engestrom <eric@engestrom.ch>
Fri, 5 Jun 2020 08:22:47 +0000 (10:22 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Jun 2020 02:09:56 +0000 (02:09 +0000)
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5369>

src/freedreno/drm/freedreno_device.c
src/freedreno/vulkan/tu_android.c
src/gallium/drivers/freedreno/freedreno_fence.c

index be03cca426f8c0aad93cda6f1c0fd831834c7b28..f0dc53b526d4c06d011bad156fadcf6659249b0d 100644 (file)
@@ -28,6 +28,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "util/os_file.h"
+
 #include "freedreno_drmif.h"
 #include "freedreno_priv.h"
 
@@ -90,7 +92,7 @@ out:
  */
 struct fd_device * fd_device_new_dup(int fd)
 {
-       int dup_fd = dup(fd);
+       int dup_fd = os_dupfd_cloexec(fd);
        struct fd_device *dev = fd_device_new(dup_fd);
        if (dev)
                dev->closefd = 1;
index 00a3a577468a8db2aab3d98a8a05ca7b2eee3158..d82c8e9125d135acf95b0ab6f5b7ad73590acbe7 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "drm-uapi/drm_fourcc.h"
 
+#include "util/os_file.h"
+
 static int
 tu_hal_open(const struct hw_module_t *mod,
             const char *id,
@@ -154,7 +156,7 @@ tu_image_from_gralloc(VkDevice device_h,
       .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
       .pNext = &ded_alloc,
       .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
-      .fd = dup(dma_buf),
+      .fd = os_dupfd_cloexec(dma_buf),
    };
 
    result =
@@ -293,7 +295,7 @@ tu_AcquireImageANDROID(VkDevice device,
 
    if (semaphore != VK_NULL_HANDLE) {
       int semaphore_fd =
-         nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd;
+         nativeFenceFd >= 0 ? os_dupfd_cloexec(nativeFenceFd) : nativeFenceFd;
       semaphore_result = tu_ImportSemaphoreFdKHR(
          device, &(VkImportSemaphoreFdInfoKHR) {
                     .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
@@ -304,7 +306,7 @@ tu_AcquireImageANDROID(VkDevice device,
    }
 
    if (fence != VK_NULL_HANDLE) {
-      int fence_fd = nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd;
+      int fence_fd = nativeFenceFd >= 0 ? os_dupfd_cloexec(nativeFenceFd) : nativeFenceFd;
       fence_result = tu_ImportFenceFdKHR(
          device, &(VkImportFenceFdInfoKHR) {
                     .sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR,
index 71472da704a701b887294641cdabe3204bb919fb..59ea1896f45e6f384d9d9e288d573f076db5f808 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <libsync.h>
 
+#include "util/os_file.h"
 #include "util/u_inlines.h"
 
 #include "freedreno_fence.h"
@@ -122,7 +123,7 @@ void fd_create_fence_fd(struct pipe_context *pctx,
                enum pipe_fd_type type)
 {
        assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
-       *pfence = fence_create(fd_context(pctx), NULL, 0, dup(fd));
+       *pfence = fence_create(fd_context(pctx), NULL, 0, os_dupfd_cloexec(fd));
 }
 
 void fd_fence_server_sync(struct pipe_context *pctx,
@@ -146,7 +147,7 @@ int fd_fence_get_fd(struct pipe_screen *pscreen,
                struct pipe_fence_handle *fence)
 {
        fence_flush(fence);
-       return dup(fence->fence_fd);
+       return os_dupfd_cloexec(fence->fence_fd);
 }
 
 struct pipe_fence_handle * fd_fence_create(struct fd_batch *batch)