2018-02-25 13:07:49 +01:00
|
|
|
/****************************************************************************
|
2021-09-24 19:57:15 +02:00
|
|
|
* Copyright (C) 2018-2021 Maschell
|
2018-02-25 13:07:49 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2021-09-24 19:57:15 +02:00
|
|
|
#pragma once
|
2018-02-25 13:07:49 +01:00
|
|
|
|
2018-02-25 15:18:52 +01:00
|
|
|
#include "common.h"
|
2018-02-25 13:07:49 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define WUPS_HOOK_EX(type_def, original_func) \
|
|
|
|
extern const wups_loader_hook_t wups_hooks_##original_func WUPS_SECTION("hooks"); \
|
|
|
|
const wups_loader_hook_t wups_hooks_##original_func = { \
|
|
|
|
.type = type_def, \
|
|
|
|
.target = (const void *) &(original_func)}
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
typedef enum wups_loader_hook_type_t {
|
2019-11-18 11:50:03 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_MALLOC,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_MALLOC,
|
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_NEWLIB,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_NEWLIB,
|
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_STDCPP,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_STDCPP,
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB,
|
2021-04-17 13:40:42 +02:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_SOCKETS,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_SOCKETS,
|
2019-11-17 17:43:09 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_WRAPPER, /* Calls __init */
|
|
|
|
WUPS_LOADER_HOOK_FINI_WRAPPER, /* Calls __fini */
|
2022-01-22 13:18:31 +01:00
|
|
|
|
2023-10-01 13:00:55 +02:00
|
|
|
WUPS_LOADER_HOOK_GET_CONFIG_DEPRECATED, /* Deprecated implementation */
|
|
|
|
WUPS_LOADER_HOOK_CONFIG_CLOSED_DEPRECATED, /* Deprecated implementation */
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2023-10-01 13:00:27 +02:00
|
|
|
WUPS_LOADER_HOOK_INIT_STORAGE_DEPRECATED, /* Deprecated implementation */
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_PLUGIN, /* Called when exiting the plugin loader */
|
|
|
|
WUPS_LOADER_HOOK_DEINIT_PLUGIN, /* Called when re-entering the plugin loader */
|
|
|
|
WUPS_LOADER_HOOK_APPLICATION_STARTS, /* Called when an application gets started */
|
2023-10-01 13:00:55 +02:00
|
|
|
WUPS_LOADER_HOOK_RELEASE_FOREGROUND, /* Called when a foreground is going to be released */
|
|
|
|
WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND, /* Called when a foreground is acquired */
|
2022-02-03 16:24:36 +01:00
|
|
|
WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT, /* Called when an application wants to exit */
|
|
|
|
WUPS_LOADER_HOOK_APPLICATION_ENDS, /* Called when an application ends */
|
2023-10-01 13:00:27 +02:00
|
|
|
|
|
|
|
WUPS_LOADER_HOOK_INIT_STORAGE, /* Only for internal usage */
|
2023-10-01 13:00:55 +02:00
|
|
|
WUPS_LOADER_HOOK_INIT_CONFIG, /* Only for internal usage */
|
2018-02-25 13:07:49 +01:00
|
|
|
} wups_loader_hook_type_t;
|
|
|
|
|
|
|
|
typedef struct wups_loader_hook_t {
|
2022-02-03 16:24:36 +01:00
|
|
|
wups_loader_hook_type_t type; /* Defines the type of the hook */
|
|
|
|
const void *target; /* Address of our own, new function */
|
2018-02-25 13:07:49 +01:00
|
|
|
} wups_loader_hook_t;
|
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define INITIALIZE_PLUGIN() \
|
|
|
|
void init_plugin(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_PLUGIN, init_plugin); \
|
2018-02-25 15:18:52 +01:00
|
|
|
void init_plugin()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define DEINITIALIZE_PLUGIN() \
|
|
|
|
void deinit_plugin(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_DEINIT_PLUGIN, deinit_plugin); \
|
2018-02-25 13:07:49 +01:00
|
|
|
void deinit_plugin()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define ON_APPLICATION_START() \
|
|
|
|
void on_app_starting(); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_STARTS, on_app_starting); \
|
2021-03-16 17:31:20 +01:00
|
|
|
void on_app_starting()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define ON_RELEASE_FOREGROUND() \
|
|
|
|
void on_release_foreground(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_RELEASE_FOREGROUND, on_release_foreground); \
|
2019-11-17 17:43:09 +01:00
|
|
|
void on_release_foreground(void)
|
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define ON_ACQUIRED_FOREGROUND() \
|
|
|
|
void on_acquired_foreground(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND, on_acquired_foreground); \
|
2019-11-17 17:43:09 +01:00
|
|
|
void on_acquired_foreground(void)
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define ON_APPLICATION_REQUESTS_EXIT() \
|
|
|
|
void on_app_requests_exit(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT, on_app_requests_exit); \
|
2021-03-16 17:31:20 +01:00
|
|
|
void on_app_requests_exit(void)
|
2019-11-17 17:43:09 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define ON_APPLICATION_ENDS() \
|
|
|
|
void on_app_ending(void); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_ENDS, on_app_ending); \
|
2018-02-25 13:07:49 +01:00
|
|
|
void on_app_ending(void)
|
|
|
|
|
2023-10-01 13:00:55 +02:00
|
|
|
#define WUPS_GET_CONFIG(x) \
|
|
|
|
static_assert(false, "Please use \"WUPSConfigAPI_Init\" inside \"INITIALIZE_PLUGIN\" to provide a callback instead");
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2023-10-01 13:00:55 +02:00
|
|
|
#define WUPS_CONFIG_CLOSED() \
|
|
|
|
static_assert(false, "Please use \"WUPSConfigAPI_Init\" inside \"INITIALIZE_PLUGIN\" to provide a callback instead");
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define WUPS_USE_STORAGE(x) \
|
|
|
|
WUPS_META(storage_id, x); \
|
|
|
|
void init_storage(wups_loader_init_storage_args_t); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_STORAGE, init_storage); \
|
|
|
|
void init_storage(wups_loader_init_storage_args_t args) { \
|
2023-12-14 17:20:38 +01:00
|
|
|
WUPSStorageAPI_InitInternal(args); \
|
2021-09-24 19:57:15 +02:00
|
|
|
}
|
2021-04-06 20:33:19 +02:00
|
|
|
|
2023-10-01 13:00:55 +02:00
|
|
|
|
2021-04-06 20:33:19 +02:00
|
|
|
#ifdef __cplusplus
|
2021-09-24 19:57:15 +02:00
|
|
|
#define __EXTERN_C_MACRO extern "C"
|
2021-04-06 20:33:19 +02:00
|
|
|
#else
|
|
|
|
#define __EXTERN_C_MACRO
|
|
|
|
#endif
|
|
|
|
|
2023-10-01 13:00:55 +02:00
|
|
|
#define WUPS_INIT_CONFIG_FUNCTIONS() \
|
|
|
|
__EXTERN_C_MACRO WUPSConfigAPIStatus WUPSConfigAPI_InitLibrary_Internal(wups_loader_init_config_args_t args); \
|
|
|
|
void wups_init_config_functions(wups_loader_init_config_args_t); \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_CONFIG, wups_init_config_functions); \
|
|
|
|
void wups_init_config_functions(wups_loader_init_config_args_t args) { \
|
|
|
|
WUPSConfigAPI_InitLibrary_Internal(args); \
|
|
|
|
}
|
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define WUPS_USE_WUT_MALLOC() \
|
|
|
|
__EXTERN_C_MACRO void __init_wut_malloc(); \
|
|
|
|
void on_init_wut_malloc() { \
|
|
|
|
__init_wut_malloc(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_MALLOC, on_init_wut_malloc); \
|
|
|
|
__EXTERN_C_MACRO void __fini_wut_malloc(); \
|
|
|
|
void on_fini_wut_malloc() { \
|
|
|
|
__fini_wut_malloc(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_MALLOC, on_fini_wut_malloc)
|
|
|
|
|
|
|
|
#define WUPS_USE_WUT_DEVOPTAB() \
|
|
|
|
__EXTERN_C_MACRO void __init_wut_devoptab(); \
|
|
|
|
void on_init_wut_devoptab() { \
|
|
|
|
__init_wut_devoptab(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB, on_init_wut_devoptab); \
|
|
|
|
__EXTERN_C_MACRO void __fini_wut_devoptab(); \
|
|
|
|
void on_fini_wut_devoptab() { \
|
|
|
|
__fini_wut_devoptab(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB, on_fini_wut_devoptab)
|
|
|
|
|
|
|
|
#define WUPS_USE_WUT_NEWLIB() \
|
|
|
|
__EXTERN_C_MACRO void __init_wut_newlib(); \
|
|
|
|
void on_init_wut_newlib() { \
|
|
|
|
__init_wut_newlib(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_NEWLIB, on_init_wut_newlib); \
|
|
|
|
__EXTERN_C_MACRO void __fini_wut_newlib(); \
|
|
|
|
void on_fini_wut_newlib() { \
|
|
|
|
__fini_wut_newlib(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_NEWLIB, on_fini_wut_newlib)
|
|
|
|
|
|
|
|
#define WUPS_USE_WUT_STDCPP() \
|
|
|
|
__EXTERN_C_MACRO void __init_wut_stdcpp(); \
|
|
|
|
void on_init_wut_stdcpp() { \
|
|
|
|
__init_wut_stdcpp(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_STDCPP, on_init_wut_stdcpp); \
|
|
|
|
__EXTERN_C_MACRO void __fini_wut_stdcpp(); \
|
|
|
|
void on_fini_wut_stdcpp() { \
|
|
|
|
__fini_wut_stdcpp(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_STDCPP, on_fini_wut_stdcpp)
|
|
|
|
|
2023-07-19 14:55:33 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" uint32_t __attribute__((weak)) wut_get_thread_specific(int id);
|
|
|
|
extern "C" const char wups_meta_info_linking_order[];
|
2023-07-19 15:17:10 +02:00
|
|
|
extern "C" void OSFatal(const char *msg);
|
2023-07-19 14:55:33 +02:00
|
|
|
#else
|
|
|
|
extern uint32_t __attribute__((weak)) wut_get_thread_specific(int id);
|
|
|
|
extern const char wups_meta_info_linking_order[];
|
2023-07-19 15:17:10 +02:00
|
|
|
extern void OSFatal(const char *msg);
|
2023-07-19 14:55:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WUPS___INIT_WRAPPER() \
|
|
|
|
__EXTERN_C_MACRO void __init(); \
|
|
|
|
void __init_wrapper() { \
|
|
|
|
if (wut_get_thread_specific(0x13371337) != 0x42424242) { \
|
|
|
|
OSFatal(wups_meta_info_linking_order); \
|
|
|
|
} \
|
|
|
|
__init(); \
|
|
|
|
} \
|
2022-02-03 16:24:36 +01:00
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WRAPPER, __init_wrapper);
|
2022-01-22 13:18:31 +01:00
|
|
|
|
2022-02-03 16:24:36 +01:00
|
|
|
#define WUPS___FINI_WRAPPER() \
|
2022-01-22 13:18:31 +01:00
|
|
|
__EXTERN_C_MACRO void __fini(); \
|
2022-02-03 16:24:36 +01:00
|
|
|
void __fini_wrapper() { \
|
|
|
|
__fini(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WRAPPER, __fini_wrapper);
|
|
|
|
|
|
|
|
#define WUPS_USE_WUT_SOCKETS() \
|
|
|
|
__EXTERN_C_MACRO void __attribute__((weak)) __init_wut_socket(); \
|
|
|
|
void on_init_wut_sockets() { \
|
|
|
|
if (&__init_wut_socket) __init_wut_socket(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_SOCKETS, on_init_wut_sockets); \
|
|
|
|
__EXTERN_C_MACRO void __attribute__((weak)) __fini_wut_socket(); \
|
|
|
|
void on_fini_wut_sockets() { \
|
|
|
|
if (&__fini_wut_socket) __fini_wut_socket(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_SOCKETS, on_fini_wut_sockets)
|
2021-09-24 19:57:15 +02:00
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|