2022-10-26 18:39:04 +02:00
|
|
|
#include <stddef.h>
|
2022-11-04 18:07:18 +01:00
|
|
|
#include <stdio.h>
|
2022-10-26 18:39:04 +02:00
|
|
|
|
2022-11-04 18:07:18 +01:00
|
|
|
typedef void ALooper;
|
|
|
|
|
typedef int (*Looper_callbackFunc)(int fd, int events, void* data);
|
2022-10-26 18:39:04 +02:00
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
/* helpers for creating wrappers for methods which use C++ itanium ABI */
|
2022-11-24 18:42:18 +01:00
|
|
|
|
|
|
|
|
#ifdef __aarch64__
|
2023-01-12 13:14:02 +01:00
|
|
|
#define ITANIUM_OBJRETCALL_DEC(ret_type, mangled_name, ...) \
|
|
|
|
|
void mangled_name(__VA_ARGS__); /* r8 used instead of implicit parameter, fun innit */
|
2022-11-24 18:42:18 +01:00
|
|
|
#else
|
2023-01-12 13:14:02 +01:00
|
|
|
#define ITANIUM_OBJRETCALL_DEC(ret_type, mangled_name, ...) \
|
|
|
|
|
void mangled_name(ret_type **ret, ##__VA_ARGS__) /* implicit first parameter used for return value */
|
2022-11-24 18:42:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
inline __attribute__((__always_inline__)) void * itanium_objretcall(void (*func)(), ...)
|
|
|
|
|
{
|
|
|
|
|
#ifdef __aarch64__
|
|
|
|
|
void *ret;
|
|
|
|
|
register void **addr_of_ret asm("r8"); /* arm wants to be special :( */
|
|
|
|
|
__asm__ ("" : : "" (addr_of_ret)); /* apparently __attribute__((used)) is not a thing */
|
|
|
|
|
addr_of_ret = &ret;
|
|
|
|
|
func(__builtin_va_arg_pack());
|
|
|
|
|
return ret;
|
|
|
|
|
#else
|
|
|
|
|
void *ret;
|
|
|
|
|
func(&ret, __builtin_va_arg_pack());
|
|
|
|
|
return ret;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
/* --- */
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
ITANIUM_OBJRETCALL_DEC(ALooper, _ZN7android6Looper12getForThreadEv);
|
|
|
|
|
ALooper * ALooper_forThread(void)
|
|
|
|
|
{
|
|
|
|
|
return itanium_objretcall(_ZN7android6Looper12getForThreadEv);
|
|
|
|
|
}
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
ITANIUM_OBJRETCALL_DEC(ALooper, _ZN7android6Looper7prepareEi, int opts);
|
|
|
|
|
ALooper * ALooper_prepare(int opts)
|
|
|
|
|
{
|
|
|
|
|
return itanium_objretcall(_ZN7android6Looper7prepareEi, opts);
|
|
|
|
|
}
|
2022-12-27 17:22:49 +01:00
|
|
|
|
|
|
|
|
void _ZNK7android7RefBase9incStrongEPKv(ALooper *this, void *unused);
|
|
|
|
|
void ALooper_acquire(ALooper* looper) {
|
|
|
|
|
_ZNK7android7RefBase9incStrongEPKv(looper, (void*)ALooper_acquire);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _ZNK7android7RefBase9decStrongEPKv(ALooper *this, void *unused);
|
|
|
|
|
void ALooper_release(ALooper* looper) {
|
|
|
|
|
_ZNK7android7RefBase9decStrongEPKv(looper, (void*)ALooper_acquire);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _ZN7android6Looper7pollAllEiPiS1_PPv(ALooper *this, int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
2022-10-26 18:39:04 +02:00
|
|
|
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData)
|
|
|
|
|
{
|
2022-11-04 18:07:18 +01:00
|
|
|
ALooper *looper = ALooper_forThread();
|
|
|
|
|
if(!looper) {
|
|
|
|
|
fprintf(stderr, "ALooper_pollAll: ALooper_forThread returned NULL\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _ZN7android6Looper7pollAllEiPiS1_PPv(looper, timeoutMillis, outFd, outEvents, outData);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-27 17:22:49 +01:00
|
|
|
int _ZN7android6Looper5addFdEiiiPFiiiPvES1_(ALooper *this, int fd, int ident, int events, Looper_callbackFunc callback, void* data);
|
2022-11-04 18:07:18 +01:00
|
|
|
int ALooper_addFd(ALooper* looper, int fd, int ident, int events, Looper_callbackFunc callback, void* data)
|
|
|
|
|
{
|
|
|
|
|
return _ZN7android6Looper5addFdEiiiPFiiiPvES1_(looper, fd, ident, events, callback, data);
|
2022-10-26 18:39:04 +02:00
|
|
|
}
|
2022-12-27 17:22:49 +01:00
|
|
|
void _ZN7android6Looper4wakeEv(ALooper *this);
|
|
|
|
|
void ALooper_wake(ALooper* looper) {
|
|
|
|
|
_ZN7android6Looper4wakeEv(looper);
|
|
|
|
|
}
|