[Galago-commits] r1926 - in trunk/galago-daemon: . src

galago-commits at freedesktop.org galago-commits at freedesktop.org
Sun Jun 5 16:00:14 PDT 2005


Author: chipx86
Date: 2005-06-05 16:00:07 -0700 (Sun, 05 Jun 2005)
New Revision: 1926

Modified:
   trunk/galago-daemon/ChangeLog
   trunk/galago-daemon/NEWS
   trunk/galago-daemon/src/prefix.c
   trunk/galago-daemon/src/prefix.h
Log:
Upgraded binreloc, fixing some portability issues with x86_64, gcc4, and when disabling binreloc during compile time


Modified: trunk/galago-daemon/ChangeLog
===================================================================
--- trunk/galago-daemon/ChangeLog	2005-06-05 22:48:23 UTC (rev 1925)
+++ trunk/galago-daemon/ChangeLog	2005-06-05 23:00:07 UTC (rev 1926)
@@ -1,3 +1,11 @@
+Sun Jun 05 15:59:18 PDT 2005  Christian Hammond <chipx86 at chipx86.com>
+
+	* src/prefix.c:
+	* src/prefix.h:
+	* NEWS:
+	  - Upgraded binreloc, fixing some portability issues with x86_64, gcc4,
+	    and when disabling binreloc during compile time.
+
 Sun Jun 05 15:47:41 PDT 2005  Christian Hammond <chipx86 at chipx86.com>
 
 	* Makefile.am:

Modified: trunk/galago-daemon/NEWS
===================================================================
--- trunk/galago-daemon/NEWS	2005-06-05 22:48:23 UTC (rev 1925)
+++ trunk/galago-daemon/NEWS	2005-06-05 23:00:07 UTC (rev 1926)
@@ -1,5 +1,7 @@
 version 0.3.3:
 	* Fixed a packaging issue where galago-daemon.service wasn't being rebuilt.
+	* Upgraded binreloc, fixing some portability issues with x86_64, gcc4,
+	  and when disabling binreloc during compile time.
 
 version 0.3.2 (May 26, 2005):
 	* Added suppor for D-BUS 0.3x. 0.23.x is the minimum version required.

Modified: trunk/galago-daemon/src/prefix.c
===================================================================
--- trunk/galago-daemon/src/prefix.c	2005-06-05 22:48:23 UTC (rev 1925)
+++ trunk/galago-daemon/src/prefix.c	2005-06-05 23:00:07 UTC (rev 1926)
@@ -30,10 +30,10 @@
 	#include "config.h"
 #endif
 
-#ifndef BR_GTHREADS
-	/* Change 1 to 0 if you don't want gthread support */
-	#define BR_GTHREADS 1
-#endif /* BR_GTHREADS */
+#ifndef BR_PTHREADS
+	/* Change 1 to 0 if you don't want pthread support */
+	#define BR_PTHREADS 1
+#endif /* BR_PTHREADS */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -56,6 +56,10 @@
 #endif /* __GNUC__ */
 
 
+static br_locate_fallback_func fallback_func = (br_locate_fallback_func) NULL;
+static void *fallback_data = NULL;
+
+
 #ifdef ENABLE_BINRELOC
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -104,8 +108,12 @@
 	br_return_val_if_fail (symbol != NULL, NULL);
 
 	f = fopen ("/proc/self/maps", "r");
-	if (!f)
-		return NULL;
+	if (!f) {
+		if (fallback_func)
+			return fallback_func(symbol, fallback_data);
+		else
+			return NULL;
+	}
 
 	while (!feof (f))
 	{
@@ -216,20 +224,28 @@
 #endif /* ENABLE_BINRELOC */
 
 
-/* gthread stuff for thread safetiness */
-#if BR_GTHREADS
+/* Pthread stuff for thread safetiness */
+#if BR_PTHREADS && defined(ENABLE_BINRELOC)
 
-#include <glib/gthread.h>
+#include <pthread.h>
 
-static GStaticPrivate br_thread_key = G_STATIC_PRIVATE_INIT;
-static GOnce br_thread_key_once = G_ONCE_INIT;
+static pthread_key_t br_thread_key;
+static pthread_once_t br_thread_key_once = PTHREAD_ONCE_INIT;
 
 
 static void
 br_thread_local_store_fini ()
 {
-	g_static_private_free (&br_thread_key);
-	br_thread_key.index = 0;
+	char *specific;
+
+	specific = (char *) pthread_getspecific (br_thread_key);
+	if (specific)
+	{
+		free (specific);
+		pthread_setspecific (br_thread_key, NULL);
+	}
+	pthread_key_delete (br_thread_key);
+	br_thread_key = 0;
 }
 
 
@@ -242,13 +258,14 @@
 
 
 static void
-br_thread_local_store_init (void *dummy)
+br_thread_local_store_init ()
 {
-  g_static_private_init (&br_thread_key);
-  atexit (br_thread_local_store_fini);
+	if (pthread_key_create (&br_thread_key, br_str_free) == 0)
+		atexit (br_thread_local_store_fini);
 }
 
-#else /* BR_GTHREADS */
+#else /* BR_PTHREADS */
+#ifdef ENABLE_BINRELOC
 
 static char *br_last_value = (char *) NULL;
 
@@ -259,9 +276,12 @@
 		free (br_last_value);
 }
 
-#endif /* BR_GTHREADS */
+#endif /* ENABLE_BINRELOC */
+#endif /* BR_PTHREADS */
 
 
+#ifdef ENABLE_BINRELOC
+
 /**
  * br_thread_local_store:
  * str: A dynamically allocated string.
@@ -270,23 +290,28 @@
  * Store str in a thread-local variable and return str. The next
  * you run this function, that variable is freed too.
  * This function is created so you don't have to worry about freeing
- * strings.
+ * strings. Just be careful about doing this sort of thing:
  *
- * Example:
+ * some_function( BR_DATADIR("/one.png"), BR_DATADIR("/two.png") )
+ *
+ * Examples:
  * char *foo;
- * foo = thread_local_store (strdup ("hello")); --> foo == "hello"
- * foo = thread_local_store (strdup ("world")); --> foo == "world"; "hello" is now freed.
+ * foo = br_thread_local_store (strdup ("hello")); --> foo == "hello"
+ * foo = br_thread_local_store (strdup ("world")); --> foo == "world"; "hello" is now freed.
  */
 const char *
 br_thread_local_store (char *str)
 {
-#if BR_GTHREADS
-		g_once (&br_thread_key_once, (GThreadFunc)br_thread_local_store_init,
-				NULL);
+	#if BR_PTHREADS
+		char *specific;
 
-		g_static_private_set (&br_thread_key, str, br_str_free);
+		pthread_once (&br_thread_key_once, br_thread_local_store_init);
 
-#else /* BR_GTHREADS */
+		specific = (char *) pthread_getspecific (br_thread_key);
+		br_str_free (specific);
+		pthread_setspecific (br_thread_key, str);
+
+	#else /* BR_PTHREADS */
 		static int initialized = 0;
 
 		if (!initialized)
@@ -298,12 +323,14 @@
 		if (br_last_value)
 			free (br_last_value);
 		br_last_value = str;
-#endif /* BR_GTHREADS */
+	#endif /* BR_PTHREADS */
 
 	return (const char *) str;
 }
 
+#endif /* ENABLE_BINRELOC */
 
+
 /**
  * br_strcat:
  * str1: A string.
@@ -431,6 +458,23 @@
 }
 
 
+/**
+ * br_set_fallback_function:
+ * func: A function to call to find the binary.
+ * data: User data to pass to func.
+ *
+ * Sets a function to call to find the path to the binary, in
+ * case "/proc/self/maps" can't be opened. The function set should
+ * return a string that is safe to free with free().
+ */
+void
+br_set_locate_fallback_func (br_locate_fallback_func func, void *data)
+{
+	fallback_func = func;
+	fallback_data = data;
+}
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: trunk/galago-daemon/src/prefix.h
===================================================================
--- trunk/galago-daemon/src/prefix.h	2005-06-05 22:48:23 UTC (rev 1925)
+++ trunk/galago-daemon/src/prefix.h	2005-06-05 23:00:07 UTC (rev 1926)
@@ -77,15 +77,15 @@
 /* The following functions are used internally by BinReloc
    and shouldn't be used directly in applications. */
 
-const char *br_thread_local_store (char *str);
 char *br_locate		(void *symbol);
 char *br_locate_prefix	(void *symbol);
 char *br_prepend_prefix	(void *symbol, char *path);
 
-
 #endif /* ENABLE_BINRELOC */
 
+const char *br_thread_local_store (char *str);
 
+
 /* These macros and functions are not guarded by the ENABLE_BINRELOC
  * macro because they are portable. You can use these functions.
  */
@@ -93,9 +93,23 @@
 #define br_strcat BR_NAMESPACE(br_strcat)
 #define br_extract_dir BR_NAMESPACE(br_extract_dir)
 #define br_extract_prefix BR_NAMESPACE(br_extract_prefix)
+#define br_set_locate_fallback_func BR_NAMESPACE(br_set_locate_fallback_func)
 
 #ifndef BR_NO_MACROS
-	/* Convenience functions for concatenating paths */
+  #ifndef ENABLE_BINRELOC        
+	#define BR_SELFPATH(suffix)	SELFPATH suffix
+	#define BR_PREFIX(suffix)	PREFIX suffix
+	#define BR_PREFIXDIR(suffix)	BR_PREFIX suffix
+	#define BR_BINDIR(suffix)	BINDIR suffix
+	#define BR_SBINDIR(suffix)	SBINDIR suffix
+	#define BR_DATADIR(suffix)	DATADIR suffix
+	#define BR_LIBDIR(suffix)	LIBDIR suffix
+	#define BR_LIBEXECDIR(suffix)	LIBEXECDIR suffix
+	#define BR_ETCDIR(suffix)	ETCDIR suffix
+	#define BR_SYSCONFDIR(suffix)	SYSCONFDIR suffix
+	#define BR_CONFDIR(suffix)	CONFDIR suffix
+	#define BR_LOCALEDIR(suffix)	LOCALEDIR suffix
+  #else
 	#define BR_SELFPATH(suffix)	(br_thread_local_store (br_strcat (SELFPATH, suffix)))
 	#define BR_PREFIX(suffix)	(br_thread_local_store (br_strcat (PREFIX, suffix)))
 	#define BR_PREFIXDIR(suffix)	(br_thread_local_store (br_strcat (BR_PREFIX, suffix)))
@@ -107,12 +121,15 @@
 	#define BR_ETCDIR(suffix)	(br_thread_local_store (br_strcat (ETCDIR, suffix)))
 	#define BR_SYSCONFDIR(suffix)	(br_thread_local_store (br_strcat (SYSCONFDIR, suffix)))
 	#define BR_CONFDIR(suffix)	(br_thread_local_store (br_strcat (CONFDIR, suffix)))
-	#define BR_LOCALEDIR(suffix)	(br_thread_local_store (br_strcat (LOCALEDIR, suffix)))
+	#define BR_LOCALEDIR(suffix)	(br_thread_local_store (br_strcat (LOCALEDIR, suffix)))        
+  #endif
 #endif
 
 char *br_strcat	(const char *str1, const char *str2);
 char *br_extract_dir	(const char *path);
 char *br_extract_prefix(const char *path);
+typedef char *(*br_locate_fallback_func) (void *symbol, void *data);
+void br_set_locate_fallback_func (br_locate_fallback_func func, void *data);
 
 
 #ifdef __cplusplus



More information about the galago-commits mailing list