mirror of
https://github.com/wiiu-env/WiiUPluginSystem.git
synced 2024-11-16 15:49:23 +01:00
Replace the "void *" of the fs and overlay access with proper function pointers
This commit is contained in:
parent
2f074ac71f
commit
3f1d27f7b2
@ -34,27 +34,25 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed)
|
|||||||
void * func_ptr = hook_data->func_pointer;
|
void * func_ptr = hook_data->func_pointer;
|
||||||
//TODO: Switch cases depending on arguments etc.
|
//TODO: Switch cases depending on arguments etc.
|
||||||
// Adding arguments!
|
// Adding arguments!
|
||||||
|
|
||||||
if(func_ptr != NULL) {
|
if(func_ptr != NULL) {
|
||||||
if(hook_type == WUPS_LOADER_HOOK_INIT_FS) {
|
if(hook_type == WUPS_LOADER_HOOK_INIT_FS) {
|
||||||
wups_loader_init_fs_args_t args;
|
wups_loader_init_fs_args_t args;
|
||||||
args.open_repl = (const void*)&open;
|
// open is defined as "extern int open (const char *, int, ...);", we are ignoring the varargs part
|
||||||
args.close_repl = (const void*)&close;
|
args.open_repl = (OpenFunction) &open;
|
||||||
args.write_repl = (const void*)&write;
|
args.close_repl = &close;
|
||||||
args.read_repl = (const void*)&read;
|
args.write_repl = &write;
|
||||||
args.lseek_repl = (const void*)&lseek;
|
args.read_repl = &read;
|
||||||
args.stat_repl = (const void*)&stat;
|
args.lseek_repl = &lseek;
|
||||||
args.fstat_repl = (const void*)&fstat;
|
args.stat_repl = &stat;
|
||||||
args.opendir_repl = (const void*)&opendir;
|
args.fstat_repl = &fstat;
|
||||||
args.closedir_repl = (const void*)&closedir;
|
args.opendir_repl = &opendir;
|
||||||
args.readdir_repl = (const void*)&readdir;
|
args.closedir_repl = &closedir;
|
||||||
args.mkdir_repl = (const void*)&mkdir;
|
args.readdir_repl = &readdir;
|
||||||
|
args.mkdir_repl = &mkdir;
|
||||||
((void (*)(wups_loader_init_fs_args_t))((uint32_t*)func_ptr) )(args);
|
((void (*)(wups_loader_init_fs_args_t))((uint32_t*)func_ptr) )(args);
|
||||||
} else if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) {
|
} else if(hook_type == WUPS_LOADER_HOOK_INIT_OVERLAY) {
|
||||||
wups_loader_init_overlay_args_t args;
|
wups_loader_init_overlay_args_t args;
|
||||||
args.overlayfunction_ptr = (const void*)&overlay_helper;
|
args.overlayfunction_ptr = &overlay_helper;
|
||||||
|
|
||||||
((void (*)(wups_loader_init_overlay_args_t))((uint32_t*)func_ptr) )(args);
|
((void (*)(wups_loader_init_overlay_args_t))((uint32_t*)func_ptr) )(args);
|
||||||
} else if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
|
} else if(hook_type == WUPS_LOADER_HOOK_INIT_PLUGIN) {
|
||||||
((void (*)(void))((uint32_t*)func_ptr) )();
|
((void (*)(void))((uint32_t*)func_ptr) )();
|
||||||
|
@ -7,89 +7,89 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <wups.h>
|
#include <wups.h>
|
||||||
|
|
||||||
static void * new_open_ptr __attribute__((section(".data"))) = NULL;
|
static OpenFunction new_open_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_close_ptr __attribute__((section(".data"))) = NULL;
|
static CloseFunction new_close_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_write_ptr __attribute__((section(".data"))) = NULL;
|
static WriteFunction new_write_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_read_ptr __attribute__((section(".data"))) = NULL;
|
static ReadFunction new_read_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_lseek_ptr __attribute__((section(".data"))) = NULL;
|
static LSeekFunction new_lseek_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_stat_ptr __attribute__((section(".data"))) = NULL;
|
static StatFunction new_stat_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_fstat_ptr __attribute__((section(".data"))) = NULL;
|
static FStatFunction new_fstat_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_opendir_ptr __attribute__((section(".data"))) = NULL;
|
static OpenDirFunction new_opendir_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_closedir_ptr __attribute__((section(".data"))) = NULL;
|
static CloseDirFunction new_closedir_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_readdir_ptr __attribute__((section(".data"))) = NULL;
|
static ReadDirFunction new_readdir_ptr __attribute__((section(".data"))) = NULL;
|
||||||
static void * new_mkdir_ptr __attribute__((section(".data"))) = NULL;
|
static MKDirFunction new_mkdir_ptr __attribute__((section(".data"))) = NULL;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void WUPS_InitFS(wups_loader_init_fs_args_t args) {
|
void WUPS_InitFS(wups_loader_init_fs_args_t args) {
|
||||||
new_open_ptr = (void*) args.open_repl;
|
new_open_ptr = args.open_repl;
|
||||||
new_close_ptr = (void*) args.close_repl;
|
new_close_ptr = args.close_repl;
|
||||||
new_write_ptr = (void*) args.write_repl;
|
new_write_ptr = args.write_repl;
|
||||||
new_read_ptr = (void*) args.read_repl;
|
new_read_ptr = args.read_repl;
|
||||||
new_lseek_ptr = (void*) args.lseek_repl;
|
new_lseek_ptr = args.lseek_repl;
|
||||||
new_stat_ptr = (void*) args.stat_repl;
|
new_stat_ptr = args.stat_repl;
|
||||||
new_fstat_ptr = (void*) args.fstat_repl;
|
new_fstat_ptr = args.fstat_repl;
|
||||||
new_opendir_ptr = (void*) args.opendir_repl;
|
new_opendir_ptr = args.opendir_repl;
|
||||||
new_closedir_ptr = (void*) args.closedir_repl;
|
new_closedir_ptr = args.closedir_repl;
|
||||||
new_readdir_ptr = (void*) args.readdir_repl;
|
new_readdir_ptr = args.readdir_repl;
|
||||||
new_mkdir_ptr = (void*) args.mkdir_repl;
|
new_mkdir_ptr = args.mkdir_repl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __real_open(const char *pathname, int flags);
|
int __real_open(const char *pathname, int flags);
|
||||||
int __wrap_open(const char *pathname, int flags) {
|
int __wrap_open(const char *pathname, int flags) {
|
||||||
if(new_open_ptr == NULL) return __real_open(pathname,flags);
|
if(new_open_ptr == NULL) return __real_open(pathname,flags);
|
||||||
return ( (int (*)(const char *,int))((unsigned int*)new_open_ptr) )(pathname,flags);
|
return new_open_ptr(pathname,flags);
|
||||||
}
|
}
|
||||||
int __real_close(int fd);
|
int __real_close(int fd);
|
||||||
int __wrap_close(int fd) {
|
int __wrap_close(int fd) {
|
||||||
if(new_close_ptr == NULL) return __real_close(fd);
|
if(new_close_ptr == NULL) return __real_close(fd);
|
||||||
return ( (int (*)(int))((unsigned int*)new_close_ptr) )(fd);
|
return new_close_ptr(fd);
|
||||||
}
|
}
|
||||||
ssize_t __real_write(int fd, const void *buf, size_t count);
|
ssize_t __real_write(int fd, const void *buf, size_t count);
|
||||||
ssize_t __wrap_write(int fd, const void *buf, size_t count) {
|
ssize_t __wrap_write(int fd, const void *buf, size_t count) {
|
||||||
if(new_write_ptr == NULL) return __real_write(fd,buf,count);
|
if(new_write_ptr == NULL) return __real_write(fd,buf,count);
|
||||||
return ( (ssize_t (*)(int, const void *, size_t))((unsigned int*)new_write_ptr) )(fd,buf,count);
|
return new_write_ptr(fd,buf,count);
|
||||||
}
|
}
|
||||||
ssize_t __real_read(int fd, const void *buf, size_t count);
|
ssize_t __real_read(int fd, void *buf, size_t count);
|
||||||
ssize_t __wrap_read(int fd, const void *buf, size_t count) {
|
ssize_t __wrap_read(int fd, void *buf, size_t count) {
|
||||||
if(new_read_ptr == NULL) return __real_read(fd,buf,count);
|
if(new_read_ptr == NULL) return __real_read(fd,buf,count);
|
||||||
return ( (ssize_t (*)(int, const void *, size_t))((unsigned int*)new_read_ptr) )(fd,buf,count);
|
return new_read_ptr(fd,buf,count);
|
||||||
}
|
}
|
||||||
off_t __real_lseek(int fd, off_t offset, int whence);
|
off_t __real_lseek(int fd, off_t offset, int whence);
|
||||||
off_t __wrap_lseek(int fd, off_t offset, int whence) {
|
off_t __wrap_lseek(int fd, off_t offset, int whence) {
|
||||||
if(new_lseek_ptr == NULL) return __real_lseek(fd, offset, whence);
|
if(new_lseek_ptr == NULL) return __real_lseek(fd, offset, whence);
|
||||||
return ( (off_t (*)(int, off_t, int))((unsigned int*)new_lseek_ptr) )(fd, offset, whence);
|
return new_lseek_ptr(fd, offset, whence);
|
||||||
}
|
}
|
||||||
int __real_stat(const char *pathname, struct stat *statbuf);
|
int __real_stat(const char *pathname, struct stat *statbuf);
|
||||||
int __wrap_stat(const char *pathname, struct stat *statbuf) {
|
int __wrap_stat(const char *pathname, struct stat *statbuf) {
|
||||||
if(new_stat_ptr == NULL) return __real_stat(pathname,statbuf);
|
if(new_stat_ptr == NULL) return __real_stat(pathname,statbuf);
|
||||||
return ( (int (*)(const char *, struct stat *))((unsigned int*)new_stat_ptr) )(pathname,statbuf);
|
return new_stat_ptr(pathname,statbuf);
|
||||||
}
|
}
|
||||||
int __real_fstat(int fd, struct stat *statbuf);
|
int __real_fstat(int fd, struct stat *statbuf);
|
||||||
int __wrap_fstat(int fd, struct stat *statbuf) {
|
int __wrap_fstat(int fd, struct stat *statbuf) {
|
||||||
if(new_fstat_ptr == NULL) return __real_fstat(fd,statbuf);
|
if(new_fstat_ptr == NULL) return __real_fstat(fd,statbuf);
|
||||||
return ( (int (*)(int, struct stat *))((unsigned int*)new_fstat_ptr) )(fd,statbuf);
|
return new_fstat_ptr(fd,statbuf);
|
||||||
}
|
}
|
||||||
DIR* __real_opendir(const char * arg);
|
DIR* __real_opendir(const char * arg);
|
||||||
DIR* __wrap_opendir(const char * arg) {
|
DIR* __wrap_opendir(const char * arg) {
|
||||||
if(new_opendir_ptr == NULL) return __real_opendir(arg);
|
if(new_opendir_ptr == NULL) return __real_opendir(arg);
|
||||||
return ( (DIR* (*)(const char *))((unsigned int*)new_opendir_ptr) )(arg);
|
return new_opendir_ptr(arg);
|
||||||
}
|
}
|
||||||
int __real_closedir(DIR *dirp);
|
int __real_closedir(DIR *dirp);
|
||||||
int __wrap_closedir(DIR *dirp) {
|
int __wrap_closedir(DIR *dirp) {
|
||||||
if(new_closedir_ptr == NULL) return __real_closedir(dirp);
|
if(new_closedir_ptr == NULL) return __real_closedir(dirp);
|
||||||
return ( (int (*)(DIR *))((unsigned int*)new_closedir_ptr) )(dirp);
|
return new_closedir_ptr(dirp);
|
||||||
}
|
}
|
||||||
struct dirent * __real_readdir(DIR *dirp);
|
struct dirent * __real_readdir(DIR *dirp);
|
||||||
struct dirent * __wrap_readdir(DIR *dirp) {
|
struct dirent * __wrap_readdir(DIR *dirp) {
|
||||||
if(new_readdir_ptr == NULL) return __real_readdir(dirp);
|
if(new_readdir_ptr == NULL) return __real_readdir(dirp);
|
||||||
return ( (struct dirent * (*)(DIR *))((unsigned int*)new_readdir_ptr) )(dirp);
|
return new_readdir_ptr(dirp);
|
||||||
}
|
}
|
||||||
int __real_mkdir(const char *path, mode_t mode);
|
int __real_mkdir(const char *path, mode_t mode);
|
||||||
int __wrap_mkdir(const char *path, mode_t mode) {
|
int __wrap_mkdir(const char *path, mode_t mode) {
|
||||||
if(new_mkdir_ptr == NULL) return __real_mkdir(path, mode);
|
if(new_mkdir_ptr == NULL) return __real_mkdir(path, mode);
|
||||||
return ( (int (*)(const char *, mode_t))((unsigned int*) new_mkdir_ptr) )(path, mode);
|
return new_mkdir_ptr(path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -21,13 +21,13 @@ void OSScreenPutFontEx(uint32_t bufferNum, uint32_t posX, uint32_t posY, const c
|
|||||||
void OSScreenEnableEx(uint32_t bufferNum, int32_t enable);
|
void OSScreenEnableEx(uint32_t bufferNum, int32_t enable);
|
||||||
void OSScreenPutPixelEx(uint32_t bufferNum, uint32_t posX, uint32_t posY, uint32_t color);
|
void OSScreenPutPixelEx(uint32_t bufferNum, uint32_t posX, uint32_t posY, uint32_t color);
|
||||||
|
|
||||||
static void * overlayfunction_ptr __attribute__((section(".data"))) = NULL;
|
static OverlayOpenFunction overlayfunction_ptr __attribute__((section(".data"))) = NULL;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
void WUPS_InitOverlay(wups_loader_init_overlay_args_t args) {
|
void WUPS_InitOverlay(wups_loader_init_overlay_args_t args) {
|
||||||
overlayfunction_ptr = (void*) args.overlayfunction_ptr;
|
overlayfunction_ptr = args.overlayfunction_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...) {
|
void WUPS_Overlay_PrintTextOnScreen(wups_overlay_options_type_t screen, int x,int y, const char * msg, ...) {
|
||||||
@ -80,7 +80,7 @@ void WUPS_Overlay_FlipBuffers(wups_overlay_options_type_t screen) {
|
|||||||
|
|
||||||
void WUPS_OpenOverlay(wups_overlay_options_type_t screen, overlay_callback callback) {
|
void WUPS_OpenOverlay(wups_overlay_options_type_t screen, overlay_callback callback) {
|
||||||
if(overlayfunction_ptr != NULL) {
|
if(overlayfunction_ptr != NULL) {
|
||||||
( (void (*)(wups_overlay_options_type_t, overlay_callback))((unsigned int*)overlayfunction_ptr) )(screen,callback);
|
overlayfunction_ptr(screen,callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define WUPS_HOOKS_DEF_H_
|
#define WUPS_HOOKS_DEF_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -57,31 +58,11 @@ typedef enum wups_loader_app_status_t {
|
|||||||
WUPS_APP_STATUS_UNKNOWN, /* Unknown status _should_ never happen.*/
|
WUPS_APP_STATUS_UNKNOWN, /* Unknown status _should_ never happen.*/
|
||||||
} wups_loader_app_status_t;
|
} wups_loader_app_status_t;
|
||||||
|
|
||||||
typedef struct wups_loader_init_overlay_args_t {
|
|
||||||
const void * overlayfunction_ptr;
|
|
||||||
} wups_loader_init_overlay_args_t;
|
|
||||||
|
|
||||||
typedef struct wups_loader_init_fs_args_t {
|
|
||||||
const void * open_repl;
|
|
||||||
const void * close_repl;
|
|
||||||
const void * write_repl;
|
|
||||||
const void * read_repl;
|
|
||||||
const void * lseek_repl;
|
|
||||||
const void * stat_repl;
|
|
||||||
const void * fstat_repl;
|
|
||||||
const void * opendir_repl;
|
|
||||||
const void * closedir_repl;
|
|
||||||
const void * readdir_repl;
|
|
||||||
const void * mkdir_repl;
|
|
||||||
} wups_loader_init_fs_args_t;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct wups_loader_app_started_args_t {
|
typedef struct wups_loader_app_started_args_t {
|
||||||
bool sd_mounted;
|
bool sd_mounted;
|
||||||
bool usb_mounted;
|
bool usb_mounted;
|
||||||
} wups_loader_app_started_args_t;
|
} wups_loader_app_started_args_t;
|
||||||
|
|
||||||
|
|
||||||
#define WUPS_FS_ACCESS() \
|
#define WUPS_FS_ACCESS() \
|
||||||
void init_fs(wups_loader_init_fs_args_t);\
|
void init_fs(wups_loader_init_fs_args_t);\
|
||||||
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_FS,init_fs); \
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_FS,init_fs); \
|
||||||
|
@ -35,6 +35,40 @@ wups_overlay_options_type_t;
|
|||||||
|
|
||||||
typedef void (*overlay_callback)(wups_overlay_options_type_t);
|
typedef void (*overlay_callback)(wups_overlay_options_type_t);
|
||||||
|
|
||||||
|
typedef void (*OverlayOpenFunction)(wups_overlay_options_type_t screen, overlay_callback callback);
|
||||||
|
|
||||||
|
typedef struct wups_loader_init_overlay_args_t {
|
||||||
|
OverlayOpenFunction overlayfunction_ptr;
|
||||||
|
} wups_loader_init_overlay_args_t;
|
||||||
|
|
||||||
|
typedef int (*OpenFunction) (const char *pathname, int flags);
|
||||||
|
typedef ssize_t (*WriteFunction) (int fd, const void *buf, size_t count);
|
||||||
|
typedef int (*CloseFunction) (int fd);
|
||||||
|
typedef ssize_t (*ReadFunction) (int fd, void *buf, size_t count);
|
||||||
|
typedef off_t (*LSeekFunction) (int fd, off_t offset, int whence);
|
||||||
|
typedef int (*StatFunction) (const char *pathname, struct stat *statbuf);
|
||||||
|
typedef int (*FStatFunction) (int fd, struct stat *statbuf);
|
||||||
|
typedef DIR* (*OpenDirFunction) (const char * arg);
|
||||||
|
typedef int (*CloseDirFunction) (DIR *dirp);
|
||||||
|
typedef struct dirent * (*ReadDirFunction) (DIR *dirp);
|
||||||
|
typedef int (*MKDirFunction) (const char *path, mode_t mode);
|
||||||
|
|
||||||
|
typedef struct wups_loader_init_fs_args_t {
|
||||||
|
OpenFunction open_repl;
|
||||||
|
CloseFunction close_repl;
|
||||||
|
WriteFunction write_repl;
|
||||||
|
ReadFunction read_repl;
|
||||||
|
LSeekFunction lseek_repl;
|
||||||
|
StatFunction stat_repl;
|
||||||
|
FStatFunction fstat_repl;
|
||||||
|
OpenDirFunction opendir_repl;
|
||||||
|
CloseDirFunction closedir_repl;
|
||||||
|
ReadDirFunction readdir_repl;
|
||||||
|
MKDirFunction mkdir_repl;
|
||||||
|
} wups_loader_init_fs_args_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Gets called by the framework
|
Gets called by the framework
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user