浏览代码

experimental BlackBox-dl c-loader added

Alexander Shiryaev 12 年之前
父节点
当前提交
be5407bd95
共有 5 个文件被更改,包括 50 次插入6 次删除
  1. 1 1
      BlackBox/tests
  2. 43 0
      c/BlackBox-dl.c
  3. 0 2
      c/BlackBox.c
  4. 1 1
      c/BlackBox1.c
  5. 5 2
      c/Makefile

+ 1 - 1
BlackBox/tests

@@ -11,7 +11,7 @@ ConsCompiler.Compile('Obx/Mod', 'Pi.odc')
 # what is source of errors???
 ConsCompiler.Compile('', 'HostFonts.txt')
 
-DevElfLinker.LinkDll libBB.so := Kernel+ Files HostFiles StdLoader
+DevElfLinker.LinkDll libBB.so := Kernel+ Kernel_so_init# Files HostFiles StdLoader
 DATA
 
 ./run-BlackBox <<DATA

+ 43 - 0
c/BlackBox-dl.c

@@ -0,0 +1,43 @@
+#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;
+		}
+	} else {
+		perror(dlerror());
+		res = 1;
+	}
+
+	return res;
+}

+ 0 - 2
c/BlackBox.c

@@ -1,5 +1,3 @@
-#include <stdio.h>
-
 int main (int argc, char *argv[])
 {
 	return 0;

+ 1 - 1
c/BlackBox1.c

@@ -1,4 +1,4 @@
-#include <stdio.h>
+// #include <stdio.h>
 
 // extern void SetKernelBaseStack (int);
 extern void Init (void);

+ 5 - 2
c/Makefile

@@ -1,4 +1,4 @@
-all: libdlobsdwrap.so lindev BlackBox
+all: libdlobsdwrap.so lindev BlackBox BlackBox-dl
 
 # libdlobsdwrap.so: universal method of correct access to dl* functions
 #	in case of dynamic loading of libBB*.so "ld.so" in LibDl may be used instead of "libc.so", but not in case of static linking
@@ -8,6 +8,9 @@ all: libdlobsdwrap.so lindev BlackBox
 BlackBox: BlackBox.c
 	${CC} ${CFLAGS} -Wall -O0 -g -o ${.TARGET} ${.ALLSRC} -L. -lBB -Wl,-E -pthread -ldlobsdwrap
 
+BlackBox-dl: BlackBox-dl.c
+	${CC} ${CFLAGS} -Wall -O0 -g -o ${.TARGET} ${.ALLSRC} -pthread
+
 lindev: BlackBox1.c
 	${CC} ${CFLAGS} -Wall -O0 -g -o ${.TARGET} ${.ALLSRC} -L . -lBB0 -ldlobsdwrap
 
@@ -15,4 +18,4 @@ libdlobsdwrap.so: libdlobsdwrap.c
 	${CC} ${CFLAGS} -Wall -O0 -g -o ${.TARGET} ${.ALLSRC} -fPIC -shared
 
 clean:
-	rm -f lindev BlackBox libdlobsdwrap.so
+	rm -f lindev BlackBox BlackBox-dl libdlobsdwrap.so