Compare commits

...

5 Commits

Author SHA1 Message Date
Bananymous 987cc3c237 3000th COMMIT: ports: Add halflife port 2025-07-31 22:47:34 +03:00
Bananymous 935f69e011 ports: Add freetype port 2025-07-31 22:47:29 +03:00
Bananymous 9f0c2fb6e2 ports: Apply only patches ending in .patch 2025-07-31 22:47:29 +03:00
Bananymous 9b18bda9c8 Kernel: Make epoll always check for HUP and ERR 2025-07-31 22:47:29 +03:00
Bananymous 7831c74e8c DynamicLoader: Add support for LD_LIBRARY_PATH
Also fix a bug with dlopen with TLS
2025-07-31 22:47:29 +03:00
12 changed files with 521 additions and 11 deletions

View File

@ -50,7 +50,7 @@ namespace Kernel
auto ready_it = m_ready_events.find(inode); auto ready_it = m_ready_events.find(inode);
if (ready_it == m_ready_events.end()) if (ready_it == m_ready_events.end())
ready_it = MUST(m_ready_events.insert(inode, 0)); ready_it = MUST(m_ready_events.insert(inode, 0));
ready_it->value |= event.events; ready_it->value |= event.events | EPOLLHUP | EPOLLERR;
m_thread_blocker.unblock(); m_thread_blocker.unblock();
return {}; return {};
@ -68,7 +68,7 @@ namespace Kernel
auto ready_it = m_ready_events.find(inode); auto ready_it = m_ready_events.find(inode);
if (ready_it == m_ready_events.end()) if (ready_it == m_ready_events.end())
ready_it = MUST(m_ready_events.insert(inode, 0)); ready_it = MUST(m_ready_events.insert(inode, 0));
ready_it->value |= event.events; ready_it->value |= event.events | EPOLLHUP | EPOLLERR;
m_thread_blocker.unblock(); m_thread_blocker.unblock();
return {}; return {};

15
ports/freetype/build.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash ../install.sh
NAME='freetype'
VERSION='2.13.3'
DOWNLOAD_URL="https://download.savannah.gnu.org/releases/freetype/freetype-$VERSION.tar.gz#5c3a8e78f7b24c20b25b54ee575d6daa40007a5f4eea2845861c3409b3021747"
CONFIG_SUB=('builds/unix/config.sub')
CONFIGURE_OPTIONS=(
'lt_cv_deplibs_check_method=pass_all'
)
post_install() {
# remove libtool file
rm -f $BANAN_SYSROOT/usr/lib/libfreetype.la
}

View File

@ -0,0 +1,31 @@
diff -ruN freetype-2.13.3/builds/unix/configure freetype-2.13.3-banan_os/builds/unix/configure
--- freetype-2.13.3/builds/unix/configure 2024-08-12 14:00:49.000000000 +0300
+++ freetype-2.13.3-banan_os/builds/unix/configure 2025-07-31 17:40:12.168493444 +0300
@@ -5474,6 +5474,10 @@
lt_cv_deplibs_check_method=pass_all
;;
+banan_os*)
+ lt_cv_deplibs_check_method=pass_all
+ ;;
+
beos*)
lt_cv_deplibs_check_method=pass_all
;;
@@ -11261,6 +11265,16 @@
esac
;;
+banan_os*)
+ version_type=linux # correct to gnu/linux during the next big refactor
+ need_lib_prefix=no
+ need_version=no
+ library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext'
+ soname_spec='$libname$release$shared_ext$major'
+ dynamic_linker="$host_os DynamicLoader.so"
+ shlibpath_var=LD_LIBRARY_PATH
+ ;;
+
beos*)
library_names_spec='$libname$shared_ext'
dynamic_linker="$host_os ld.so"

18
ports/halflife/build.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash ../install.sh
NAME='halflife'
VERSION='git'
DOWNLOAD_URL="https://github.com/FWGS/hlsdk-portable.git#343b09bc4de15ecf310ab97e759bfdef6e883bd8"
DEPENDENCIES=('xash3d-fwgs')
configure() {
./waf configure -T release || exit 1
}
build() {
./waf build || exit 1
}
install() {
./waf install --destdir=$BANAN_SYSROOT/home/user/halflife || exit 1
}

View File

@ -0,0 +1,55 @@
From eb4fc64fb39e6c00350ac87a29dd8fc690b3be9f Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Thu, 31 Jul 2025 22:39:13 +0300
Subject: [PATCH] Add support for banan-os
---
public/build.h | 3 +++
scripts/waifulib/library_naming.py | 3 +++
2 files changed, 6 insertions(+)
diff --git a/public/build.h b/public/build.h
index 3fdfeded..2752f8bd 100644
--- a/public/build.h
+++ b/public/build.h
@@ -82,6 +82,7 @@ Then you can use another oneliner to query all variables:
#undef XASH_RISCV_SOFTFP
#undef XASH_SERENITY
#undef XASH_SUNOS
+#undef XASH_BANAN_OS
#undef XASH_TERMUX
#undef XASH_WIN32
#undef XASH_X86
@@ -135,6 +136,8 @@ Then you can use another oneliner to query all variables:
#define XASH_WASI 1
#elif defined __sun__
#define XASH_SUNOS 1
+ #elif defined __banan_os__
+ #define XASH_BANAN_OS 1
#elif defined __EMSCRIPTEN__
#define XASH_EMSCRIPTEN 1
#else
diff --git a/scripts/waifulib/library_naming.py b/scripts/waifulib/library_naming.py
index da39c90f..a0b65b59 100644
--- a/scripts/waifulib/library_naming.py
+++ b/scripts/waifulib/library_naming.py
@@ -64,6 +64,7 @@ DEFINES = [
'XASH_WASI',
'XASH_WASM',
'XASH_SUNOS',
+'XASH_BANAN_OS',
]
def configure(conf):
@@ -109,6 +110,8 @@ def configure(conf):
buildos = "wasi"
elif conf.env.XASH_SUNOS:
buildos = "sunos"
+ elif conf.env.XASH_BANAN_OS:
+ buildos = "banan-os"
else:
conf.fatal("Place your operating system name in build.h and library_naming.py!\n"
"If this is a mistake, try to fix conditions above and report a bug")
--
2.50.1

View File

@ -155,7 +155,7 @@ if [ "$VERSION" = "git" ]; then
pushd "$build_dir" >/dev/null pushd "$build_dir" >/dev/null
git checkout "$COMMIT" || exit 1 git checkout "$COMMIT" || exit 1
if [ -d ../patches ]; then if [ -d ../patches ]; then
for patch in ../patches/*; do for patch in ../patches/*.patch ; do
git apply "$patch" || exit 1 git apply "$patch" || exit 1
done done
fi fi
@ -194,7 +194,7 @@ else
mv "$TAR_CONTENT" "$build_dir" || exit 1 mv "$TAR_CONTENT" "$build_dir" || exit 1
if [ -d patches ]; then if [ -d patches ]; then
for patch in ./patches/*; do for patch in ./patches/*.patch ; do
patch -ruN -p1 -d "$build_dir" < "$patch" || exit 1 patch -ruN -p1 -d "$build_dir" < "$patch" || exit 1
done done
fi fi

39
ports/xash3d-fwgs/build.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash ../install.sh
NAME='xash3d-fwgs'
VERSION='git'
DOWNLOAD_URL="https://github.com/FWGS/xash3d-fwgs.git#da1b9ad80d76156a5cbd54d3ce87edb32634ea87"
DEPENDENCIES=('SDL2' 'freetype')
configure() {
git submodule update --init --recursive || exit 1
pushd 3rdparty/mainui || exit 1
for patch in ../../../patches/mainui/*; do
git apply $patch
done
popd
pushd 3rdparty/vorbis/vorbis-src || exit 1
for patch in ../../../../patches/vorbis/*; do
git apply $patch
done
popd
./waf configure -T release --disable-gl || exit 1
}
build() {
./waf build || exit 1
}
install() {
./waf install --destdir=$BANAN_SYSROOT/home/user/halflife || exit 1
cat > $BANAN_SYSROOT/home/user/halflife/start.sh << EOF
#!/bin/Shell
export LD_LIBRARY_PATH=/home/user/halflife
./xash3d -console
EOF
chmod +x $BANAN_SYSROOT/home/user/halflife/start.sh
}

View File

@ -0,0 +1,215 @@
From 2b3a0198640c23a7f8f8247ed1edae309c11e15f Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Thu, 31 Jul 2025 22:15:43 +0300
Subject: [PATCH 1/2] add support for banan-os
---
engine/common/net_http.c | 4 +++-
engine/common/net_ws.c | 17 +++++++++++++++++
engine/common/whereami.c | 16 ++++++++++++++++
engine/platform/posix/lib_posix.c | 2 ++
public/build.c | 2 ++
public/build.h | 3 +++
public/buildenums.h | 3 +++
7 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/engine/common/net_http.c b/engine/common/net_http.c
index ff6fd41b..ebb5bbad 100644
--- a/engine/common/net_http.c
+++ b/engine/common/net_http.c
@@ -261,14 +261,16 @@ static int HTTP_FileCreateSocket( httpfile_t *file )
return 0;
}
+#if !XASH_BANAN_OS
if( ioctlsocket( file->socket, FIONBIO, (void *)&mode ) < 0 )
{
Con_Printf( S_ERROR "%s: ioctl() returned %s\n", __func__, NET_ErrorString());
HTTP_FreeFile( file, true );
return 0;
}
+#endif
-#if XASH_LINUX
+#if XASH_LINUX || XASH_BANAN_OS
res = fcntl( file->socket, F_GETFL, 0 );
diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c
index 7ee4cba0..e93a2410 100644
--- a/engine/common/net_ws.c
+++ b/engine/common/net_ws.c
@@ -1364,7 +1364,12 @@ static qboolean NET_QueuePacket( netsrc_t sock, netadr_t *from, byte *data, size
byte buf[NET_MAX_FRAGMENT];
int ret, protocol;
int net_socket;
+#ifdef XASH_BANAN_OS
+ socklen_t addr_len;
+#else
WSAsize_t addr_len;
+#endif
+
struct sockaddr_storage addr = { 0 };
*length = 0;
@@ -1617,7 +1622,11 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
if( family == AF_INET6 )
pfamily = PF_INET6;
+#ifdef SOCK_NONBLOCK
+ if( NET_IsSocketError(( net_socket = socket( pfamily, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP ))))
+#else
if( NET_IsSocketError(( net_socket = socket( pfamily, SOCK_DGRAM, IPPROTO_UDP ))))
+#endif
{
err = WSAGetLastError();
if( err != WSAEAFNOSUPPORT )
@@ -1625,6 +1634,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
return INVALID_SOCKET;
}
+#ifndef SOCK_NONBLOCK
if( NET_IsSocketError( ioctlsocket( net_socket, FIONBIO, (void*)&_true )))
{
struct timeval timeout;
@@ -1634,6 +1644,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
timeout.tv_sec = timeout.tv_usec = 0;
setsockopt( net_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
}
+#endif
// make it broadcast capable
if( NET_IsSocketError( setsockopt( net_socket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof( _true ))))
@@ -1686,6 +1697,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
optval = 0x10; // IPTOS_LOWDELAY
Con_Printf( "Enabling LOWDELAY TOS option\n" );
+#ifdef IP_TOS
if( NET_IsSocketError( setsockopt( net_socket, IPPROTO_IP, IP_TOS, (const char *)&optval, sizeof( optval ))))
{
err = WSAGetLastError();
@@ -1694,6 +1706,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
closesocket( net_socket );
return INVALID_SOCKET;
}
+#endif
}
if( Sys_CheckParm( "-loopback" ))
@@ -1801,7 +1814,11 @@ static void NET_DetermineLocalAddress( void )
char hostname[512];
char buff[512];
struct sockaddr_storage address;
+#ifdef XASH_BANAN_OS
+ socklen_t namelen;
+#else
WSAsize_t namelen;
+#endif
const char *net_addr_string;
memset( &net_local, 0, sizeof( netadr_t ));
diff --git a/engine/common/whereami.c b/engine/common/whereami.c
index 31726774..5b7ff504 100644
--- a/engine/common/whereami.c
+++ b/engine/common/whereami.c
@@ -851,6 +851,22 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
return -1;
}
+#elif defined(__banan_os__)
+
+/* Not possible on this platform */
+
+WAI_FUNCSPEC
+int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
+{
+ return -1;
+}
+
+WAI_FUNCSPEC
+int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
+{
+ return -1;
+}
+
#else
#error unsupported platform
diff --git a/engine/platform/posix/lib_posix.c b/engine/platform/posix/lib_posix.c
index 23d1c3b1..a5a84fe1 100644
--- a/engine/platform/posix/lib_posix.c
+++ b/engine/platform/posix/lib_posix.c
@@ -208,6 +208,7 @@ const char *COM_NameForFunction( void *hInstance, void *function )
return Loader_GetFuncName_int(wm, function);
else
#endif
+#ifndef XASH_BANAN_OS
// NOTE: dladdr() is a glibc extension
{
Dl_info info = {0};
@@ -215,6 +216,7 @@ const char *COM_NameForFunction( void *hInstance, void *function )
if( ret && info.dli_sname )
return COM_GetPlatformNeutralName( info.dli_sname );
}
+#endif
#ifdef XASH_ALLOW_SAVERESTORE_OFFSETS
return COM_OffsetNameForFunction( function );
#else
diff --git a/public/build.c b/public/build.c
index 6c85bbaf..460b4040 100644
--- a/public/build.c
+++ b/public/build.c
@@ -151,6 +151,8 @@ const char *Q_PlatformStringByID( const int platform )
return "wasi";
case PLATFORM_SUNOS:
return "sunos";
+ case PLATFORM_BANAN_OS:
+ return "banan-os";
}
assert( 0 );
diff --git a/public/build.h b/public/build.h
index 3fdfeded..2752f8bd 100644
--- a/public/build.h
+++ b/public/build.h
@@ -82,6 +82,7 @@ Then you can use another oneliner to query all variables:
#undef XASH_RISCV_SOFTFP
#undef XASH_SERENITY
#undef XASH_SUNOS
+#undef XASH_BANAN_OS
#undef XASH_TERMUX
#undef XASH_WIN32
#undef XASH_X86
@@ -135,6 +136,8 @@ Then you can use another oneliner to query all variables:
#define XASH_WASI 1
#elif defined __sun__
#define XASH_SUNOS 1
+ #elif defined __banan_os__
+ #define XASH_BANAN_OS 1
#elif defined __EMSCRIPTEN__
#define XASH_EMSCRIPTEN 1
#else
diff --git a/public/buildenums.h b/public/buildenums.h
index 4dc327d3..57585f73 100644
--- a/public/buildenums.h
+++ b/public/buildenums.h
@@ -43,6 +43,7 @@ GNU General Public License for more details.
#define PLATFORM_PSVITA 14
#define PLATFORM_WASI 15
#define PLATFORM_SUNOS 16
+#define PLATFORM_BANAN_OS 17
#if XASH_WIN32
#define XASH_PLATFORM PLATFORM_WIN32
@@ -76,6 +77,8 @@ GNU General Public License for more details.
#define XASH_PLATFORM PLATFORM_WASI
#elif XASH_SUNOS
#define XASH_PLATFORM PLATFORM_SUNOS
+#elif XASH_BANAN_OS
+ #define XASH_PLATFORM PLATFORM_BANAN_OS
#else
#error
#endif
--
2.50.1

View File

@ -0,0 +1,25 @@
From b8c6ea53b4a8119f299fb6b5e4684c30795037a7 Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Thu, 31 Jul 2025 22:36:28 +0300
Subject: [PATCH] Don't export have libbacktrace
This doesnt work :)
---
3rdparty/libbacktrace/wscript | 1 -
1 file changed, 1 deletion(-)
diff --git a/3rdparty/libbacktrace/wscript b/3rdparty/libbacktrace/wscript
index 2e076a56..98aca8d5 100644
--- a/3rdparty/libbacktrace/wscript
+++ b/3rdparty/libbacktrace/wscript
@@ -180,7 +180,6 @@ def build(bld):
features = 'frandomseed' if bld.env.HAVE_FRANDOM_SEED else '',
use = 'EXTRAFLAGS lzma z zstd',
includes = '. libbacktrace/',
- export_defines = 'HAVE_LIBBACKTRACE=1',
export_includes = 'libbacktrace/'
)
--
2.50.1

View File

@ -0,0 +1,55 @@
From 72d30e589450d1a928924f93adfaadff7618ba59 Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Thu, 31 Jul 2025 22:16:51 +0300
Subject: [PATCH] add support for banan-os
---
sdk_includes/public/build.h | 3 +++
sdk_includes/public/buildenums.h | 3 +++
2 files changed, 6 insertions(+)
diff --git a/sdk_includes/public/build.h b/sdk_includes/public/build.h
index 24fd9d5..52b6088 100644
--- a/sdk_includes/public/build.h
+++ b/sdk_includes/public/build.h
@@ -82,6 +82,7 @@ Then you can use another oneliner to query all variables:
#undef XASH_RISCV_SOFTFP
#undef XASH_SERENITY
#undef XASH_SUNOS
+#undef XASH_BANAN_OS
#undef XASH_WIN32
#undef XASH_X86
#undef XASH_NSWITCH
@@ -133,6 +134,8 @@ Then you can use another oneliner to query all variables:
#define XASH_WASI 1
#elif defined __sun__
#define XASH_SUNOS 1
+ #elif defined __banan_os__
+ #define XASH_BANAN_OS 1
#else
#error
#endif
diff --git a/sdk_includes/public/buildenums.h b/sdk_includes/public/buildenums.h
index 4dc327d..57585f7 100644
--- a/sdk_includes/public/buildenums.h
+++ b/sdk_includes/public/buildenums.h
@@ -43,6 +43,7 @@ GNU General Public License for more details.
#define PLATFORM_PSVITA 14
#define PLATFORM_WASI 15
#define PLATFORM_SUNOS 16
+#define PLATFORM_BANAN_OS 17
#if XASH_WIN32
#define XASH_PLATFORM PLATFORM_WIN32
@@ -76,6 +77,8 @@ GNU General Public License for more details.
#define XASH_PLATFORM PLATFORM_WASI
#elif XASH_SUNOS
#define XASH_PLATFORM PLATFORM_SUNOS
+#elif XASH_BANAN_OS
+ #define XASH_PLATFORM PLATFORM_BANAN_OS
#else
#error
#endif
--
2.50.1

View File

@ -0,0 +1,26 @@
From 1e1fb9caff45f0cb05e89bfe452a7ff2abb558ff Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Thu, 31 Jul 2025 22:17:48 +0300
Subject: [PATCH] include alloca on banan-os
This detection does not work :(
---
lib/os.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/os.h b/lib/os.h
index 9ded7358..66b56704 100644
--- a/lib/os.h
+++ b/lib/os.h
@@ -62,7 +62,7 @@ void *_alloca(size_t size);
#endif /* _V_IFDEFJAIL_H_ */
-#ifdef HAVE_ALLOCA_H
+#if defined(HAVE_ALLOCA_H) || defined(__banan_os__)
# include <alloca.h>
#endif
--
2.50.1

View File

@ -195,6 +195,8 @@ struct LoadedElf
static LoadedElf s_loaded_files[128]; static LoadedElf s_loaded_files[128];
static size_t s_loaded_file_count = 0; static size_t s_loaded_file_count = 0;
static const char* s_ld_library_path = nullptr;
constexpr uintptr_t SYM_NOT_FOUND = -1; constexpr uintptr_t SYM_NOT_FOUND = -1;
static uint32_t elf_hash(const char* name) static uint32_t elf_hash(const char* name)
@ -717,16 +719,15 @@ uintptr_t resolve_symbol(const LoadedElf& elf, uintptr_t plt_entry)
static LoadedElf& load_elf(const char* path, int fd); static LoadedElf& load_elf(const char* path, int fd);
static bool find_library(const char* library_name, char out[PATH_MAX]) static bool check_library(const char* library_dir, const char* library_name, char out[PATH_MAX])
{ {
const char* library_dir = "/usr/lib/";
char path_buffer[PATH_MAX]; char path_buffer[PATH_MAX];
char* path_ptr = path_buffer; char* path_ptr = path_buffer;
if (library_name[0] != '/') if (library_name[0] != '/')
for (size_t i = 0; library_dir[i]; i++) for (size_t i = 0; library_dir[i]; i++)
*path_ptr++ = library_dir[i]; *path_ptr++ = library_dir[i];
*path_ptr++ = '/';
for (size_t i = 0; library_name[i]; i++) for (size_t i = 0; library_name[i]; i++)
*path_ptr++ = library_name[i]; *path_ptr++ = library_name[i];
*path_ptr = '\0'; *path_ptr = '\0';
@ -734,6 +735,15 @@ static bool find_library(const char* library_name, char out[PATH_MAX])
return syscall(SYS_REALPATH, path_buffer, out) >= 0; return syscall(SYS_REALPATH, path_buffer, out) >= 0;
} }
static bool find_library(const char* library_name, char out[PATH_MAX])
{
if (s_ld_library_path && check_library(s_ld_library_path, library_name, out))
return true;
if (check_library("/usr/lib", library_name, out))
return true;
return false;
}
static void handle_dynamic(LoadedElf& elf) static void handle_dynamic(LoadedElf& elf)
{ {
uintptr_t pltgot = 0; uintptr_t pltgot = 0;
@ -798,7 +808,10 @@ static void handle_dynamic(LoadedElf& elf)
char path_buffer[PATH_MAX]; char path_buffer[PATH_MAX];
if (!find_library(library_name, path_buffer)) if (!find_library(library_name, path_buffer))
print_error_and_exit("could not open shared object", 0); {
print(STDERR_FILENO, "could not open shared object: ");
print_error_and_exit(library_name, 0);
}
const auto& loaded_elf = load_elf(path_buffer, -1); const auto& loaded_elf = load_elf(path_buffer, -1);
dynamic.d_un.d_ptr = reinterpret_cast<uintptr_t>(&loaded_elf); dynamic.d_un.d_ptr = reinterpret_cast<uintptr_t>(&loaded_elf);
@ -1346,16 +1359,21 @@ void* __dlopen(const char* file, int mode)
return nullptr; return nullptr;
} }
const size_t old_loaded_count = s_loaded_file_count;
init_random(); init_random();
auto& elf = load_elf(path_buffer, -1); auto& elf = load_elf(path_buffer, -1);
fini_random(); fini_random();
if (!elf.is_relocating && !elf.is_calling_init) if (!elf.is_relocating && !elf.is_calling_init)
{ {
if (elf.tls_header.p_type == PT_TLS) for (size_t i = old_loaded_count + 1; i < s_loaded_file_count; i++)
{ {
s_dlerror_string = "TODO: __dlopen with TLS"; if (s_loaded_files[i].tls_header.p_type == PT_TLS)
return nullptr; {
s_dlerror_string = "TODO: __dlopen with TLS";
return nullptr;
}
} }
relocate_elf(elf, lazy); relocate_elf(elf, lazy);
@ -1399,10 +1417,23 @@ static LibELF::AuxiliaryVector* find_auxv(char** envp)
return reinterpret_cast<LibELF::AuxiliaryVector*>(null_env + 1); return reinterpret_cast<LibELF::AuxiliaryVector*>(null_env + 1);
} }
static bool starts_with(const char* string, const char* comp)
{
size_t i = 0;
for (; string[i] && comp[i]; i++)
if (string[i] != comp[i])
return false;
return comp[i] == '\0';
}
extern "C" extern "C"
__attribute__((used)) __attribute__((used))
uintptr_t _entry(int argc, char* argv[], char* envp[]) uintptr_t _entry(int argc, char* argv[], char* envp[])
{ {
for (size_t i = 0; envp[i]; i++)
if (starts_with(envp[i], "LD_LIBRARY_PATH="))
s_ld_library_path = envp[i] + 16;
int execfd = -1; int execfd = -1;
if (auto* auxv = find_auxv(envp)) if (auto* auxv = find_auxv(envp))
for (auto* aux = auxv; aux->a_type != LibELF::AT_NULL; aux++) for (auto* aux = auxv; aux->a_type != LibELF::AT_NULL; aux++)