Selaa lähdekoodia

* Add runtime dynamic loader / symbol table handling

Bryan Drewery 16 vuotta sitten
vanhempi
commit
07930cb0cb
4 muutettua tiedostoa jossa 71 lisäystä ja 0 poistoa
  1. 1 0
      src/Makefile.in
  2. 35 0
      src/dl.c
  3. 34 0
      src/dl.h
  4. 1 0
      src/types.h

+ 1 - 0
src/Makefile.in

@@ -29,6 +29,7 @@ OBJS = auth.o \
 	dcc.o \
 	dccutil.o \
 	debug.o \
+	dl.o \
 	egg_timer.o \
 	enclink.o \
 	EncryptedStream.o \

+ 35 - 0
src/dl.c

@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 1997 Robey Pointer
+ * Copyright (C) 1999 - 2002 Eggheads Development Team
+ * Copyright (C) 2002 - 2010 Bryan Drewery
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+ * dl.c -- handles:
+ *   dlopen/dlsym and symbol table handling
+ *
+ */
+
+
+#include "common.h"
+#include "main.h"
+#include "dl.h"
+#include <bdlib/src/String.h>
+#include <bdlib/src/Array.h>
+#include <bdlib/src/HashTable.h>
+
+bd::HashTable<bd::String, FunctionPtr> dl_symbol_table;

+ 34 - 0
src/dl.h

@@ -0,0 +1,34 @@
+#ifndef _DL_H
+#define _DL_H
+
+#include "common.h"
+#include <dlfcn.h>
+
+#include <bdlib/src/String.h>
+#include <bdlib/src/HashTable.h>
+
+#define DLSYM(_handle, x) \
+  dlerror(); \
+  x##_t x; \
+  *(void **) (&x) = dlsym(_handle, #x); \
+  dlsym_error = dlerror(); \
+  if (dlsym_error) { \
+    sdprintf("%s", dlsym_error); \
+    return(1); \
+  }
+
+#define DLSYM_GLOBAL(_handle, x) do { \
+  dlerror(); \
+  dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x)); \
+  dlsym_error = dlerror(); \
+  if (dlsym_error) { \
+    sdprintf("%s", dlsym_error); \
+    return(1); \
+  } \
+} while (0)
+
+#define DLSYM_VAR(x) ((x##_t)dl_symbol_table[#x])
+
+extern bd::HashTable<bd::String, FunctionPtr> dl_symbol_table;
+
+#endif /* !_DL_H_ */

+ 1 - 0
src/types.h

@@ -15,6 +15,7 @@
 
 /* It's used in so many places, let's put it here */
 typedef int (*Function) ();
+typedef intptr_t (*FunctionPtr) ();
 
 #if !HAVE_SOCKLEN_T
 typedef int socklen_t;