Permalink
Browse files

misguided attempt at .init and .fini support

  • Loading branch information...
1 parent dc5801f commit c490a3a1351eb84ba685fe751635b875d0a6bd37 @nickbjohnson4224 committed Dec 10, 2011
Showing with 112 additions and 36 deletions.
  1. +21 −32 TODO
  2. +4 −2 dl/dl.h
  3. +2 −0 dl/elfc.c
  4. +34 −0 dl/fini.c
  5. +34 −0 dl/init.c
  6. +3 −0 dl/interface.c
  7. +4 −0 dl/load.c
  8. +1 −0 dl/uload.c
  9. +2 −2 libc/inc/dlfcn.h
  10. +4 −0 libc/init/init.c
  11. +3 −0 libc/stdlib/exit.c
View
53 TODO
@@ -1,24 +1,6 @@
For 0.9 Alpha:
-+ merge libdriver and libc
-+ move rcall handling to natio
-+ isolate VFS code from driver code
-+ move more functions to rcall (fs_*)
-+ non-recursive fs_find
-+ hard links
-+ symlinks
-+ better event system (textual)
-+ process tracker
-+ file locking
-+ top/ps equivalent
-+ proper session/controlling tty stuff
-
+ driver interface complete
- + I/O interface
- + VFS interface
- + core interface
- + security interface
- + event interface
- kernel improvements
+ kernel robject tables
@@ -36,6 +18,7 @@ For 0.9 Alpha:
- graphics architecture improvements
- shared memory (mmap-style)
- canvas/blitter API
+ - virtual teletypes
- drivers
- PCI bus driver
@@ -48,24 +31,29 @@ For 0.9 Alpha:
- FAT32 driver
- POSIXness
- - start unistd.h as wrapper
- - implement coreutils
+ - implement coreutils (port GNU?)
+
+ + <dirent.h>
+ - <fcntl.h>
+ - <grp.h>
+ - <sys/ipc.h>
+ - <sys/msg.h>
+ - <sys/sem.h>
+ - <sys/stat.h>
+ - <sys/time.h>
+ - <sys/types.h>
+ - <sys/wait.h>
+ - <unistd.h>
+ - <utime.h>
+ ELF dynamic linking
- + address space layout
- + shared object relocation
- + shared object symbol lookup (basic)
- + dynamic symbol resolution (PLT)
- + dependency graph traversal
- + dependency loading
- + finishing touches
- + dl optimization
- shared libraries
(+) ELF dynamic linking
- shared library daemon?
- mmap-ed file loading
- - transition all binaries to dynamic
+ + transition all binaries to dynamic
+ - .init and .fini support
For 1.0 Beta:
@@ -86,20 +74,21 @@ For 1.0 Beta:
- C standard library cleanup
- malloc performance testing
- floating point environment
- - math library improvements
+ - math library improvements (port libm?)
- C standard library finalization
- - C++ standard library
+ - C++ standard library (port LLVM libc++?)
- C++ testing
- toolchain
(requires C++ standard library)
- port LLVM
- port Clang
+ + port Lua
- port Python?
- graphics improvements
- port SDL
- - games?
+ - games? (at least Tetris)
For 1.1 Beta:
View
@@ -36,8 +36,8 @@
void *_load(void *image, size_t size, int flags);
int _exec(void *image, size_t size, int flags);
-int _init(void *object);
-int _fini(void *object);
+void _init(void *object);
+void _fini(void *object);
char *_dep (void *object, uint32_t index, int loaded);
void *_sym (void *object, const char *symbol);
@@ -57,6 +57,8 @@ struct elf_cache {
const struct elf32_ehdr *image;
uint32_t vsize;
+ void (*init)(void);
+ void (*fini)(void);
const struct elf32_phdr *segtab;
const struct elf32_dyn *dynamic;
const struct elf32_sym *symtab;
View
@@ -379,6 +379,8 @@ void elf_gencache(struct elf_cache *cache, const struct elf32_ehdr *image, int l
case DT_PLTGOT: cache->pltgot = (const uint32_t*) (base + cache->dynamic[i].val); break;
case DT_HASH: cache->hash = (const uint32_t*) (base + cache->dynamic[i].val); break;
case DT_SONAME: cache->soname = (const char*) cache->dynamic[i].val; break;
+ case DT_INIT: cache->init = (void (*) (void)) (base + cache->dynamic[i].val); break;
+ case DT_FINI: cache->fini = (void (*) (void)) (base + cache->dynamic[i].val); break;
}
}
View
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <rho/layout.h>
+#include <rho/arch.h>
+#include <rho/exec.h>
+
+#include "dl.h"
+
+void _fini(void *object) {
+ struct elf_cache cache;
+
+ elf_gencache(&cache, object, 1);
+
+ if (cache.fini) {
+ cache.fini();
+ }
+}
View
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <rho/layout.h>
+#include <rho/arch.h>
+#include <rho/exec.h>
+
+#include "dl.h"
+
+void _init(void *object) {
+ struct elf_cache cache;
+
+ elf_gencache(&cache, object, 1);
+
+ if (cache.init) {
+ cache.init();
+ }
+}
View
@@ -28,6 +28,9 @@ struct dl __interface__ = {
.load = _load,
.exec = _exec,
+ .init = _init,
+ .fini = _fini,
+
.dep = _dep,
.sym = _sym,
.uload = _uload,
View
@@ -72,6 +72,10 @@ void *_load(void *image, size_t size, int flags) {
if (flags & RLTD_NOW) elfc_relocate_now(&cache);
else elfc_relocate_all(&cache);
+
+ if (cache.init) {
+ cache.init();
+ }
}
return (void*) object;
View
@@ -24,5 +24,6 @@
#include "dl.h"
void _uload(void *object) {
+ _fini(object);
sltfree_addr(object);
}
View
@@ -21,8 +21,8 @@ struct dl {
void *(*load) (void *image, size_t size, int flags);
int (*exec) (void *image, size_t size, int flags);
- int (*init) (void *object);
- int (*fini) (void *object);
+ void (*init) (void *object);
+ void (*fini) (void *object);
char *(*dep) (void *object, uint32_t index, int loaded);
void *(*sym) (void *object, const char *symbol);
View
@@ -98,6 +98,10 @@ static char *__type(rp_t source, int argc, char **argv) {
return strdup("proc");
}
+void _init(void) {
+ return;
+}
+
/****************************************************************************
* __libc_init
*
View
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <dlfcn.h>
#include <rho/natio.h>
#include <rho/proc.h>
@@ -42,6 +43,8 @@ void exit(int status) {
free(f);
}
+ dl->fini(dlopen(NULL, 0));
+
msendb(RP_CONS(getppid(), 0), PORT_CHILD);
__exit(status);
}

0 comments on commit c490a3a

Please sign in to comment.