diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-10-29 16:12:21 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-10-29 16:12:21 -0400 |
commit | 711f5a93cf708e9b40c2f937469934f270a02476 (patch) | |
tree | 5841b262daa6333b762f20ce0fe4798ba0fe1b3d | |
parent | 972d2eee3a3518f18e0958e6f8a1b2ffafd6d39a (diff) |
outline <dlfcn.h>
-rw-r--r-- | src/dlfcn/RTLD_GLOBAL.h | 5 | ||||
-rw-r--r-- | src/dlfcn/RTLD_LAZY.h | 5 | ||||
-rw-r--r-- | src/dlfcn/RTLD_LOCAL.h | 5 | ||||
-rw-r--r-- | src/dlfcn/RTLD_NOW.h | 5 | ||||
-rw-r--r-- | src/dlfcn/_dlfcn.h | 12 | ||||
-rw-r--r-- | src/dlfcn/dlclose.c | 13 | ||||
-rw-r--r-- | src/dlfcn/dlerror.c | 12 | ||||
-rw-r--r-- | src/dlfcn/dlopen.c | 34 | ||||
-rw-r--r-- | src/dlfcn/dlsym.c | 13 |
9 files changed, 104 insertions, 0 deletions
diff --git a/src/dlfcn/RTLD_GLOBAL.h b/src/dlfcn/RTLD_GLOBAL.h new file mode 100644 index 00000000..d9dee8b2 --- /dev/null +++ b/src/dlfcn/RTLD_GLOBAL.h @@ -0,0 +1,5 @@ +#define RTLD_GLOBAL (1<<2) + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/RTLD_LAZY.h b/src/dlfcn/RTLD_LAZY.h new file mode 100644 index 00000000..f123753b --- /dev/null +++ b/src/dlfcn/RTLD_LAZY.h @@ -0,0 +1,5 @@ +#define RTLD_LAZY (1<<0) + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/RTLD_LOCAL.h b/src/dlfcn/RTLD_LOCAL.h new file mode 100644 index 00000000..817d3adf --- /dev/null +++ b/src/dlfcn/RTLD_LOCAL.h @@ -0,0 +1,5 @@ +#define RTLD_LOCAL (1<<3) + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/RTLD_NOW.h b/src/dlfcn/RTLD_NOW.h new file mode 100644 index 00000000..91b98afb --- /dev/null +++ b/src/dlfcn/RTLD_NOW.h @@ -0,0 +1,5 @@ +#define RTLD_NOW (1<<1) + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/_dlfcn.h b/src/dlfcn/_dlfcn.h new file mode 100644 index 00000000..fd5e30d0 --- /dev/null +++ b/src/dlfcn/_dlfcn.h @@ -0,0 +1,12 @@ +#ifndef ___DLFCN_H__ +#define ___DLFCN_H__ + +#include <stddef.h> + +struct dlhandle { + void *base; + size_t size; + int fd; +}; + +#endif diff --git a/src/dlfcn/dlclose.c b/src/dlfcn/dlclose.c new file mode 100644 index 00000000..cfe43112 --- /dev/null +++ b/src/dlfcn/dlclose.c @@ -0,0 +1,13 @@ +#include <dlfcn.h> +#include "_dlfcn.h" + +int dlclose(void *handle) +{ + struct dlhandle *h = handle; + munmap(h->base, h->size); + close(h->fd); +} + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/dlerror.c b/src/dlfcn/dlerror.c new file mode 100644 index 00000000..fb1dc0e6 --- /dev/null +++ b/src/dlfcn/dlerror.c @@ -0,0 +1,12 @@ +#include <dlfcn.h> +#include "_dlfcn.h" + +char *dlerror(void) +{ + extern char *__dlerror; + return __dlerror; +} + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/dlopen.c b/src/dlfcn/dlopen.c new file mode 100644 index 00000000..f67e51ff --- /dev/null +++ b/src/dlfcn/dlopen.c @@ -0,0 +1,34 @@ +#include <dlfcn.h> +#include <fcntl.h> +#include <stdlib.h> +#include "_dlfcn.h" + +void *dlopen(const char *file, int mode) +{ + if ((mode & (RTLD_LAZY | RTLD_NOW)) == (RTLD_LAZY | RTLD_NOW)) { + return NULL; + } + + if ((mode & (RTLD_GLOBAL | RTLD_LOCAL)) == (RTLD_GLOBAL | RTLD_LOCAL)) { + return NULL; + } + + struct dlhandle *h = malloc(sizeof(*h)); + if (h == NULL) { + return NULL; + } + + h->fd = open(file, O_RDONLY | O_EXEC); + if (h->fd == -1) { + free(h); + return NULL; + } + + /* map and verify file header */ + + return h; +} + +/* +XOPEN(500) +*/ diff --git a/src/dlfcn/dlsym.c b/src/dlfcn/dlsym.c new file mode 100644 index 00000000..1648fdbc --- /dev/null +++ b/src/dlfcn/dlsym.c @@ -0,0 +1,13 @@ +#include <dlfcn.h> +#include "_dlfcn.h" + +void *dlsym(void *restrict handle, const char *restrict name) +{ + struct dlhandle *h = handle; + (void)name; + return h; +} + +/* +XOPEN(500) +*/ |