Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include $(TOPDIR)/share/wums_rules

export WUMS_MAJOR := 0
export WUMS_MINOR := 3
export WUMS_PATCH := 5
export WUMS_PATCH := 6

VERSION := $(WUMS_MAJOR).$(WUMS_MINOR).$(WUMS_PATCH)

Expand Down
13 changes: 12 additions & 1 deletion include/wums/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "common.h"
#include "defines/module_defines.h"
#include "reent_internal.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -68,7 +69,9 @@ typedef enum wums_hook_type_t {
WUMS_HOOK_GET_CUSTOM_RPL_ALLOCATOR, // for internal usage only
WUMS_HOOK_CLEAR_ALLOCATED_RPL_MEMORY, // for internal usage only
// Introduced in 0.3.5
WUMS_HOOK_INIT_WUT_THREAD // for internal usage only
WUMS_HOOK_INIT_WUT_THREAD, // for internal usage only
// Introduced in 0.3.6
WUMS_HOOK_INIT_REENT_FUNCTIONS // for internal usage only
} wums_hook_type_t;

typedef uint32_t (*WUMSRPLAllocatorAllocFn)(int32_t size, int32_t align, void **outAddr);
Expand Down Expand Up @@ -196,6 +199,14 @@ typedef struct wums_relocs_done_args_t {
} \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_THREAD, on_init_wut_thread);

#define WUMS_INIT_REENT_FUNCTIONS() \
__EXTERN_C_MACRO void WUMSReentAPI_InitInternal(wums_loader_init_reent_args_t_); \
void wums_init_reent_functions(wums_loader_init_reent_args_t_ args); \
WUMS_HOOK_EX(WUMS_HOOK_INIT_REENT_FUNCTIONS, wums_init_reent_functions); \
void wums_init_reent_functions(wums_loader_init_reent_args_t_ args) { \
return WUMSReentAPI_InitInternal(args); \
}

#define WUMS_USE_WUT_SOCKETS() \
__EXTERN_C_MACRO void __init_wut_socket(); \
WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_SOCKETS, __init_wut_socket); \
Expand Down
3 changes: 2 additions & 1 deletion include/wums/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
extern "C" {
#endif

#define WUMS_VERSION "0.3.5"
#define WUMS_VERSION "0.3.6"

#define WUMS_MODULE_EXPORT_NAME(__module_name) \
WUMS_META(export_name, __module_name); \
Expand All @@ -50,6 +50,7 @@ extern "C" {
WUMS_USE_WUT_THREAD(); \
WUMS___INIT_WRAPPER(); \
WUMS___FINI_WRAPPER(); \
WUMS_INIT_REENT_FUNCTIONS(); \
WUMS_META(buildtimestamp, __DATE__ " " __TIME__); \
extern const char wums_meta_module_name[] WUMS_SECTION("meta"); \
const char wums_meta_module_name[] = __module_name; \
Expand Down
35 changes: 35 additions & 0 deletions include/wums/reent_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum wums_loader_init_reent_errors_t_ {
WUMSReent_ERROR_NONE = 0,
WUMSReent_ERROR_GLOBAL_REENT_REQUESTED = 1,
WUMSReent_ERROR_NO_THREAD = 2,
} wums_loader_init_reent_errors_t_;

typedef void *(*WUMSReent_GetReentContext)(const void *moduleId, wums_loader_init_reent_errors_t_ *outError);
typedef void *(*WUMSReent_SetSentinel)();
typedef void (*WUMSReent_RestoreHead)(void *oldHead);
typedef bool (*WUMSReent_AddReentContext)(const void *moduleId, void *reentPtr, void (*cleanupFn)(void *), void *oldHead);

typedef uint32_t WUMS_REENT_API_VERSION;

#define WUMS_REENT_CUR_API_VERSION 0x01

typedef struct wums_loader_init_reent_args_t_ {
WUMS_REENT_API_VERSION version;
WUMSReent_GetReentContext get_context_ptr;
WUMSReent_SetSentinel set_sentinel_ptr;
WUMSReent_RestoreHead restore_head_ptr;
WUMSReent_AddReentContext add_reent_context_ptr;
} wums_loader_init_reent_args_t_;

void WUMSReentAPI_InitInternal(wums_loader_init_reent_args_t_ args);

#ifdef __cplusplus
}
#endif
19 changes: 2 additions & 17 deletions include/wums/wums_debug.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
#pragma once

#if defined(__GNUC__) || defined(__clang__)

#define WUMS_FORMAT_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args)))

#else // not __GNUC__ and not __clang__

#define WUMS_FORMAT_PRINTF(fmt, args)

#endif //__GNUC__ or __clang__

extern "C" void OSReport(const char *fmt, ...);

#ifdef __cplusplus
extern "C" {
#endif


#ifdef DEBUG
extern void OSReport(const char *fmt, ...) WUMS_FORMAT_PRINTF(1, 2);
#endif

extern const char wums_meta_info_dump[];
#ifdef __cplusplus
}
Expand All @@ -31,4 +16,4 @@ extern const char wums_meta_info_dump[];
#define WUMS_DEBUG_REPORT(fmt, ...)
#endif

#define WUMS_DEBUG_WARN(fmt, ...) OSReport("[%s] " fmt, wums_meta_info_dump, ##__VA_ARGS__)
#define WUMS_DEBUG_WARN(fmt, ...) OSReport("\033[33m[%s] " fmt "\033[0m", wums_meta_info_dump, ##__VA_ARGS__)
24 changes: 17 additions & 7 deletions libraries/libwums/crt.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "wums/wums_debug.h"
#include "wums_reent.h"
#include "wums_thread_specific.h"

#include <cstdio>
#include <cstring>

extern "C" void OSFatal(const char *);
extern "C" void OSFatal(const char *);

int main(int argc, char **argv) {
Expand Down Expand Up @@ -43,16 +45,22 @@ struct _reent *__getreent(void) {
return __wums_getreent();
}

extern "C" void __attribute__((weak)) wut_set_thread_specific(__wut_thread_specific_id id, void *value);

void wut_set_thread_specific(__wut_thread_specific_id id, void *value) {
return wums_set_thread_specific(id, value);
}
typedef enum __wut_thread_specific_id {
WUT_THREAD_SPECIFIC_0 = 0,
WUT_THREAD_SPECIFIC_1 = 1,
} __wut_thread_specific_id;

extern "C" void *__attribute__((weak)) wut_get_thread_specific(__wut_thread_specific_id id);

void *wut_get_thread_specific(__wut_thread_specific_id id) {
return wums_get_thread_specific(id);
if ((uint32_t) id == 0x13371337) { // Mechanism to detect if the function was overridden properly
return (void *) 0x42424242;
}

WUMS_DEBUG_WARN("wums_get_thread_specific: NOT SUPPORTED\n");
OSFatal("wums_get_thread_specific: NOT SUPPORTED\n");

return nullptr;
}

extern "C" const char wums_meta_module_name[];
Expand Down Expand Up @@ -100,6 +108,8 @@ __assert_func(const char *file,
}

OSFatal(buffer);
while (true)
;
/* NOTREACHED */
}

Expand Down
Loading
Loading