From f77015f22f5c5421864200a6cd974ff87e75f0e0 Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Thu, 11 Jul 2019 19:46:04 +0200 Subject: [PATCH 1/3] Added 3ds-libdl. --- 3ds/libdl/PKGBUILD | 27 +++++++++++++++++++++++++++ 3ds/libdl/dlfcn.c | 36 ++++++++++++++++++++++++++++++++++++ 3ds/libdl/dlfcn.h | 25 +++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 3ds/libdl/PKGBUILD create mode 100644 3ds/libdl/dlfcn.c create mode 100644 3ds/libdl/dlfcn.h diff --git a/3ds/libdl/PKGBUILD b/3ds/libdl/PKGBUILD new file mode 100644 index 00000000..1d3b2b4d --- /dev/null +++ b/3ds/libdl/PKGBUILD @@ -0,0 +1,27 @@ +# Contributor: Teddy Astie +# Maintainer: + +pkgname=3ds-libdl +pkgver=1.0.0 +pkgrel=1 +pkgdesc='Extensible libdl library for projects that needs it.' +arch=('any') +options=(!strip) +makedepends=('devkitpro-pkgbuild-helpers') +source=('dlfcn.c' 'dlfcn.h') +sha256sums=('9c84be0ef4365a3b2ed3948426ecfbdf8116611d63d5ec42d4af8a551c20ef72' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336') +groups=('3ds-portlibs') + +build() { + source /opt/devkitpro/3dsvars.sh + + arm-none-eabi-gcc $CFLAGS -c -o dlfcn.o dlfcn.c + arm-none-eabi-ar rcu libdl.a dlfcn.o +} + +package() { + source /opt/devkitpro/3dsvars.sh + mkdir -p $pkgdir$PORTLIBS_PREFIX/lib/ $pkgdir$PORTLIBS_PREFIX/include + cp libdl.a $pkgdir$PORTLIBS_PREFIX/lib/ + cp dlfcn.h $pkgdir$PORTLIBS_PREFIX/include/ +} diff --git a/3ds/libdl/dlfcn.c b/3ds/libdl/dlfcn.c new file mode 100644 index 00000000..6d4aeae3 --- /dev/null +++ b/3ds/libdl/dlfcn.c @@ -0,0 +1,36 @@ +#include "dlfcn.h" + +#include + +static dl_open open = NULL; +static dl_error error = NULL; +static dl_sym sym = NULL; +static dl_close close = NULL; + +void dl_setfn(dl_open new_open, dl_error new_error, dl_sym new_sym, dl_close new_close) +{ + open = new_open; + error = new_error; + sym = new_sym; + close = new_close; +} + +void *dlopen(const char *module, int flag) +{ + return open ? (*open)(module, flag) : NULL; +} + +char *dlerror(void) +{ + return error ? (*error)() : ""; +} + +void *dlsym(void *handle, const char *name) +{ + return sym ? (*sym)(handle, name) : NULL; +} + +int dlclose(void *handle) +{ + return close ? (*close)(handle) : 0; +} diff --git a/3ds/libdl/dlfcn.h b/3ds/libdl/dlfcn.h new file mode 100644 index 00000000..0e36f042 --- /dev/null +++ b/3ds/libdl/dlfcn.h @@ -0,0 +1,25 @@ +#ifndef __DLFCN_H__ +#define __DLFCN_H__ + +#define RTLD_LAZY 0 +#define RTLD_NOW 1 +#define RTLD_GLOBAL 2 +#define RTLD_LOCAL 3 + +/* Defines a dlfcn.h compatible API. */ +void *dlopen(const char *module, int flag); +char *dlerror(void); +void *dlsym(void *handle, const char *name); +int dlclose(void *handle); + +/* Add a custom API to change builtin functions with user-provided ones. + * This is useful to expand dlfcn to something working when needed (e.g LuaJIT FFI). + */ +typedef void *(*dl_open)(const char *, int); +typedef char *(*dl_error)(void); +typedef void *(*dl_sym)(void *, const char *); +typedef int (*dl_close)(void *); + +void dl_setfn(dl_open open, dl_error error, dl_sym sym, dl_close close); + +#endif /* __DLFCN_H__ */ From b871d4f63121c5912a7523b9c9bdb38884a9a5c9 Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Thu, 11 Jul 2019 22:34:42 +0200 Subject: [PATCH 2/3] Added changes as requested by fincs. --- 3ds/libdl/PKGBUILD | 15 ++++++++------- 3ds/libdl/dlfcn.c | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/3ds/libdl/PKGBUILD b/3ds/libdl/PKGBUILD index 1d3b2b4d..67179216 100644 --- a/3ds/libdl/PKGBUILD +++ b/3ds/libdl/PKGBUILD @@ -9,19 +9,20 @@ arch=('any') options=(!strip) makedepends=('devkitpro-pkgbuild-helpers') source=('dlfcn.c' 'dlfcn.h') -sha256sums=('9c84be0ef4365a3b2ed3948426ecfbdf8116611d63d5ec42d4af8a551c20ef72' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336') +sha256sums=('2ae71d569bcd33d0cd23f84966aea05c2666760f051c688c72c19551c756fd74' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336') groups=('3ds-portlibs') build() { source /opt/devkitpro/3dsvars.sh - - arm-none-eabi-gcc $CFLAGS -c -o dlfcn.o dlfcn.c - arm-none-eabi-ar rcu libdl.a dlfcn.o + + ${TOOL_PREFIX}gcc ${CFLAGS} -c -o dlfcn.o dlfcn.c + ${AR} rcu libdl.a dlfcn.o } package() { source /opt/devkitpro/3dsvars.sh - mkdir -p $pkgdir$PORTLIBS_PREFIX/lib/ $pkgdir$PORTLIBS_PREFIX/include - cp libdl.a $pkgdir$PORTLIBS_PREFIX/lib/ - cp dlfcn.h $pkgdir$PORTLIBS_PREFIX/include/ + + mkdir -p ${pkgdir}${PORTLIBS_PREFIX}/lib/ ${pkgdir}${PORTLIBS_PREFIX}/include/ + cp libdl.a ${pkgdir}${PORTLIBS_PREFIX}/lib/ + cp dlfcn.h ${pkgdir}${PORTLIBS_PREFIX}/include/ } diff --git a/3ds/libdl/dlfcn.c b/3ds/libdl/dlfcn.c index 6d4aeae3..5547f26a 100644 --- a/3ds/libdl/dlfcn.c +++ b/3ds/libdl/dlfcn.c @@ -2,35 +2,35 @@ #include -static dl_open open = NULL; -static dl_error error = NULL; -static dl_sym sym = NULL; -static dl_close close = NULL; +static dl_open g_open = NULL; +static dl_error g_error = NULL; +static dl_sym g_sym = NULL; +static dl_close g_close = NULL; void dl_setfn(dl_open new_open, dl_error new_error, dl_sym new_sym, dl_close new_close) { - open = new_open; - error = new_error; - sym = new_sym; - close = new_close; + g_open = new_open; + g_error = new_error; + g_sym = new_sym; + g_close = new_close; } void *dlopen(const char *module, int flag) { - return open ? (*open)(module, flag) : NULL; + return g_open ? g_open(module, flag) : NULL; } char *dlerror(void) { - return error ? (*error)() : ""; + return g_error ? g_error() : ""; } void *dlsym(void *handle, const char *name) { - return sym ? (*sym)(handle, name) : NULL; + return g_sym ? g_sym(handle, name) : NULL; } int dlclose(void *handle) { - return close ? (*close)(handle) : 0; + return g_close ? g_close(handle) : 0; } From 12776c1251a9eddb8664bc461533de5fd342bee7 Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Thu, 11 Jul 2019 22:40:48 +0200 Subject: [PATCH 3/3] Add a forgotten change. --- 3ds/libdl/PKGBUILD | 2 +- 3ds/libdl/dlfcn.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/3ds/libdl/PKGBUILD b/3ds/libdl/PKGBUILD index 67179216..7e047f02 100644 --- a/3ds/libdl/PKGBUILD +++ b/3ds/libdl/PKGBUILD @@ -9,7 +9,7 @@ arch=('any') options=(!strip) makedepends=('devkitpro-pkgbuild-helpers') source=('dlfcn.c' 'dlfcn.h') -sha256sums=('2ae71d569bcd33d0cd23f84966aea05c2666760f051c688c72c19551c756fd74' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336') +sha256sums=('561e4031eab33c95eceae4fea7b617fc4c2f7d39606e910d077830b36ef4963d' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336') groups=('3ds-portlibs') build() { diff --git a/3ds/libdl/dlfcn.c b/3ds/libdl/dlfcn.c index 5547f26a..9aa5fa6a 100644 --- a/3ds/libdl/dlfcn.c +++ b/3ds/libdl/dlfcn.c @@ -2,10 +2,10 @@ #include -static dl_open g_open = NULL; -static dl_error g_error = NULL; -static dl_sym g_sym = NULL; -static dl_close g_close = NULL; +static dl_open g_open; +static dl_error g_error; +static dl_sym g_sym; +static dl_close g_close; void dl_setfn(dl_open new_open, dl_error new_error, dl_sym new_sym, dl_close new_close) {