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
|
|
|
|
2022-11-24 18:42:18 +01:00
|
|
|
/* macros for creating wrappers for methods which use C++ itanium ABI */
|
|
|
|
|
|
|
|
|
|
#ifdef __aarch64__
|
|
|
|
|
|
|
|
|
|
#define ITANIUM_OBJ_RET_WRAPPER_DEC(ret_type, wrapper_name, mangled_name, ...) \
|
|
|
|
|
void mangled_name(__VA_ARGS__); /* r8 used instead of implicit parameter, fun innit */\
|
|
|
|
|
ret_type * wrapper_name(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define ITANIUM_OBJ_RET_WRAPPER_BODY(ret_type, wrapper_name, mangled_name, ...) \
|
|
|
|
|
{ \
|
|
|
|
|
ret_type *ret; \
|
|
|
|
|
register ret_type **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; \
|
|
|
|
|
mangled_name(__VA_ARGS__); \
|
|
|
|
|
return ret; \
|
2022-10-26 18:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-24 18:42:18 +01:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define ITANIUM_OBJ_RET_WRAPPER_DEC(ret_type, wrapper_name, mangled_name, ...) \
|
|
|
|
|
void mangled_name(ret_type **ret, ##__VA_ARGS__); /* implicit first parameter used for return value */\
|
|
|
|
|
ret_type * wrapper_name(__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define ITANIUM_OBJ_RET_WRAPPER_BODY(ret_type, wrapper_name, mangled_name, ...) \
|
|
|
|
|
{ \
|
|
|
|
|
ret_type *ret; \
|
|
|
|
|
mangled_name(&ret, ##__VA_ARGS__); \
|
|
|
|
|
return ret; \
|
2022-10-26 18:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-24 18:42:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define ITANIUM_OBJ_RET_WRAPPER_NOARGS(ret_type, wrapper_name, mangled_name) \
|
|
|
|
|
ITANIUM_OBJ_RET_WRAPPER_DEC(ret_type, wrapper_name, mangled_name) \
|
|
|
|
|
ITANIUM_OBJ_RET_WRAPPER_BODY(ret_type, wrapper_name, mangled_name)
|
|
|
|
|
|
|
|
|
|
// ALooper * ALooper_forThread()
|
|
|
|
|
ITANIUM_OBJ_RET_WRAPPER_NOARGS(ALooper, ALooper_forThread, _ZN7android6Looper12getForThreadEv)
|
|
|
|
|
|
|
|
|
|
// ALooper * ALooper_prepare(int opts)
|
|
|
|
|
ITANIUM_OBJ_RET_WRAPPER_DEC(ALooper, ALooper_prepare, _ZN7android6Looper7prepareEi, int opts)
|
|
|
|
|
ITANIUM_OBJ_RET_WRAPPER_BODY(ALooper, ALooper_prepare, _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);
|
|
|
|
|
}
|