Minor fixes

This commit is contained in:
topjohnwu 2024-02-24 22:00:09 -08:00
parent 0dbaf52566
commit 47e6dd286d
2 changed files with 43 additions and 9 deletions

View File

@ -3,6 +3,7 @@
#include <libgen.h> #include <libgen.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <pthread.h>
// Source: bionic/libc/upstream-openbsd/lib/libc/stdlib/getenv.c // Source: bionic/libc/upstream-openbsd/lib/libc/stdlib/getenv.c
static char *__findenv(const char *name, int len, int *offset) { static char *__findenv(const char *name, int len, int *offset) {
@ -162,17 +163,34 @@ int __cxa_atexit(void (*func) (void *), void * arg, void * dso_handle) {
return 0; return 0;
} }
// Dummy function symbols // Emulate pthread functions
long dummy() { return 0; } static pthread_key_t g_counter = 0;
static void **g_key_values = NULL;
#define DUMMY_SYMBOL(name) \ int pthread_key_create(pthread_key_t *key_ptr, void (*dtor)(void*)) {
__asm__(".global " #name " \n " #name " = dummy") *key_ptr = g_counter++;
g_key_values = realloc(g_key_values, g_counter * sizeof(void*));
return 0;
}
DUMMY_SYMBOL(pthread_setspecific); int pthread_key_delete(pthread_key_t key) {
DUMMY_SYMBOL(pthread_key_create); if (key < g_counter) {
DUMMY_SYMBOL(pthread_key_delete); g_key_values[key] = NULL;
DUMMY_SYMBOL(pthread_getspecific); }
return 0;
}
void *pthread_getspecific(pthread_key_t key) {
return key < g_counter ? g_key_values[key] : NULL;
}
int pthread_setspecific(pthread_key_t key, const void *value) {
if (key < g_counter) {
g_key_values[key] = (void *) value;
}
return 0;
}
// Workaround LTO bug: https://github.com/llvm/llvm-project/issues/61101 // Workaround LTO bug: https://github.com/llvm/llvm-project/issues/61101
#if defined(__i386__) #if defined(__i386__)

View File

@ -28,7 +28,6 @@ __asm__(".global " #from " \n " #from " = " #to)
SYMBOL_ALIAS(name, sys_##name) SYMBOL_ALIAS(name, sys_##name)
EXPORT_SYMBOL(_exit); EXPORT_SYMBOL(_exit);
EXPORT_SYMBOL(open);
EXPORT_SYMBOL(openat); EXPORT_SYMBOL(openat);
EXPORT_SYMBOL(close); EXPORT_SYMBOL(close);
EXPORT_SYMBOL(read); EXPORT_SYMBOL(read);
@ -203,3 +202,20 @@ int faccessat(int dirfd, const char *pathname, int mode, int flags) {
return sys_faccessat(dirfd, pathname, mode); return sys_faccessat(dirfd, pathname, mode);
} }
int open(const char *pathname, int flags, ...) {
int mode = 0;
if (((flags & O_CREAT) == O_CREAT) || ((flags & O_TMPFILE) == O_TMPFILE)) {
va_list args;
va_start(args, flags);
mode = va_arg(args, int);
va_end(args);
}
#if !defined(__LP64__)
flags |= O_LARGEFILE;
#endif
return sys_openat(AT_FDCWD, pathname, flags, mode);
}