Implement WUMS 0.2

This commit is contained in:
Maschell 2021-09-17 16:17:54 +02:00
parent f461fc4539
commit c5af736523
13 changed files with 170 additions and 113 deletions

View File

@ -1,4 +1,4 @@
FROM wiiuenv/devkitppc:20210414
FROM wiiuenv/devkitppc:20210917
WORKDIR build
COPY . .

View File

@ -2,8 +2,8 @@ TOPDIR ?= $(CURDIR)
include $(TOPDIR)/share/wums_rules
export WUMS_MAJOR := 0
export WUMS_MINOR := 1
export WUMS_PATCH := 3
export WUMS_MINOR := 2
export WUMS_PATCH := 0
VERSION := $(WUMS_MAJOR).$(WUMS_MINOR).$(WUMS_PATCH)

View File

@ -1,8 +1,6 @@
#ifndef WUMS_H_
#define WUMS_H_
#pragma once
#include "wums/meta.h"
#include "wums/common.h"
#include "wums/exports.h"
#include "wums/hooks.h"
#endif /* WUMS_H_ */
#include "wums/hooks.h"

View File

@ -2,7 +2,7 @@
* by Alex Chadwick
*
* Copyright (C) 2014, Alex Chadwick
* Modified by Maschell, 2018-2020
* Modified by Maschell, 2018-2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -23,18 +23,9 @@
* SOFTWARE.
*/
#ifndef WUMS_COMMON_DEF_H_
#define WUMS_COMMON_DEF_H_
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <stdbool.h>
#include "defines/module_defines.h"
#ifdef __cplusplus
extern "C" {
@ -46,17 +37,6 @@ extern "C" {
extern const char wums_meta_ ## id [] WUMS_SECTION("meta"); \
const char wums_meta_ ## id [] = #id "=" value
#define WUMS_MODULE_EXPORT_NAME(x) WUMS_META(export_name, x); WUMS_META(wum, "0.1"); WUMS_META(buildtimestamp, __DATE__ " " __TIME__)
#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x)
#define WUMS_MODULE_VERSION(x) WUMS_META(version, x)
#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x)
#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x)
#define WUMS_MODULE_SKIP_ENTRYPOINT() WUMS_META(skipEntrypoint, "true")
#define WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK() WUMS_META(initBeforeRelocationDoneHook, "true")
#define WUMS_MODULE_SKIP_WUT_INIT() WUMS_META(skipwutInit, "true")
#ifdef __cplusplus
}
#endif
#endif /* WUMS_COMMON_DEF_H_ */

View File

@ -17,6 +17,7 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@ -39,13 +40,13 @@ typedef struct _dyn_linking_function_t {
typedef struct _dyn_linking_import_t {
char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1];
bool isData = false;
bool isData;
} dyn_linking_import_t;
typedef struct _dyn_linking_relocation_entry_t {
dyn_linking_function_t *functionEntry = NULL;
dyn_linking_import_t *importEntry = NULL;
void *destination = NULL;
dyn_linking_function_t *functionEntry;
dyn_linking_import_t *importEntry;
void *destination;
char type;
size_t offset;
int32_t addend;

View File

@ -6,5 +6,5 @@
typedef struct export_data_t {
uint32_t type;
char name[EXPORT_MAXIMUM_NAME_LENGTH];
uint32_t address = 0;
uint32_t address;
} export_data_t;

View File

@ -32,15 +32,15 @@ extern "C" {
#define DYN_LINK_RELOCATION_LIST_LENGTH 500
#define EXPORT_ENTRY_LIST_LENGTH 100
#define HOOK_ENTRY_LIST_LENGTH 10
#define HOOK_ENTRY_LIST_LENGTH 20
typedef struct hook_data_t {
uint32_t type;
uint32_t target = 0;
uint32_t target;
} hook_data_t;
struct module_information_single_t {
char path[MAXIMUM_MODULE_PATH_NAME_LENGTH] = ""; // Path where the module is stored
typedef struct module_information_single_t {
char path[MAXIMUM_MODULE_PATH_NAME_LENGTH]; // Path where the module is stored
dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH];
char module_export_name[MAXIMUM_EXPORT_MODULE_NAME_LENGTH];
export_data_t export_entries[EXPORT_ENTRY_LIST_LENGTH];
@ -55,19 +55,18 @@ struct module_information_single_t {
uint32_t endAddress;
uint8_t skipEntrypoint;
uint8_t initBeforeRelocationDoneHook;
uint8_t skipWUTInit;
};
} module_information_single_t;
#define MAXIMUM_MODULES 8
#define MODULE_INFORMATION_VERSION 0x00000003
#define MODULE_INFORMATION_VERSION 0x00000004
struct module_information_t {
uint32_t version = MODULE_INFORMATION_VERSION;
int32_t number_used_modules = 0; // Number of used function. Maximum is MAXIMUM_MODULES
typedef struct module_information_t {
uint32_t version;
int32_t number_used_modules; // Number of used function. Maximum is MAXIMUM_MODULES
dyn_linking_relocation_data_t linking_data;
relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH];
module_information_single_t module_data[MAXIMUM_MODULES];
};
} module_information_t;
#ifdef __cplusplus
}

View File

@ -16,5 +16,5 @@ typedef enum RelocationType{
typedef struct relocation_trampolin_entry_t {
uint32_t id;
uint32_t trampolin[4];
RelocationTrampolinStatus status = RELOC_TRAMP_FREE;
RelocationTrampolinStatus status;
} relocation_trampolin_entry_t;

View File

@ -2,7 +2,7 @@
* by Alex Chadwick
*
* Copyright (C) 2014, Alex Chadwick
* Modified by Maschell, 2018-2020
* Modified by Maschell, 2018-2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -23,8 +23,7 @@
* SOFTWARE.
*/
#ifndef WUMS_FUNCTION_EXPORT_DEF_H_
#define WUMS_FUNCTION_EXPORT_DEF_H_
#pragma once
#include "common.h"
@ -55,9 +54,6 @@ typedef struct wums_entry_t {
.address = (const void*) value \
}
#ifdef __cplusplus
}
#endif
#endif /* WUMS_FUNCTION_EXPORT_DEF_H_ */
#endif

View File

@ -2,7 +2,7 @@
* by Alex Chadwick
*
* Copyright (C) 2014, Alex Chadwick
* Modified by Maschell, 2018-2020
* Modified by Maschell, 2018-2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -40,11 +40,20 @@ extern "C" {
}
typedef enum wums_hook_type_t {
WUMS_HOOK_INIT_WUT_MALLOC,
WUMS_HOOK_FINI_WUT_MALLOC,
WUMS_HOOK_INIT_WUT_NEWLIB,
WUMS_HOOK_FINI_WUT_NEWLIB,
WUMS_HOOK_INIT_WUT_STDCPP,
WUMS_HOOK_FINI_WUT_STDCPP,
WUMS_HOOK_INIT_WUT_DEVOPTAB,
WUMS_HOOK_FINI_WUT_DEVOPTAB,
WUMS_HOOK_INIT_WUT_SOCKETS,
WUMS_HOOK_FINI_WUT_SOCKETS,
WUMS_HOOK_INIT,
WUMS_HOOK_APPLICATION_STARTS,
WUMS_HOOK_APPLICATION_ENDS,
WUMS_HOOK_INIT_WUT,
WUMS_HOOK_FINI_WUT,
WUMS_HOOK_RELOCATIONS_DONE,
WUMS_HOOK_APPLICATION_REQUESTS_EXIT,
} wums_hook_type_t;
@ -63,8 +72,6 @@ typedef struct wums_relocs_done_args_t {
} wums_relocs_done_args_t;
#define WUMS_INITIALIZE(myargs) \
WUMS_INIT_WUT(); \
WUMS_FINI_WUT(); \
void __wums__init(wums_app_init_args_t);\
WUMS_HOOK_EX(WUMS_HOOK_INIT, __wums__init); \
void __wums__init(wums_app_init_args_t myargs)
@ -88,43 +95,67 @@ typedef struct wums_relocs_done_args_t {
void __wums_relocations_done(wums_relocs_done_args_t);\
WUMS_HOOK_EX(WUMS_HOOK_RELOCATIONS_DONE, __wums_relocations_done); \
void __wums_relocations_done(wums_relocs_done_args_t myargs)
#ifdef __cplusplus
#define WUMS_INIT_WUT() \
void __wums_init_wut(void);\
extern "C" void __init_wut(void);\
void __wums_init_wut(){ \
__init_wut(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT, __wums_init_wut)
#else
#define WUMS_INIT_WUT() \
void __wums_init_wut(void);\
extern void __init_wut(void);\
void __wums_init_wut(){ \
__init_wut(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT, __wums_init_wut)
#endif
#ifdef __cplusplus
#define WUMS_FINI_WUT() \
void __wums_fini_wut(void);\
extern "C" void __fini_wut(void);\
void __wums_fini_wut(){ \
__fini_wut(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT, __wums_fini_wut)
#define __EXTERN_C_MACRO extern "C"
#else
#define WUMS_FINI_WUT() \
void __wums_fini_wut(void);\
extern void __fini_wut(void);\
void __wums_fini_wut(){ \
__fini_wut(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT, __wums_fini_wut)
#define __EXTERN_C_MACRO
#endif
#define WUMS_USE_WUT_MALLOC() \
__EXTERN_C_MACRO void __init_wut_malloc(); \
void on_init_wut_malloc(){ \
__init_wut_malloc(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_MALLOC,on_init_wut_malloc); \
__EXTERN_C_MACRO void __fini_wut_malloc(); \
void on_fini_wut_malloc(){ \
__fini_wut_malloc(); \
} \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_MALLOC,on_fini_wut_malloc); \
#define WUMS_USE_WUT_DEVOPTAB() \
__EXTERN_C_MACRO void __init_wut_devoptab(); \
void on_init_wut_devoptab(){ \
__init_wut_devoptab(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_DEVOPTAB,on_init_wut_devoptab); \
__EXTERN_C_MACRO void __fini_wut_devoptab(); \
void on_fini_wut_devoptab(){ \
__fini_wut_devoptab(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_DEVOPTAB,on_fini_wut_devoptab);
#define WUMS_USE_WUT_NEWLIB() \
__EXTERN_C_MACRO void __init_wut_newlib(); \
void on_init_wut_newlib(){ \
__init_wut_newlib(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_NEWLIB,on_init_wut_newlib); \
__EXTERN_C_MACRO void __fini_wut_newlib(); \
void on_fini_wut_newlib(){ \
__fini_wut_newlib(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_NEWLIB,on_fini_wut_newlib);
#define WUMS_USE_WUT_STDCPP() \
__EXTERN_C_MACRO void __init_wut_stdcpp(); \
void on_init_wut_stdcpp(){ \
__init_wut_stdcpp(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_STDCPP,on_init_wut_stdcpp); \
__EXTERN_C_MACRO void __fini_wut_stdcpp(); \
void on_fini_wut_stdcpp(){ \
__fini_wut_stdcpp(); \
}\
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_STDCPP,on_fini_wut_stdcpp);
#define WUMS_USE_WUT_SOCKETS() \
__EXTERN_C_MACRO void __init_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_SOCKETS,__init_wut_socket); \
__EXTERN_C_MACRO void __fini_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_SOCKETS,__fini_wut_socket);
#ifdef __cplusplus
}
#endif
#endif

45
include/wums/meta.h Normal file
View File

@ -0,0 +1,45 @@
/* based on blsug.h
* by Alex Chadwick
*
* Copyright (C) 2014, Alex Chadwick
* Modified by Maschell, 2018-2021
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include "common.h"
#include "hooks.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WUMS_MODULE_EXPORT_NAME(x) WUMS_META(export_name, x); WUMS_META(wum, "0.2"); WUMS_USE_WUT_MALLOC() WUMS_USE_WUT_SOCKETS() WUMS_USE_WUT_NEWLIB() WUMS_USE_WUT_STDCPP() WUMS_META(buildtimestamp, __DATE__ " " __TIME__);
#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x)
#define WUMS_MODULE_VERSION(x) WUMS_META(version, x)
#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x)
#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x)
#define WUMS_MODULE_SKIP_ENTRYPOINT() WUMS_META(skipEntrypoint, "true")
#define WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK() WUMS_META(initBeforeRelocationDoneHook, "true")
#ifdef __cplusplus
}
#endif

View File

@ -1,3 +1,27 @@
int main(int argc, char** argv){
int main(int argc, char **argv) {
return 0;
}
extern __attribute__((weak)) void __wut_socket_init_devoptab();
extern __attribute__((weak)) void __wut_socket_fini_devoptab();
static int __wut_socket_devoptab_added = 0;
extern void socket_lib_init();
void __attribute__((weak)) __init_wut_socket() {
if(!&__wut_socket_init_devoptab) return;
if (!__wut_socket_devoptab_added) {
socket_lib_init();
__wut_socket_init_devoptab();
__wut_socket_devoptab_added = 1;
}
}
void __attribute__((weak)) __fini_wut_socket() {
if(!&__wut_socket_init_devoptab || !&__wut_socket_fini_devoptab) return;
if (__wut_socket_devoptab_added) {
__wut_socket_fini_devoptab();
__wut_socket_devoptab_added = 0;
}
}

View File

@ -1,24 +1,7 @@
.extern main
.extern exit
.extern __init_wut
.extern __fini_wut
.section .crt0, "ax", @progbits
.global __wums_start
__wums_start:
stwu 1, -0x28(1)
mflr 0
stw 0, 0x2C(1)
stw 31, 0x24(1)
or 31, 1, 1
stw 3, 0x18(31)
stw 4, 0x1C(31)
bl __init_wut
lwz 4, 0x1C(31)
lwz 3, 0x18(31)
bl main
addi 11, 31, 0x28
lwz 0, 0x4(11)
mtlr 0
lwz 31, -0x4(11)
or 1, 11, 11
blr
b main