From 75d3372ac4784383f6cdc8b5260098f81f8b2751 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 24 Jul 2013 16:48:02 -0700 Subject: [PATCH] Initial commit of glaze, a thin, shiny wrapper for OpenGL The basic mechanic is in place here to create a pass-through ifunc for every function in a list of functions. The current list is the tiniest stub so far, (nothing but glClear). And there is not yet any mechanism to do selective substitution of any OpenGL functions, (so glaze cannot actually be used for anything yet). --- .gitignore | 2 ++ Makefile | 18 ++++++++++++++ glapi.def | 1 + glaze.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 glapi.def create mode 100644 glaze.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..463ea60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib32 +lib64 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7bb7447 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC ?= gcc +CFLAGS ?= -g +CFLAGS += -Wall -Wextra -Wmissing-declarations -Werror=attributes + +TARGETS = lib64/libGL.so.1 lib32/libGL.so.1 + +all: $(TARGETS) + +lib64/libGL.so.1: glaze.c glapi.def + mkdir -p lib64 + $(CC) $(CFLAGS) -m64 -fPIC -shared -Wl,-Bsymbolic -o $@ $< + +lib32/libGL.so.1: glaze.c glapi.def + mkdir -p lib32 + $(CC) $(CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $< + +clean: + rm -f $(TARGETS) diff --git a/glapi.def b/glapi.def new file mode 100644 index 0000000..97372a2 --- /dev/null +++ b/glapi.def @@ -0,0 +1 @@ +GLAZE_API(glClear) diff --git a/glaze.c b/glaze.c new file mode 100644 index 0000000..5ad3af3 --- /dev/null +++ b/glaze.c @@ -0,0 +1,71 @@ +/* Copyright © 2013, 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 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. + */ + +#define _GNU_SOURCE +#include + +#include +#include + +void *libgl_handle; + +static void +open_libgl_handle (void) +{ + const char *path; + + if (libgl_handle) + return; + + path = getenv ("GLAZE_LIBGL"); + if (path == NULL) { + fprintf (stderr, "GLAZE_LIBGL unset. Please set to path of real libGL.so under glaze.\n"); + exit (1); + } + + libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL); + if (libgl_handle == NULL) { + fprintf (stderr, "Error: Failed to dlopen %s\n", path); + exit (1); + } +} + +static void +glaze_init (void) __attribute__((constructor)); + +static void +glaze_init (void) +{ + open_libgl_handle (); +} + +static void * +resolve (const char *name) +{ + return dlsym (libgl_handle, name); +} + +#define GLAZE_API(name) \ +void * name() __attribute__((ifunc(#name "_resolver"))); \ +static void * \ +name ## _resolver (void) { return resolve (#name); } + +#include "glapi.def" -- 2.43.0