source: build-files/ports-overlay/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-common-crOpenGL-fakedri_drv.c @ 1e102bd

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 1e102bd was 1e102bd, checked in by Kris Moore <kris@…>, 9 months ago

Add a bunch of modified ports for 10.0, so we can fix the building

  • Property mode set to 100644
File size: 3.1 KB
Line 
1--- src/VBox/Additions/common/crOpenGL/fakedri_drv.c.orig       2012-12-19 13:25:04.000000000 -0500
2+++ src/VBox/Additions/common/crOpenGL/fakedri_drv.c    2013-01-27 17:57:04.000000000 -0500
3@@ -29,6 +29,15 @@
4 #include <dlfcn.h>
5 #include <elf.h>
6 #include <unistd.h>
7+
8+#include <sys/param.h>
9+#if defined(BSD)
10+#include <fcntl.h>
11+#include <gelf.h>
12+#include <libelf.h>
13+#include <string.h>
14+#endif
15+
16 /** X server message type definitions. */
17 typedef enum {
18     X_PROBED,                  /* Value was probed */
19@@ -50,11 +59,11 @@
20 
21 //@todo this could be different...
22 #ifdef RT_ARCH_AMD64
23-# define DRI_DEFAULT_DRIVER_DIR "/usr/lib64/dri:/usr/lib/dri:/usr/lib/x86_64-linux-gnu/dri"
24-# define DRI_XORG_DRV_DIR "/usr/lib/xorg/modules/drivers/"
25+# define DRI_DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
26+# define DRI_XORG_DRV_DIR "/usr/local/lib/xorg/modules/drivers/"
27 #else
28-# define DRI_DEFAULT_DRIVER_DIR "/usr/lib/dri:/usr/lib/i386-linux-gnu/dri"
29-# define DRI_XORG_DRV_DIR "/usr/lib/xorg/modules/drivers/"
30+# define DRI_DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
31+# define DRI_XORG_DRV_DIR "/usr/local/lib/xorg/modules/drivers/"
32 #endif
33 
34 #ifdef DEBUG_DRI_CALLS
35@@ -209,6 +218,85 @@
36 
37 #define FAKEDRI_JMP64_PATCH_SIZE 13
38 
39+#if defined(BSD)
40+/* Provide basic dladdr1 flags */
41+enum {
42+       RTLD_DL_SYMENT  = 1
43+};
44+
45+/* Provide a minimal local version of dladdr1 */
46+static int
47+dladdr1(const void *address, Dl_info *dlip, void **info, int flags)
48+{
49+       static DRI_ELFSYM desym;
50+       GElf_Sym sym;
51+       GElf_Shdr shdr;
52+       Elf *elf;
53+       Elf_Scn *scn;
54+       Elf_Data *data;
55+       int ret, fd, count, i;
56+
57+       /* Initialize variables */
58+       fd = -1;
59+       elf = NULL;
60+
61+       /* Call dladdr first */
62+       ret = dladdr(address, dlip);
63+       if (ret == 0) goto err_exit;
64+
65+       /* Check for supported flags */
66+       if (flags != RTLD_DL_SYMENT) return 1;
67+
68+       /* Open shared library's ELF file */
69+       if (elf_version(EV_CURRENT) == EV_NONE) goto err_exit;
70+       fd = open(dlip->dli_fname, O_RDONLY);
71+       if (fd < 0) goto err_exit;
72+       elf = elf_begin(fd, ELF_C_READ, NULL);
73+       if (elf == NULL) goto err_exit;
74+
75+       /* Find the '.dynsym' section */
76+       scn = elf_nextscn(elf, NULL);
77+       while (scn != NULL) {
78+               if (gelf_getshdr(scn, &shdr) == NULL) goto err_exit;
79+               if (shdr.sh_type == SHT_DYNSYM) break;
80+               scn = elf_nextscn(elf, scn);
81+       }
82+       if (scn == NULL) goto err_exit;
83+
84+       /* Search for the requested symbol by name and offset */
85+       data = elf_getdata(scn, NULL);
86+       count = shdr.sh_size / shdr.sh_entsize;
87+       for (i = 0; i < count; i++) {
88+               gelf_getsym(data, i, &sym);
89+               if ((strcmp(dlip->dli_sname,
90+                       elf_strptr(elf, shdr.sh_link, sym.st_name)) == 0) &&
91+                   (sym.st_value == (dlip->dli_saddr - dlip->dli_fbase))) {
92+                       break;
93+               }
94+       }
95+
96+       /* Close ELF file */
97+       elf_end(elf);
98+       close(fd);
99+
100+       /* Return symbol entry in native format */
101+       desym.st_name = sym.st_name;
102+       desym.st_info = sym.st_info;
103+       desym.st_other = sym.st_other;
104+       desym.st_shndx = sym.st_shndx;
105+       desym.st_value = sym.st_value;
106+       desym.st_size = sym.st_size;
107+       *info = &desym;
108+       return 1;
109+
110+       /* Error handler */
111+err_exit:
112+       if (elf != NULL) elf_end(elf);
113+       if (fd >= 0) close(fd);
114+       return 0;
115+}
116+#endif
117+
118 static void
119 vboxPatchMesaExport(const char* psFuncName, const void *pStart, const void *pEnd)
120 {
Note: See TracBrowser for help on using the repository browser.