ソースを参照

loader simplified

Alexander Shiryaev 12 年 前
コミット
ef16679dea

+ 0 - 48
BlackBox/_LinuxOpenBSD_/Lin/Rsrc/loader/BlackBox-dl.c

@@ -1,48 +0,0 @@
-#include <dlfcn.h>
-#include <stdio.h>
-
-int main (int argc, char *argv[])
-{
-	void * h;
-	/*
-	void * h1;
-	void (*SetKernelBaseStack) (int);
-	void (*Init) (void);
-	*/
-	int res;
-
-	h = dlopen("libBB.so", RTLD_LAZY | RTLD_GLOBAL);
-	if (h != NULL) {
-		/*
-		h1 = dlsym(h, "SetKernelBaseStack");
-		if (h1 != NULL) {
-			*(void **) (&SetKernelBaseStack) = h1;
-			h1 = dlsym(h, "Init");
-			if (h1 != NULL) {
-				*(void **) (&Init) = h1;
-
-				asm ("movl %%esp, %[res]" : [res] "=m" (res) );
-				SetKernelBaseStack(res - 8);
-
-				printf("before Init()\n");
-				Init();
-				printf("after Init()\n");
-
-				res = 0;
-			} else {
-				perror(dlerror());
-				res = 3;
-			}
-		} else {
-			perror(dlerror());
-			res = 2;
-		}
-		*/
-		res = 0;
-	} else {
-		perror(dlerror());
-		res = 1;
-	}
-
-	return res;
-}

+ 0 - 4
BlackBox/_LinuxOpenBSD_/Lin/Rsrc/loader/BlackBox.c

@@ -1,4 +0,0 @@
-int main (int argc, char *argv[])
-{
-	return 0;
-}

+ 0 - 24
BlackBox/_LinuxOpenBSD_/Lin/Rsrc/loader/BlackBox1.c

@@ -1,24 +0,0 @@
-// #include <stdio.h>
-
-// extern void SetKernelBaseStack (int);
-extern void Init (void);
-
-int main (int argc, char *argv[])
-{
-	// int res;
-
-	// printf("START\n");
-
-	/* 2012.09.02: This is from oberoncore.ru
-		2012.09.05: not required in case of static linking of shared library (-lBB) */
-	// asm ("movl %%esp, %[res]" : [res] "=m" (res) );
-	// SetKernelBaseStack(res - 8);
-	// printf("SetKernelBaseStack(0x%02x): done\n", res - 8);
-	// <return adr> <caller ebp> -> base stack = locals of main proc
-
-	Init();
-
-	// printf("END\n");
-
-	return 0;
-}

+ 0 - 18
BlackBox/_LinuxOpenBSD_/Lin/Rsrc/loader/dev0.c

@@ -1,18 +0,0 @@
-#include <dlfcn.h>
-#include <stdio.h>
-
-int main (int argc, char *argv[])
-{
-	void * h;
-	int res;
-
-	h = dlopen("libBB0.so", RTLD_LAZY | RTLD_GLOBAL);
-	if (h != NULL) {
-		res = 0;
-	} else {
-		perror(dlerror());
-		res = 1;
-	}
-
-	return res;
-}

+ 23 - 0
BlackBox/_LinuxOpenBSD_/Lin/Rsrc/loader/loader.c

@@ -0,0 +1,23 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+int main (int argc, char *argv[])
+{
+	void * h;
+	int res;
+
+	if (argc == 2) {
+		h = dlopen(argv[1], RTLD_LAZY | RTLD_GLOBAL);
+		if (h != NULL) {
+			res = 0;
+		} else {
+			perror(dlerror());
+			res = 2;
+		}
+	} else {
+		fprintf(stderr, "usage: %s file.so\n", argv[0]);
+		res = 1;
+	}
+
+	return res;
+}

+ 0 - 1
BlackBox/_Linux_/BlackBox

@@ -1 +0,0 @@
-Lin/Rsrc/loader/BlackBox

+ 3 - 9
BlackBox/_Linux_/Lin/Rsrc/loader/Makefile

@@ -4,18 +4,12 @@
 # ${.ALLSRC}    $^
 # ${.IMPSRC}    $<
 
-all: dev0 BlackBox
+all: loader
 
 CFLAGS += -Wall -O0 -g -m32
 
-#BlackBox: BlackBox.c
-#	${CC} ${CFLAGS} -o $@ $^ -L. -lBB
-
-BlackBox: BlackBox-dl.c
-	${CC} ${CFLAGS} -o $@ $^ -ldl
-
-dev0: dev0.c
+loader: loader.c
 	${CC} ${CFLAGS} -o $@ $^ -ldl
 
 clean:
-	rm -f dev0 BlackBox
+	rm -f loader

+ 0 - 1
BlackBox/_Linux_/Lin/Rsrc/loader/libBB.so

@@ -1 +0,0 @@
-../../../libBB.so

+ 0 - 1
BlackBox/_Linux_/Lin/Rsrc/loader/libBB0.so

@@ -1 +0,0 @@
-../../../libBB0.so

+ 0 - 1
BlackBox/_Linux_/dev0

@@ -1 +0,0 @@
-Lin/Rsrc/loader/dev0

+ 0 - 1
BlackBox/_OpenBSD_/BlackBox

@@ -1 +0,0 @@
-Lin/Rsrc/loader/BlackBox

+ 3 - 12
BlackBox/_OpenBSD_/Lin/Rsrc/loader/Makefile

@@ -6,21 +6,12 @@
 
 CFLAGS += -Wall -O0 -g
 
-all: dev0 BlackBox
+all: loader
 
 # -pthread required to dlopen libraries that depends on pthread
 
-#BlackBox: BlackBox.c
-#	${CC} ${CFLAGS} -o ${.TARGET} ${.ALLSRC} -L. -lBB -pthread
-
-BlackBox: BlackBox-dl.c
+loader: loader.c
 	${CC} ${CFLAGS} -o ${.TARGET} ${.ALLSRC} -pthread
 
-#dev0: BlackBox1.c
-#	${CC} ${CFLAGS} -o ${.TARGET} ${.ALLSRC} -L . -lBB0
-
-dev0: dev0.c
-	${CC} ${CFLAGS} -o ${.TARGET} ${.ALLSRC}
-
 clean:
-	rm -f dev0 BlackBox
+	rm -f loader

+ 0 - 1
BlackBox/_OpenBSD_/Lin/Rsrc/loader/libBB.so

@@ -1 +0,0 @@
-../../../libBB.so

+ 0 - 1
BlackBox/_OpenBSD_/Lin/Rsrc/loader/libBB0.so

@@ -1 +0,0 @@
-../../../libBB0.so

+ 0 - 1
BlackBox/_OpenBSD_/dev0

@@ -1 +0,0 @@
-Lin/Rsrc/loader/dev0

BIN
BlackBox/_OpenBSD_/libBB0.so


+ 1 - 1
BlackBox/run-BlackBox

@@ -7,7 +7,7 @@ rn=`readlink -f "${0}"`
 pd=`dirname "${rn}"`
 sd=`readlink -f .`
 
-exe="BlackBox"
+exe="loader"
 lib="libBB.so"
 
 # export LD_DEBUG=all

+ 16 - 2
BlackBox/run-dev0

@@ -1,4 +1,18 @@
 #!/bin/sh
 
-# env LD_LIBRARY_PATH=. env LD_DEBUG=1 ./dev0
-env LD_LIBRARY_PATH=. ./dev0
+# ulimit -s 32000
+# ulimit -a
+
+rn=`readlink -f "${0}"`
+pd=`dirname "${rn}"`
+sd=`readlink -f .`
+
+exe="loader"
+lib="libBB0.so"
+
+# export LD_DEBUG=all
+env \
+	LD_LIBRARY_PATH="${pd}" \
+	BB_PRIMARY_DIR="${pd}" BB_SECONDARY_DIR="${sd}" \
+	BB_PACKED_NAME="${lib}" \
+	"${pd}"/${exe} "${lib}"

+ 1 - 1
README

@@ -14,7 +14,7 @@ How to build:
 		cd BlackBox/Lin/Rsrc/loader
 		make clean
 		make
-		mv BlackBox dev0 ../../../_`uname -s`_/Lin/Rsrc/loader/
+		mv loader ../../../_`uname -s`_/
 
 	compile self:
 		cd BlackBox