[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1065654: mesa ftbfs with time_t64



Package: src:mesa
Version: 24.0.2-1
Severity: serious
Tags: sid trixie patch

mesa ftbfs with time_t64, patch attached. I didn't check if the _TIMET_BITS are used in the affected files.

There's also a bug in the profile support. WINE cannot be built without LLVM, and therefore should be disabled.
reverted:
--- mesa-24.0.2/.pc/.quilt_patches
+++ mesa-24.0.2.orig/.pc/.quilt_patches
@@ -1 +0,0 @@
-patches
reverted:
--- mesa-24.0.2/.pc/.quilt_series
+++ mesa-24.0.2.orig/.pc/.quilt_series
@@ -1 +0,0 @@
-series
reverted:
--- mesa-24.0.2/.pc/.version
+++ mesa-24.0.2.orig/.pc/.version
@@ -1 +0,0 @@
-2
reverted:
--- mesa-24.0.2/.pc/applied-patches
+++ mesa-24.0.2.orig/.pc/applied-patches
@@ -1 +0,0 @@
-time64.diff
reverted:
--- mesa-24.0.2/.pc/time64.diff/src/drm-shim/drm_shim.c
+++ mesa-24.0.2.orig/.pc/time64.diff/src/drm-shim/drm_shim.c
@@ -1,836 +0,0 @@
-/*
- * Copyright © 2018 Broadcom
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * @file
- *
- * Implements wrappers of libc functions to fake having a DRM device that
- * isn't actually present in the kernel.
- */
-
-/* Prevent glibc from defining open64 when we want to alias it. */
-#undef _FILE_OFFSET_BITS
-#define _LARGEFILE64_SOURCE
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/sysmacros.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-#include <dirent.h>
-#include <c11/threads.h>
-#include <drm-uapi/drm.h>
-
-#include "util/anon_file.h"
-#include "util/set.h"
-#include "util/simple_mtx.h"
-#include "util/u_debug.h"
-#include "drm_shim.h"
-
-#define REAL_FUNCTION_POINTER(x) __typeof__(x) *real_##x
-
-static simple_mtx_t shim_lock = SIMPLE_MTX_INITIALIZER;
-struct set *opendir_set;
-bool drm_shim_debug;
-
-/* If /dev/dri doesn't exist, we'll need an arbitrary pointer that wouldn't be
- * returned by any other opendir() call so we can return just our fake node.
- */
-DIR *fake_dev_dri = (void *)&opendir_set;
-
-REAL_FUNCTION_POINTER(close);
-REAL_FUNCTION_POINTER(closedir);
-REAL_FUNCTION_POINTER(dup);
-REAL_FUNCTION_POINTER(fcntl);
-REAL_FUNCTION_POINTER(fopen);
-REAL_FUNCTION_POINTER(ioctl);
-REAL_FUNCTION_POINTER(mmap);
-REAL_FUNCTION_POINTER(mmap64);
-REAL_FUNCTION_POINTER(open);
-REAL_FUNCTION_POINTER(opendir);
-REAL_FUNCTION_POINTER(readdir);
-REAL_FUNCTION_POINTER(readdir64);
-REAL_FUNCTION_POINTER(readlink);
-REAL_FUNCTION_POINTER(realpath);
-
-#define HAS_XSTAT __GLIBC__ == 2 && __GLIBC_MINOR__ < 33
-
-#if HAS_XSTAT
-REAL_FUNCTION_POINTER(__xstat);
-REAL_FUNCTION_POINTER(__xstat64);
-REAL_FUNCTION_POINTER(__fxstat);
-REAL_FUNCTION_POINTER(__fxstat64);
-#else
-REAL_FUNCTION_POINTER(stat);
-REAL_FUNCTION_POINTER(stat64);
-REAL_FUNCTION_POINTER(fstat);
-REAL_FUNCTION_POINTER(fstat64);
-#endif
-
-static char render_node_dir[] = "/dev/dri/";
-/* Full path of /dev/dri/renderD* */
-static char *render_node_path;
-/* renderD* */
-static char *render_node_dirent_name;
-/* /sys/dev/char/major: */
-static int drm_device_path_len;
-static char *drm_device_path;
-/* /sys/dev/char/major:minor/device */
-static int device_path_len;
-static char *device_path;
-/* /sys/dev/char/major:minor/device/subsystem */
-static char *subsystem_path;
-int render_node_minor = -1;
-
-struct file_override {
-   const char *path;
-   char *contents;
-};
-static struct file_override file_overrides[10];
-static int file_overrides_count;
-extern bool drm_shim_driver_prefers_first_render_node;
-
-static int
-nfvasprintf(char **restrict strp, const char *restrict fmt, va_list ap)
-{
-   int ret = vasprintf(strp, fmt, ap);
-   assert(ret >= 0);
-   return ret;
-}
-
-static int
-nfasprintf(char **restrict strp, const char *restrict fmt, ...)
-{
-   va_list ap;
-   va_start(ap, fmt);
-   int ret = nfvasprintf(strp, fmt, ap);
-   va_end(ap);
-   return ret;
-}
-
-/* Pick the minor and filename for our shimmed render node.  This can be
- * either a new one that didn't exist on the system, or if the driver wants,
- * it can replace the first render node.
- */
-static void
-get_dri_render_node_minor(void)
-{
-   for (int i = 0; i < 10; i++) {
-      UNUSED int minor = 128 + i;
-      nfasprintf(&render_node_dirent_name, "renderD%d", minor);
-      nfasprintf(&render_node_path, "/dev/dri/%s",
-                 render_node_dirent_name);
-      struct stat st;
-      if (drm_shim_driver_prefers_first_render_node ||
-          stat(render_node_path, &st) == -1) {
-
-         render_node_minor = minor;
-         return;
-      }
-   }
-
-   fprintf(stderr, "Couldn't find a spare render node slot\n");
-}
-
-static void *get_function_pointer(const char *name)
-{
-   void *func = dlsym(RTLD_NEXT, name);
-   if (!func) {
-      fprintf(stderr, "Failed to resolve %s\n", name);
-      abort();
-   }
-   return func;
-}
-
-#define GET_FUNCTION_POINTER(x) real_##x = get_function_pointer(#x)
-
-void
-drm_shim_override_file(const char *contents, const char *path_format, ...)
-{
-   assert(file_overrides_count < ARRAY_SIZE(file_overrides));
-
-   char *path;
-   va_list ap;
-   va_start(ap, path_format);
-   nfvasprintf(&path, path_format, ap);
-   va_end(ap);
-
-   struct file_override *override = &file_overrides[file_overrides_count++];
-   override->path = path;
-   override->contents = strdup(contents);
-}
-
-static void
-destroy_shim(void)
-{
-   _mesa_set_destroy(opendir_set, NULL);
-   free(render_node_path);
-   free(render_node_dirent_name);
-   free(subsystem_path);
-}
-
-/* Initialization, which will be called from the first general library call
- * that might need to be wrapped with the shim.
- */
-static void
-init_shim(void)
-{
-   static bool inited = false;
-   drm_shim_debug = debug_get_bool_option("DRM_SHIM_DEBUG", false);
-
-   /* We can't lock this, because we recurse during initialization. */
-   if (inited)
-      return;
-
-   /* This comes first (and we're locked), to make sure we don't recurse
-    * during initialization.
-    */
-   inited = true;
-
-   opendir_set = _mesa_set_create(NULL,
-                                  _mesa_hash_string,
-                                  _mesa_key_string_equal);
-
-   GET_FUNCTION_POINTER(close);
-   GET_FUNCTION_POINTER(closedir);
-   GET_FUNCTION_POINTER(dup);
-   GET_FUNCTION_POINTER(fcntl);
-   GET_FUNCTION_POINTER(fopen);
-   GET_FUNCTION_POINTER(ioctl);
-   GET_FUNCTION_POINTER(mmap);
-   GET_FUNCTION_POINTER(mmap64);
-   GET_FUNCTION_POINTER(open);
-   GET_FUNCTION_POINTER(opendir);
-   GET_FUNCTION_POINTER(readdir);
-   GET_FUNCTION_POINTER(readdir64);
-   GET_FUNCTION_POINTER(readlink);
-   GET_FUNCTION_POINTER(realpath);
-
-#if HAS_XSTAT
-   GET_FUNCTION_POINTER(__xstat);
-   GET_FUNCTION_POINTER(__xstat64);
-   GET_FUNCTION_POINTER(__fxstat);
-   GET_FUNCTION_POINTER(__fxstat64);
-#else
-   GET_FUNCTION_POINTER(stat);
-   GET_FUNCTION_POINTER(stat64);
-   GET_FUNCTION_POINTER(fstat);
-   GET_FUNCTION_POINTER(fstat64);
-#endif
-
-   get_dri_render_node_minor();
-
-   if (drm_shim_debug) {
-      fprintf(stderr, "Initializing DRM shim on %s\n",
-              render_node_path);
-   }
-
-   drm_device_path_len =
-      nfasprintf(&drm_device_path, "/sys/dev/char/%d:", DRM_MAJOR);
-
-   device_path_len =
-      nfasprintf(&device_path,
-                 "/sys/dev/char/%d:%d/device",
-                 DRM_MAJOR, render_node_minor);
-
-   nfasprintf(&subsystem_path,
-              "/sys/dev/char/%d:%d/device/subsystem",
-              DRM_MAJOR, render_node_minor);
-
-   drm_shim_device_init();
-
-   atexit(destroy_shim);
-}
-
-static bool hide_drm_device_path(const char *path)
-{
-   if (render_node_minor == -1)
-      return false;
-
-   /* If the path looks like our fake render node device, then don't hide it.
-    */
-   if (strncmp(path, device_path, device_path_len) == 0 ||
-       strcmp(path, render_node_path) == 0)
-      return false;
-
-   /* String starts with /sys/dev/char/226: but is not the fake render node.
-    * We want to hide all other drm devices for the shim.
-    */
-   if (strncmp(path, drm_device_path, drm_device_path_len) == 0)
-      return true;
-
-   /* String starts with /dev/dri/ but is not the fake render node. We want to
-    * hide all other drm devices for the shim.
-    */
-   if (strncmp(path, render_node_dir, sizeof(render_node_dir) - 1) == 0)
-      return true;
-
-   return false;
-}
-
-static int file_override_open(const char *path)
-{
-   for (int i = 0; i < file_overrides_count; i++) {
-      if (strcmp(file_overrides[i].path, path) == 0) {
-         int fd = os_create_anonymous_file(0, "shim file");
-         write(fd, file_overrides[i].contents,
-               strlen(file_overrides[i].contents));
-         lseek(fd, 0, SEEK_SET);
-         return fd;
-      }
-   }
-
-   return -1;
-}
-
-/* Override libdrm's reading of various sysfs files for device enumeration. */
-PUBLIC FILE *fopen(const char *path, const char *mode)
-{
-   init_shim();
-
-   int fd = file_override_open(path);
-   if (fd >= 0)
-      return fdopen(fd, "r");
-
-   return real_fopen(path, mode);
-}
-PUBLIC FILE *fopen64(const char *path, const char *mode)
-   __attribute__((alias("fopen")));
-
-/* Intercepts open(render_node_path) to redirect it to the simulator. */
-PUBLIC int open(const char *path, int flags, ...)
-{
-   init_shim();
-
-   va_list ap;
-   va_start(ap, flags);
-   mode_t mode = va_arg(ap, mode_t);
-   va_end(ap);
-
-   int fd = file_override_open(path);
-   if (fd >= 0)
-      return fd;
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   if (strcmp(path, render_node_path) != 0)
-      return real_open(path, flags, mode);
-
-   fd = real_open("/dev/null", O_RDWR, 0);
-
-   drm_shim_fd_register(fd, NULL);
-
-   return fd;
-}
-PUBLIC int open64(const char*, int, ...) __attribute__((alias("open")));
-
-/* __open64_2 isn't declared unless _FORTIFY_SOURCE is defined. */
-PUBLIC int __open64_2(const char *path, int flags);
-PUBLIC int __open64_2(const char *path, int flags)
-{
-   return open(path, flags, 0);
-}
-
-PUBLIC int close(int fd)
-{
-   init_shim();
-
-   drm_shim_fd_unregister(fd);
-
-   return real_close(fd);
-}
-
-#if HAS_XSTAT
-/* Fakes stat to return character device stuff for our fake render node. */
-PUBLIC int __xstat(int ver, const char *path, struct stat *st)
-{
-   init_shim();
-
-   /* Note: call real stat if we're in the process of probing for a free
-    * render node!
-    */
-   if (render_node_minor == -1)
-      return real___xstat(ver, path, st);
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   /* Fool libdrm's probe of whether the /sys dir for this char dev is
-    * there.
-    */
-   char *sys_dev_drm_dir;
-   nfasprintf(&sys_dev_drm_dir,
-              "/sys/dev/char/%d:%d/device/drm",
-              DRM_MAJOR, render_node_minor);
-   if (strcmp(path, sys_dev_drm_dir) == 0) {
-      free(sys_dev_drm_dir);
-      return 0;
-   }
-   free(sys_dev_drm_dir);
-
-   if (strcmp(path, render_node_path) != 0)
-      return real___xstat(ver, path, st);
-
-   memset(st, 0, sizeof(*st));
-   st->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   st->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-/* Fakes stat to return character device stuff for our fake render node. */
-PUBLIC int __xstat64(int ver, const char *path, struct stat64 *st)
-{
-   init_shim();
-
-   /* Note: call real stat if we're in the process of probing for a free
-    * render node!
-    */
-   if (render_node_minor == -1)
-      return real___xstat64(ver, path, st);
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   /* Fool libdrm's probe of whether the /sys dir for this char dev is
-    * there.
-    */
-   char *sys_dev_drm_dir;
-   nfasprintf(&sys_dev_drm_dir,
-              "/sys/dev/char/%d:%d/device/drm",
-              DRM_MAJOR, render_node_minor);
-   if (strcmp(path, sys_dev_drm_dir) == 0) {
-      free(sys_dev_drm_dir);
-      return 0;
-   }
-   free(sys_dev_drm_dir);
-
-   if (strcmp(path, render_node_path) != 0)
-      return real___xstat64(ver, path, st);
-
-   memset(st, 0, sizeof(*st));
-   st->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   st->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-/* Fakes fstat to return character device stuff for our fake render node. */
-PUBLIC int __fxstat(int ver, int fd, struct stat *st)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-
-   if (!shim_fd)
-      return real___fxstat(ver, fd, st);
-
-   memset(st, 0, sizeof(*st));
-   st->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   st->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-PUBLIC int __fxstat64(int ver, int fd, struct stat64 *st)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-
-   if (!shim_fd)
-      return real___fxstat64(ver, fd, st);
-
-   memset(st, 0, sizeof(*st));
-   st->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   st->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-#else
-
-PUBLIC int stat(const char* path, struct stat* stat_buf)
-{
-   init_shim();
-
-   /* Note: call real stat if we're in the process of probing for a free
-    * render node!
-    */
-   if (render_node_minor == -1)
-      return real_stat(path, stat_buf);
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   /* Fool libdrm's probe of whether the /sys dir for this char dev is
-    * there.
-    */
-   char *sys_dev_drm_dir;
-   nfasprintf(&sys_dev_drm_dir,
-              "/sys/dev/char/%d:%d/device/drm",
-              DRM_MAJOR, render_node_minor);
-   if (strcmp(path, sys_dev_drm_dir) == 0) {
-      free(sys_dev_drm_dir);
-      return 0;
-   }
-   free(sys_dev_drm_dir);
-
-   if (strcmp(path, render_node_path) != 0)
-      return real_stat(path, stat_buf);
-
-   memset(stat_buf, 0, sizeof(*stat_buf));
-   stat_buf->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   stat_buf->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-PUBLIC int stat64(const char* path, struct stat64* stat_buf)
-{
-   init_shim();
-
-   /* Note: call real stat if we're in the process of probing for a free
-    * render node!
-    */
-   if (render_node_minor == -1)
-      return real_stat64(path, stat_buf);
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   /* Fool libdrm's probe of whether the /sys dir for this char dev is
-    * there.
-    */
-   char *sys_dev_drm_dir;
-   nfasprintf(&sys_dev_drm_dir,
-              "/sys/dev/char/%d:%d/device/drm",
-              DRM_MAJOR, render_node_minor);
-   if (strcmp(path, sys_dev_drm_dir) == 0) {
-      free(sys_dev_drm_dir);
-      return 0;
-   }
-   free(sys_dev_drm_dir);
-
-   if (strcmp(path, render_node_path) != 0)
-      return real_stat64(path, stat_buf);
-
-   memset(stat_buf, 0, sizeof(*stat_buf));
-   stat_buf->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   stat_buf->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-PUBLIC int fstat(int fd, struct stat* stat_buf)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-
-   if (!shim_fd)
-      return real_fstat(fd, stat_buf);
-
-   memset(stat_buf, 0, sizeof(*stat_buf));
-   stat_buf->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   stat_buf->st_mode = S_IFCHR;
-
-   return 0;
-}
-
-PUBLIC int fstat64(int fd, struct stat64* stat_buf)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-
-   if (!shim_fd)
-      return real_fstat64(fd, stat_buf);
-
-   memset(stat_buf, 0, sizeof(*stat_buf));
-   stat_buf->st_rdev = makedev(DRM_MAJOR, render_node_minor);
-   stat_buf->st_mode = S_IFCHR;
-
-   return 0;
-}
-#endif
-
-/* Tracks if the opendir was on /dev/dri. */
-PUBLIC DIR *
-opendir(const char *name)
-{
-   init_shim();
-
-   DIR *dir = real_opendir(name);
-   if (strcmp(name, "/dev/dri") == 0) {
-      if (!dir) {
-         /* If /dev/dri didn't exist, we still want to be able to return our
-          * fake /dev/dri/render* even though we probably can't
-          * mkdir("/dev/dri").  Return a fake DIR pointer for that.
-          */
-         dir = fake_dev_dri;
-      }
-
-      simple_mtx_lock(&shim_lock);
-      _mesa_set_add(opendir_set, dir);
-      simple_mtx_unlock(&shim_lock);
-   }
-
-   return dir;
-}
-
-/* If we're looking at /dev/dri, add our render node to the list
- * before the real entries in the directory.
- */
-PUBLIC struct dirent *
-readdir(DIR *dir)
-{
-   init_shim();
-
-   struct dirent *ent = NULL;
-
-   static struct dirent render_node_dirent = { 0 };
-
-   simple_mtx_lock(&shim_lock);
-   if (_mesa_set_search(opendir_set, dir)) {
-      strcpy(render_node_dirent.d_name,
-             render_node_dirent_name);
-      render_node_dirent.d_type = DT_CHR;
-      ent = &render_node_dirent;
-      _mesa_set_remove_key(opendir_set, dir);
-   }
-   simple_mtx_unlock(&shim_lock);
-
-   if (!ent && dir != fake_dev_dri)
-      ent = real_readdir(dir);
-
-   return ent;
-}
-
-/* If we're looking at /dev/dri, add our render node to the list
- * before the real entries in the directory.
- */
-PUBLIC struct dirent64 *
-readdir64(DIR *dir)
-{
-   init_shim();
-
-   struct dirent64 *ent = NULL;
-
-   static struct dirent64 render_node_dirent = { 0 };
-
-   simple_mtx_lock(&shim_lock);
-   if (_mesa_set_search(opendir_set, dir)) {
-      strcpy(render_node_dirent.d_name,
-             render_node_dirent_name);
-      render_node_dirent.d_type = DT_CHR;
-      ent = &render_node_dirent;
-      _mesa_set_remove_key(opendir_set, dir);
-   }
-   simple_mtx_unlock(&shim_lock);
-
-   if (!ent && dir != fake_dev_dri)
-      ent = real_readdir64(dir);
-
-   return ent;
-}
-
-/* Cleans up tracking of opendir("/dev/dri") */
-PUBLIC int
-closedir(DIR *dir)
-{
-   init_shim();
-
-   simple_mtx_lock(&shim_lock);
-   _mesa_set_remove_key(opendir_set, dir);
-   simple_mtx_unlock(&shim_lock);
-
-   if (dir != fake_dev_dri)
-      return real_closedir(dir);
-   else
-      return 0;
-}
-
-/* Handles libdrm's readlink to figure out what kind of device we have. */
-PUBLIC ssize_t
-readlink(const char *path, char *buf, size_t size)
-{
-   init_shim();
-
-   if (hide_drm_device_path(path)) {
-      errno = ENOENT;
-      return -1;
-   }
-
-   if (strcmp(path, subsystem_path) != 0)
-      return real_readlink(path, buf, size);
-
-   static const struct {
-      const char *name;
-      int bus_type;
-   } bus_types[] = {
-      { "/pci", DRM_BUS_PCI },
-      { "/usb", DRM_BUS_USB },
-      { "/platform", DRM_BUS_PLATFORM },
-      { "/spi", DRM_BUS_PLATFORM },
-      { "/host1x", DRM_BUS_HOST1X },
-   };
-
-   for (uint32_t i = 0; i < ARRAY_SIZE(bus_types); i++) {
-      if (bus_types[i].bus_type != shim_device.bus_type)
-         continue;
-
-      strncpy(buf, bus_types[i].name, size);
-      buf[size - 1] = 0;
-      break;
-   }
-
-   return strlen(buf) + 1;
-}
-
-#if __USE_FORTIFY_LEVEL > 0 && !defined _CLANG_FORTIFY_DISABLE
-/* Identical to readlink, but with buffer overflow check */
-PUBLIC ssize_t
-__readlink_chk(const char *path, char *buf, size_t size, size_t buflen)
-{
-   if (size > buflen)
-      abort();
-   return readlink(path, buf, size);
-}
-#endif
-
-/* Handles libdrm's realpath to figure out what kind of device we have. */
-PUBLIC char *
-realpath(const char *path, char *resolved_path)
-{
-   init_shim();
-
-   if (strcmp(path, device_path) != 0)
-      return real_realpath(path, resolved_path);
-
-   strcpy(resolved_path, path);
-
-   return resolved_path;
-}
-
-/* Main entrypoint to DRM drivers: the ioctl syscall.  We send all ioctls on
- * our DRM fd to drm_shim_ioctl().
- */
-PUBLIC int
-ioctl(int fd, unsigned long request, ...)
-{
-   init_shim();
-
-   va_list ap;
-   va_start(ap, request);
-   void *arg = va_arg(ap, void *);
-   va_end(ap);
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-   if (!shim_fd)
-      return real_ioctl(fd, request, arg);
-
-   return drm_shim_ioctl(fd, request, arg);
-}
-
-/* Gallium uses this to dup the incoming fd on gbm screen creation */
-PUBLIC int
-fcntl(int fd, int cmd, ...)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-
-   va_list ap;
-   va_start(ap, cmd);
-   void *arg = va_arg(ap, void *);
-   va_end(ap);
-
-   int ret = real_fcntl(fd, cmd, arg);
-
-   if (shim_fd && (cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC))
-      drm_shim_fd_register(ret, shim_fd);
-
-   return ret;
-}
-PUBLIC int fcntl64(int, int, ...)
-   __attribute__((alias("fcntl")));
-
-/* I wrote this when trying to fix gallium screen creation, leaving it around
- * since it's probably good to have.
- */
-PUBLIC int
-dup(int fd)
-{
-   init_shim();
-
-   int ret = real_dup(fd);
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-   if (shim_fd && ret >= 0)
-      drm_shim_fd_register(ret, shim_fd);
-
-   return ret;
-}
-
-PUBLIC void *
-mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-   if (shim_fd)
-      return drm_shim_mmap(shim_fd, length, prot, flags, fd, offset);
-
-   return real_mmap(addr, length, prot, flags, fd, offset);
-}
-
-PUBLIC void *
-mmap64(void* addr, size_t length, int prot, int flags, int fd, off64_t offset)
-{
-   init_shim();
-
-   struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
-   if (shim_fd)
-      return drm_shim_mmap(shim_fd, length, prot, flags, fd, offset);
-
-   return real_mmap64(addr, length, prot, flags, fd, offset);
-}
reverted:
--- mesa-24.0.2/.pc/time64.diff/src/intel/tools/intel_sanitize_gpu.c
+++ mesa-24.0.2.orig/.pc/time64.diff/src/intel/tools/intel_sanitize_gpu.c
@@ -1,435 +0,0 @@
-/*
- * Copyright © 2015-2018 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#undef _FILE_OFFSET_BITS /* prevent #define open open64 */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/sysmacros.h>
-#include <dlfcn.h>
-#include <pthread.h>
-#include "drm-uapi/i915_drm.h"
-
-#include "util/hash_table.h"
-#include "util/u_math.h"
-
-#define MESA_LOG_TAG "INTEL-SANITIZE-GPU"
-#include "util/log.h"
-#include "common/intel_mem.h"
-
-static int (*libc_open)(const char *pathname, int flags, mode_t mode);
-static int (*libc_close)(int fd);
-static int (*libc_ioctl)(int fd, unsigned long request, void *argp);
-static int (*libc_fcntl)(int fd, int cmd, int param);
-
-#define DRM_MAJOR 226
-
-/* TODO: we want to make sure that the padding forces
- * the BO to take another page on the (PP)GTT; 4KB
- * may or may not be the page size for the BO. Indeed,
- * depending on GPU, kernel version and GEM size, the
- * page size can be one of 4KB, 64KB or 2M.
- */
-#define PADDING_SIZE 4096
-
-struct refcnt_hash_table {
-   struct hash_table *t;
-   int refcnt;
-};
-
-pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-#define MUTEX_LOCK() do {                        \
-   if (unlikely(pthread_mutex_lock(&mutex))) {   \
-      mesa_loge("mutex_lock failed");           \
-      abort();                                   \
-   }                                             \
-} while (0)
-#define MUTEX_UNLOCK() do {                      \
-   if (unlikely(pthread_mutex_unlock(&mutex))) { \
-      mesa_loge("mutex_unlock failed");         \
-      abort();                                   \
-   }                                             \
-} while (0)
-
-static struct hash_table *fds_to_bo_sizes = NULL;
-
-static inline struct hash_table*
-bo_size_table(int fd)
-{
-   struct hash_entry *e = _mesa_hash_table_search(fds_to_bo_sizes,
-                                                  (void*)(uintptr_t)fd);
-   return e ? ((struct refcnt_hash_table*)e->data)->t : NULL;
-}
-
-static inline uint64_t
-bo_size(int fd, uint32_t handle)
-{
-   struct hash_table *t = bo_size_table(fd);
-   if (!t)
-      return UINT64_MAX;
-   struct hash_entry *e = _mesa_hash_table_search(t, (void*)(uintptr_t)handle);
-   return e ? (uint64_t)(uintptr_t)e->data : UINT64_MAX;
-}
-
-static inline bool
-is_drm_fd(int fd)
-{
-   return !!bo_size_table(fd);
-}
-
-static inline void
-add_drm_fd(int fd)
-{
-   struct refcnt_hash_table *r = malloc(sizeof(*r));
-   r->refcnt = 1;
-   r->t = _mesa_pointer_hash_table_create(NULL);
-   _mesa_hash_table_insert(fds_to_bo_sizes, (void*)(uintptr_t)fd,
-                           (void*)(uintptr_t)r);
-}
-
-static inline void
-dup_drm_fd(int old_fd, int new_fd)
-{
-   struct hash_entry *e = _mesa_hash_table_search(fds_to_bo_sizes,
-                                                  (void*)(uintptr_t)old_fd);
-   struct refcnt_hash_table *r = e->data;
-   r->refcnt++;
-   _mesa_hash_table_insert(fds_to_bo_sizes, (void*)(uintptr_t)new_fd,
-                           (void*)(uintptr_t)r);
-}
-
-static inline void
-del_drm_fd(int fd)
-{
-   struct hash_entry *e = _mesa_hash_table_search(fds_to_bo_sizes,
-                                                  (void*)(uintptr_t)fd);
-   struct refcnt_hash_table *r = e->data;
-   if (!--r->refcnt) {
-      _mesa_hash_table_remove(fds_to_bo_sizes, e);
-      _mesa_hash_table_destroy(r->t, NULL);
-      free(r);
-   }
-}
-
-/* Our goal is not to have noise good enough for crypto,
- * but instead values that are unique-ish enough that
- * it is incredibly unlikely that a buffer overwrite
- * will produce the exact same values.
- */
-static uint8_t
-next_noise_value(uint8_t prev_noise)
-{
-   uint32_t v = prev_noise;
-   return (v * 103u + 227u) & 0xFF;
-}
-
-static void
-fill_noise_buffer(uint8_t *dst, uint8_t start, uint32_t length)
-{
-   for(uint32_t i = 0; i < length; ++i) {
-      dst[i] = start;
-      start = next_noise_value(start);
-   }
-}
-
-static bool
-padding_is_good(int fd, uint32_t handle)
-{
-   struct drm_i915_gem_mmap mmap_arg = {
-      .handle = handle,
-      .offset = align64(bo_size(fd, handle), 4096),
-      .size = PADDING_SIZE,
-      .flags = 0,
-   };
-
-   /* Unknown bo, maybe prime or userptr. Ignore */
-   if (mmap_arg.offset == UINT64_MAX)
-      return true;
-
-   uint8_t *mapped;
-   int ret;
-   uint8_t expected_value;
-
-   ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg);
-   if (ret != 0) {
-      mesa_logd("Unable to map buffer %d for pad checking.", handle);
-      return false;
-   }
-
-   mapped = (uint8_t*) (uintptr_t) mmap_arg.addr_ptr;
-#ifdef SUPPORT_INTEL_INTEGRATED_GPUS
-   /* bah-humbug, we need to see the latest contents and
-    * if the bo is not cache coherent we likely need to
-    * invalidate the cache lines to get it.
-    */
-   intel_invalidate_range(mapped, PADDING_SIZE);
-#endif
-
-   expected_value = handle & 0xFF;
-   for (uint32_t i = 0; i < PADDING_SIZE; ++i) {
-      if (expected_value != mapped[i]) {
-         munmap(mapped, PADDING_SIZE);
-         return false;
-      }
-      expected_value = next_noise_value(expected_value);
-   }
-   munmap(mapped, PADDING_SIZE);
-
-   return true;
-}
-
-static int
-create_with_padding(int fd, struct drm_i915_gem_create *create)
-{
-   uint64_t original_size = create->size;
-
-   create->size = align64(original_size, 4096) + PADDING_SIZE;
-   int ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, create);
-   create->size = original_size;
-
-   if (ret != 0)
-      return ret;
-
-   uint8_t *noise_values;
-   struct drm_i915_gem_mmap mmap_arg = {
-      .handle = create->handle,
-      .offset = align64(create->size, 4096),
-      .size = PADDING_SIZE,
-      .flags = 0,
-   };
-
-   ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg);
-   if (ret != 0) {
-      mesa_logd("Unable to map buffer %d for pad creation.\n", create->handle);
-      return 0;
-   }
-
-   noise_values = (uint8_t*) (uintptr_t) mmap_arg.addr_ptr;
-   fill_noise_buffer(noise_values, create->handle & 0xFF,
-                     PADDING_SIZE);
-   munmap(noise_values, PADDING_SIZE);
-
-   _mesa_hash_table_insert(bo_size_table(fd), (void*)(uintptr_t)create->handle,
-                           (void*)(uintptr_t)create->size);
-
-   return 0;
-}
-
-static int
-exec_and_check_padding(int fd, unsigned long request,
-                       struct drm_i915_gem_execbuffer2 *exec)
-{
-   int ret = libc_ioctl(fd, request, exec);
-   if (ret != 0)
-      return ret;
-
-   struct drm_i915_gem_exec_object2 *objects =
-      (void*)(uintptr_t)exec->buffers_ptr;
-   uint32_t batch_bo = exec->flags & I915_EXEC_BATCH_FIRST ? objects[0].handle :
-      objects[exec->buffer_count - 1].handle;
-
-   struct drm_i915_gem_wait wait = {
-      .bo_handle = batch_bo,
-      .timeout_ns = -1,
-   };
-   ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait);
-   if (ret != 0)
-      return ret;
-
-   bool detected_out_of_bounds_write = false;
-
-   for (int i = 0; i < exec->buffer_count; i++) {
-      uint32_t handle = objects[i].handle;
-
-      if (!padding_is_good(fd, handle)) {
-         detected_out_of_bounds_write = true;
-         mesa_loge("Detected buffer out-of-bounds write in bo %d", handle);
-      }
-   }
-
-   if (unlikely(detected_out_of_bounds_write)) {
-      abort();
-   }
-
-   return 0;
-}
-
-static int
-gem_close(int fd, struct drm_gem_close *close)
-{
-   int ret = libc_ioctl(fd, DRM_IOCTL_GEM_CLOSE, close);
-   if (ret != 0)
-      return ret;
-
-   struct hash_table *t = bo_size_table(fd);
-   struct hash_entry *e =
-      _mesa_hash_table_search(t, (void*)(uintptr_t)close->handle);
-
-   if (e)
-      _mesa_hash_table_remove(t, e);
-
-   return 0;
-}
-
-static bool
-is_i915(int fd) {
-   struct stat stat;
-   if (fstat(fd, &stat))
-      return false;
-
-   if (!S_ISCHR(stat.st_mode) || major(stat.st_rdev) != DRM_MAJOR)
-      return false;
-
-   char name[5] = "";
-   drm_version_t version = {
-      .name = name,
-      .name_len = sizeof(name) - 1,
-   };
-   if (libc_ioctl(fd, DRM_IOCTL_VERSION, &version))
-      return false;
-
-   return strcmp("i915", name) == 0;
-}
-
-__attribute__ ((visibility ("default"))) int
-open(const char *path, int flags, ...)
-{
-   va_list args;
-   mode_t mode;
-
-   va_start(args, flags);
-   mode = va_arg(args, int);
-   va_end(args);
-
-   int fd = libc_open(path, flags, mode);
-
-   MUTEX_LOCK();
-
-   if (fd >= 0 && is_i915(fd))
-      add_drm_fd(fd);
-
-   MUTEX_UNLOCK();
-
-   return fd;
-}
-
-__attribute__ ((visibility ("default"), alias ("open"))) int
-open64(const char *path, int flags, ...);
-
-__attribute__ ((visibility ("default"))) int
-close(int fd)
-{
-   MUTEX_LOCK();
-
-   if (is_drm_fd(fd))
-      del_drm_fd(fd);
-
-   MUTEX_UNLOCK();
-
-   return libc_close(fd);
-}
-
-__attribute__ ((visibility ("default"))) int
-fcntl(int fd, int cmd, ...)
-{
-   va_list args;
-   int param;
-
-   va_start(args, cmd);
-   param = va_arg(args, int);
-   va_end(args);
-
-   int res = libc_fcntl(fd, cmd, param);
-
-   MUTEX_LOCK();
-
-   if (is_drm_fd(fd) && cmd == F_DUPFD_CLOEXEC)
-      dup_drm_fd(fd, res);
-
-   MUTEX_UNLOCK();
-
-   return res;
-}
-
-__attribute__ ((visibility ("default"))) int
-ioctl(int fd, unsigned long request, ...)
-{
-   int res;
-   va_list args;
-   void *argp;
-
-   MUTEX_LOCK();
-
-   va_start(args, request);
-   argp = va_arg(args, void *);
-   va_end(args);
-
-   if (_IOC_TYPE(request) == DRM_IOCTL_BASE && !is_drm_fd(fd) && is_i915(fd)) {
-      mesa_loge("missed drm fd %d", fd);
-      add_drm_fd(fd);
-   }
-
-   if (is_drm_fd(fd)) {
-      switch (request) {
-      case DRM_IOCTL_GEM_CLOSE:
-         res = gem_close(fd, (struct drm_gem_close*)argp);
-         goto out;
-
-      case DRM_IOCTL_I915_GEM_CREATE:
-         res = create_with_padding(fd, (struct drm_i915_gem_create*)argp);
-         goto out;
-
-      case DRM_IOCTL_I915_GEM_EXECBUFFER2:
-      case DRM_IOCTL_I915_GEM_EXECBUFFER2_WR:
-         res = exec_and_check_padding(fd, request,
-                                      (struct drm_i915_gem_execbuffer2*)argp);
-         goto out;
-
-      default:
-         break;
-      }
-   }
-   res = libc_ioctl(fd, request, argp);
-
- out:
-   MUTEX_UNLOCK();
-   return res;
-}
-
-static void __attribute__ ((constructor))
-init(void)
-{
-   fds_to_bo_sizes = _mesa_pointer_hash_table_create(NULL);
-   libc_open = dlsym(RTLD_NEXT, "open");
-   libc_close = dlsym(RTLD_NEXT, "close");
-   libc_fcntl = dlsym(RTLD_NEXT, "fcntl");
-   libc_ioctl = dlsym(RTLD_NEXT, "ioctl");
-}
diff -u mesa-24.0.2/debian/changelog mesa-24.0.2/debian/changelog
--- mesa-24.0.2/debian/changelog
+++ mesa-24.0.2/debian/changelog
@@ -1,4 +1,4 @@
-mesa (24.0.2-1ubuntu5) noble; urgency=medium
+mesa (24.0.2-1ubuntu6) noble; urgency=medium
 
   * Fix time64 build.
 
diff -u mesa-24.0.2/debian/patches/series mesa-24.0.2/debian/patches/series
--- mesa-24.0.2/debian/patches/series
+++ mesa-24.0.2/debian/patches/series
@@ -3,3 +3,4 @@
 src_glx_dri_common.h.diff
 fix-zink-logging.diff
 radeon-fix-gnome-shell-crash.diff
+time64.diff
reverted:
--- mesa-24.0.2/patches/series
+++ mesa-24.0.2.orig/patches/series
@@ -1 +0,0 @@
-time64.diff
reverted:
--- mesa-24.0.2/patches/time64.diff
+++ mesa-24.0.2.orig/patches/time64.diff
@@ -1,20 +0,0 @@
---- a/src/drm-shim/drm_shim.c
-+++ b/src/drm-shim/drm_shim.c
-@@ -30,6 +30,7 @@
- 
- /* Prevent glibc from defining open64 when we want to alias it. */
- #undef _FILE_OFFSET_BITS
-+#undef _TIME_BITS
- #define _LARGEFILE64_SOURCE
- 
- #include <stdbool.h>
---- a/src/intel/tools/intel_sanitize_gpu.c
-+++ b/src/intel/tools/intel_sanitize_gpu.c
-@@ -22,6 +22,7 @@
-  */
- 
- #undef _FILE_OFFSET_BITS /* prevent #define open open64 */
-+#undef _TIME_BITS
- 
- #include <string.h>
- #include <stdlib.h>
reverted:
--- mesa-24.0.2/src/drm-shim/drm_shim.c
+++ mesa-24.0.2.orig/src/drm-shim/drm_shim.c
@@ -30,7 +30,6 @@
 
 /* Prevent glibc from defining open64 when we want to alias it. */
 #undef _FILE_OFFSET_BITS
-#undef _TIME_BITS
 #define _LARGEFILE64_SOURCE
 
 #include <stdbool.h>
reverted:
--- mesa-24.0.2/src/intel/tools/intel_sanitize_gpu.c
+++ mesa-24.0.2.orig/src/intel/tools/intel_sanitize_gpu.c
@@ -22,7 +22,6 @@
  */
 
 #undef _FILE_OFFSET_BITS /* prevent #define open open64 */
-#undef _TIME_BITS
 
 #include <string.h>
 #include <stdlib.h>
only in patch2:
unchanged:
--- mesa-24.0.2.orig/debian/patches/time64.diff
+++ mesa-24.0.2/debian/patches/time64.diff
@@ -0,0 +1,20 @@
+--- a/src/drm-shim/drm_shim.c
++++ b/src/drm-shim/drm_shim.c
+@@ -30,6 +30,7 @@
+ 
+ /* Prevent glibc from defining open64 when we want to alias it. */
+ #undef _FILE_OFFSET_BITS
++#undef _TIME_BITS
+ #define _LARGEFILE64_SOURCE
+ 
+ #include <stdbool.h>
+--- a/src/intel/tools/intel_sanitize_gpu.c
++++ b/src/intel/tools/intel_sanitize_gpu.c
+@@ -22,6 +22,7 @@
+  */
+ 
+ #undef _FILE_OFFSET_BITS /* prevent #define open open64 */
++#undef _TIME_BITS
+ 
+ #include <string.h>
+ #include <stdlib.h>

Reply to: