Index: src/amiga-glue.h ================================================================== --- src/amiga-glue.h +++ src/amiga-glue.h @@ -43,11 +43,11 @@ #else # define PPC_PARAMS(...) (__VA_ARGS__) # define M68K_ARG(...) #endif -extern bool glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF); +extern bool glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc); extern void *_Nullable glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFAllocZeroedMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFResizeMemory PPC_PARAMS(void *_Nullable pointer, size_t count, size_t size); extern void glue_OFFreeMemory PPC_PARAMS(void *_Nullable pointer); extern void glue_OFHashInit PPC_PARAMS(unsigned long *_Nonnull hash); Index: src/amiga-glue.m ================================================================== --- src/amiga-glue.m +++ src/amiga-glue.m @@ -29,17 +29,16 @@ " blr\n" ); #endif bool __saveds -glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF) +glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc) { M68K_ARG(unsigned int, version, d0) M68K_ARG(struct OFLibC *_Nonnull, libc, a0) - M68K_ARG(FILE *_Nonnull *_Nonnull, sF, a1) - return OFInit(version, libc, sF); + return OFInit(version, libc); } void *_Nullable __saveds glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size) { Index: src/amiga-library.h ================================================================== --- src/amiga-library.h +++ src/amiga-library.h @@ -107,10 +107,9 @@ int (*_Nonnull setjmp)(jmp_buf); void __dead2 (*_Nonnull longjmp)(jmp_buf, int); #endif }; -extern bool OFInit(unsigned int version, struct OFLibC *_Nonnull libC, - FILE *_Nonnull *_Nonnull sF); +extern bool OFInit(unsigned int version, struct OFLibC *_Nonnull libC); extern unsigned long *OFHashSeedRef(void); extern void OFPBKDF2Wrapper(const OFPBKDF2Parameters *_Nonnull parameters); extern void OFScryptWrapper(const OFScryptParameters *_Nonnull parameters); Index: src/amiga-library.m ================================================================== --- src/amiga-library.m +++ src/amiga-library.m @@ -13,24 +13,26 @@ * file. */ #include "config.h" -#include -#include -#include -#include - #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFSocket.h" #import "OFStdIOStream.h" #import "OFString.h" -#import "amiga-library.h" #import "macros.h" +#import "amiga-glue.h" +#import "amiga-library.h" + +#include +#include +#include +#include + #define CONCAT_VERSION2(major, minor) #major "." #minor #define CONCAT_VERSION(major, minor) CONCAT_VERSION2(major, minor) #define VERSION_STRING CONCAT_VERSION(OBJFW_LIB_MAJOR, OBJFW_LIB_MINOR) #if defined(OF_AMIGAOS_M68K) @@ -49,10 +51,18 @@ int _start(void) { return -1; } + +#ifdef OF_AMIGAOS_M68K +void +__init_eh(void) +{ + /* Taken care of by OFInit() */ +} +#endif struct ObjFWBase { struct Library library; void *segList; struct ObjFWBase *parent; @@ -64,26 +74,15 @@ extern uintptr_t __CTOR_LIST__[]; extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif -#include "amiga-glue.h" - -#ifdef OF_AMIGAOS_M68K -void -__init_eh(void) -{ - /* Taken care of by OFInit() */ -} -#endif - #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; struct OFLibC libC; -FILE **__sF; #if defined(OF_AMIGAOS_M68K) __asm__ ( ".text\n" ".globl ___restore_a4\n" @@ -171,12 +170,12 @@ return dataDataRelocs; } static struct Library * -libInit(struct ObjFWBase *base OF_M68K_REG(d0), void *segList OF_M68K_REG(a0), - struct ExecBase *sysBase OF_M68K_REG(a6)) +libInit(struct ObjFWBase *base OF_M68K_REG(d0), + void *segList OF_M68K_REG(a0), struct ExecBase *sysBase OF_M68K_REG(a6)) { #if defined(OF_AMIGAOS_M68K) __asm__ __volatile__ ( "move.l a6, _SysBase" :: "a"(sysBase) @@ -328,11 +327,11 @@ { return NULL; } bool -OFInit(unsigned int version, struct OFLibC *libC_, FILE **sF) +OFInit(unsigned int version, struct OFLibC *libC_) { #ifdef OF_AMIGAOS_M68K OF_M68K_ARG(struct ObjFWBase *, base, a6) #else register struct ObjFWBase *r12 __asm__("r12"); @@ -348,11 +347,10 @@ if (base->initialized) return true; memcpy(&libC, libC_, sizeof(libC)); - __sF = sF; #ifdef OF_AMIGAOS_M68K for (void *const *frame = _EH_FRAME_BEGINS__, **object = _EH_FRAME_OBJECTS__; *frame != NULL;) libC.__register_frame_info(*frame++, *object++); @@ -716,11 +714,11 @@ .rt_Revision = OBJFW_LIB_MINOR, .rt_Tags = NULL, #endif }; -#ifdef OF_MORPHOS +#if defined(OF_MORPHOS) __asm__ ( ".section .eh_frame, \"aw\"\n" ".globl __EH_FRAME_BEGIN__\n" ".type __EH_FRAME_BEGIN__, @object\n" "__EH_FRAME_BEGIN__:\n" @@ -727,7 +725,23 @@ ".section .ctors, \"aw\"\n" ".globl __CTOR_LIST__\n" ".type __CTOR_LIST__, @object\n" "__CTOR_LIST__:\n" ".section .text" +); +#elif defined(OF_AMIGAOS_M68K) +__asm__ ( + ".section .list___EH_FRAME_BEGINS__, \"aw\"\n" + ".globl __EH_FRAME_BEGIN__\n" + ".type __EH_FRAME_BEGIN__, @object\n" + "__EH_FRAME_BEGINS__:\n" + ".section .dlist___EH_FRAME_OBJECTS__, \"aw\"\n" + ".globl __EH_FRAME_OBJECTS__\n" + ".type __EH_FRAME_OBJECTS__, @object\n" + "__EH_FRAME_OBJECTS__:\n" + ".section .list___CTOR_LIST__, \"aw\"\n" + ".globl ___CTOR_LIST__\n" + ".type ___CTOR_LIST__, @object\n" + "___CTOR_LIST__:\n" + ".section .text" ); #endif Index: src/amiga-library.xml ================================================================== --- src/amiga-library.xml +++ src/amiga-library.xml @@ -2,11 +2,10 @@ amiga-library.h - OFObject.h Index: src/linklib/init.m ================================================================== --- src/linklib/init.m +++ src/linklib/init.m @@ -368,11 +368,11 @@ if ((ObjFWBase = OpenLibrary(OBJFW_AMIGA_LIB, OBJFW_LIB_MINOR)) == NULL) error("Failed to open " OBJFW_AMIGA_LIB " version %lu!", OBJFW_LIB_MINOR); - if (!OFInit(1, &libC, __sF)) + if (!OFInit(1, &libC)) error("Failed to initialize " OBJFW_AMIGA_LIB "!", 0); initialized = true; } Index: src/linklib/linklib.m ================================================================== --- src/linklib/linklib.m +++ src/linklib/linklib.m @@ -40,23 +40,23 @@ extern struct Library *ObjFWBase; #pragma GCC diagnostic ignored "-Warray-parameter" bool -OFInit(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF) +OFInit(unsigned int version, struct OFLibC *_Nonnull libc) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; - return ((bool (*)(unsigned int __asm__("d0"), struct OFLibC *_Nonnull __asm__("a0"), FILE *_Nonnull *_Nonnull __asm__("a1")))(((uintptr_t)ObjFWBase) - 30))(version, libc, sF); + return ((bool (*)(unsigned int __asm__("d0"), struct OFLibC *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 30))(version, libc); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); - return __extension__ ((bool (*)(unsigned int, struct OFLibC *_Nonnull, FILE *_Nonnull *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 28))(version, libc, sF); + return __extension__ ((bool (*)(unsigned int, struct OFLibC *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 28))(version, libc); #endif } void *_Nullable OFAllocMemory(size_t count, size_t size) Index: src/runtime/amiga-glue.h ================================================================== --- src/runtime/amiga-glue.h +++ src/runtime/amiga-glue.h @@ -26,11 +26,11 @@ #else # define PPC_PARAMS(...) (__VA_ARGS__) # define M68K_ARG(...) #endif -extern bool glue_objc_init PPC_PARAMS(unsigned int version, struct objc_libc *libc); +extern bool glue_objc_init PPC_PARAMS(unsigned int version, struct objc_libC *libC); extern void glue___objc_exec_class PPC_PARAMS(struct objc_module *_Nonnull module); extern IMP _Nonnull glue_objc_msg_lookup PPC_PARAMS(id _Nullable object, SEL _Nonnull selector); extern IMP _Nonnull glue_objc_msg_lookup_stret PPC_PARAMS(id _Nullable object, SEL _Nonnull selector); extern IMP _Nonnull glue_objc_msg_lookup_super PPC_PARAMS(struct objc_super *_Nonnull super, SEL _Nonnull selector); extern IMP _Nonnull glue_objc_msg_lookup_super_stret PPC_PARAMS(struct objc_super *_Nonnull super, SEL _Nonnull selector); Index: src/runtime/amiga-glue.m ================================================================== --- src/runtime/amiga-glue.m +++ src/runtime/amiga-glue.m @@ -29,16 +29,16 @@ " blr\n" ); #endif bool __saveds -glue_objc_init PPC_PARAMS(unsigned int version, struct objc_libc *libc) +glue_objc_init PPC_PARAMS(unsigned int version, struct objc_libC *libC) { M68K_ARG(unsigned int, version, d0) - M68K_ARG(struct objc_libc *, libc, a0) + M68K_ARG(struct objc_libC *, libC, a0) - return objc_init(version, libc); + return objc_init(version, libC); } void __saveds glue___objc_exec_class PPC_PARAMS(struct objc_module *_Nonnull module) { Index: src/runtime/amiga-library.m ================================================================== --- src/runtime/amiga-library.m +++ src/runtime/amiga-library.m @@ -50,10 +50,11 @@ #ifdef OF_AMIGAOS_M68K void __init_eh(void) { + /* Taken care of by objc_init() */ } #endif struct ObjFWRTBase { struct Library library; @@ -71,11 +72,11 @@ #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; -struct objc_libc libc; +struct objc_libC libC; #if defined(OF_AMIGAOS_M68K) __asm__ ( ".text\n" ".globl ___restore_a4\n" @@ -163,11 +164,11 @@ return dataDataRelocs; } static struct Library * -lib_init(struct ObjFWRTBase *base OBJC_M68K_REG(d0), +libInit(struct ObjFWRTBase *base OBJC_M68K_REG(d0), void *segList OBJC_M68K_REG(a0), struct ExecBase *sysBase OBJC_M68K_REG(a6)) { #if defined(OF_AMIGAOS_M68K) __asm__ __volatile__ ( "move.l a6, _SysBase" @@ -187,11 +188,11 @@ return &base->library; } struct Library *__saveds -lib_open(void) +libOpen(void) { OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) struct ObjFWRTBase *child; size_t dataSize, *dataDataRelocs; @@ -202,11 +203,11 @@ base->library.lib_OpenCnt++; base->library.lib_Flags &= ~LIBF_DELEXP; /* - * We cannot use malloc here, as that depends on the libc passed from + * We cannot use malloc here, as that depends on the libC passed from * the application. */ if ((child = AllocMem(base->library.lib_NegSize + base->library.lib_PosSize, MEMF_ANY)) == NULL) { base->library.lib_OpenCnt--; @@ -268,19 +269,19 @@ return segList; #undef SysBase } static void *__saveds -lib_expunge(void) +libExpunge(void) { OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) return expunge(base, SysBase); } static void *__saveds -lib_close(void) +libClose(void) { /* * SysBase becomes invalid during this function, so we store it in * sysBase and add a define to make the inlines use the right one. */ @@ -294,11 +295,11 @@ #ifdef OF_AMIGAOS_M68K if (base->initialized) for (void *const *frame = _EH_FRAME_BEGINS__; *frame != NULL;) - libc.__deregister_frame_info(*frame++); + libC.__deregister_frame_info(*frame++); #endif parent = base->parent; FreeMem(base->dataSeg - DATA_OFFSET, getDataSize()); @@ -315,17 +316,17 @@ return NULL; #undef SysBase } static void * -lib_null(void) +libNull(void) { return NULL; } bool -objc_init(unsigned int version, struct objc_libc *libc_) +objc_init(unsigned int version, struct objc_libC *libC_) { #ifdef OF_AMIGAOS_M68K OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) #else register struct ObjFWRTBase *r12 __asm__("r12"); @@ -340,16 +341,16 @@ return false; if (base->initialized) return true; - memcpy(&libc, libc_, sizeof(libc)); + memcpy(&libC, libC_, sizeof(libC)); #ifdef OF_AMIGAOS_M68K - for (void *const *frame = _EH_FRAME_OBJECTS__, + for (void *const *frame = _EH_FRAME_BEGINS__, **object = _EH_FRAME_OBJECTS__; *frame != NULL;) - libc.__register_frame_info(*frame++, *object++); + libC.__register_frame_info(*frame++, *object++); iter0 = &__CTOR_LIST__[1]; #elif defined(OF_MORPHOS) __asm__ ( "lis %0, __EH_FRAME_BEGIN__@ha\n\t" @@ -357,11 +358,11 @@ "lis %1, __CTOR_LIST__@ha\n\t" "la %1, __CTOR_LIST__@l(%1)\n\t" : "=r"(frame), "=r"(iter0) ); - libc.__register_frame(frame); + libC.__register_frame(frame); #endif for (iter = iter0; *iter != 0; iter++); while (iter > iter0) { @@ -375,110 +376,136 @@ } void * malloc(size_t size) { - return libc.malloc(size); + return libC.malloc(size); } void * calloc(size_t count, size_t size) { - return libc.calloc(count, size); + return libC.calloc(count, size); } void * realloc(void *ptr, size_t size) { - return libc.realloc(ptr, size); + return libC.realloc(ptr, size); } void free(void *ptr) { - libc.free(ptr); + libC.free(ptr); } #ifdef HAVE_SJLJ_EXCEPTIONS int _Unwind_SjLj_RaiseException(void *ex) { - return libc._Unwind_SjLj_RaiseException(ex); + return libC._Unwind_SjLj_RaiseException(ex); } #else int _Unwind_RaiseException(void *ex) { - return libc._Unwind_RaiseException(ex); + return libC._Unwind_RaiseException(ex); } #endif void _Unwind_DeleteException(void *ex) { - libc._Unwind_DeleteException(ex); + libC._Unwind_DeleteException(ex); } void * _Unwind_GetLanguageSpecificData(void *ctx) { - return libc._Unwind_GetLanguageSpecificData(ctx); + return libC._Unwind_GetLanguageSpecificData(ctx); } uintptr_t _Unwind_GetRegionStart(void *ctx) { - return libc._Unwind_GetRegionStart(ctx); + return libC._Unwind_GetRegionStart(ctx); } uintptr_t _Unwind_GetDataRelBase(void *ctx) { - return libc._Unwind_GetDataRelBase(ctx); + return libC._Unwind_GetDataRelBase(ctx); } uintptr_t _Unwind_GetTextRelBase(void *ctx) { - return libc._Unwind_GetTextRelBase(ctx); + return libC._Unwind_GetTextRelBase(ctx); } uintptr_t _Unwind_GetIP(void *ctx) { - return libc._Unwind_GetIP(ctx); + return libC._Unwind_GetIP(ctx); } uintptr_t _Unwind_GetGR(void *ctx, int gr) { - return libc._Unwind_GetGR(ctx, gr); + return libC._Unwind_GetGR(ctx, gr); } void _Unwind_SetIP(void *ctx, uintptr_t ip) { - libc._Unwind_SetIP(ctx, ip); + libC._Unwind_SetIP(ctx, ip); } void _Unwind_SetGR(void *ctx, int gr, uintptr_t value) { - libc._Unwind_SetGR(ctx, gr, value); + libC._Unwind_SetGR(ctx, gr, value); } #ifdef HAVE_SJLJ_EXCEPTIONS void _Unwind_SjLj_Resume(void *ex) { - libc._Unwind_SjLj_Resume(ex); + libC._Unwind_SjLj_Resume(ex); } #else void _Unwind_Resume(void *ex) { - libc._Unwind_Resume(ex); + libC._Unwind_Resume(ex); +} +#endif + +#ifdef OF_AMIGAOS_M68K +void +__register_frame_info(const void *begin, void *object) +{ + libC.__register_frame_info(begin, object); +} + +void +*__deregister_frame_info(const void *begin) +{ + return libC.__deregister_frame_info(begin); +} +#endif + +#ifdef OF_MORPHOS +void __register_frame(void *frame) +{ + libC.__register_frame(frame); +} + +void __deregister_frame(void *frame) +{ + libC.__deregister_frame(frame); } #endif #ifdef OF_AMIGAOS_M68K int @@ -496,24 +523,24 @@ int vsnprintf(char *restrict str, size_t size, const char *restrict fmt, va_list args) { - return libc.vsnprintf(str, size, fmt, args); + return libC.vsnprintf(str, size, fmt, args); } #endif int atexit(void (*function)(void)) { - return libc.atexit(function); + return libC.atexit(function); } void exit(int status) { - libc.exit(status); + libC.exit(status); OF_UNREACHABLE } #pragma GCC diagnostic push @@ -521,14 +548,14 @@ static CONST_APTR functionTable[] = { #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_BEGIN, (CONST_APTR)FUNCARRAY_32BIT_NATIVE, #endif - (CONST_APTR)lib_open, - (CONST_APTR)lib_close, - (CONST_APTR)lib_expunge, - (CONST_APTR)lib_null, + (CONST_APTR)libOpen, + (CONST_APTR)libClose, + (CONST_APTR)libExpunge, + (CONST_APTR)libNull, #ifdef OF_MORPHOS (CONST_APTR)-1, (CONST_APTR)FUNCARRAY_32BIT_SYSTEMV, #endif #include "amiga-funcarray.inc" @@ -549,11 +576,11 @@ struct ExecBase *execBase OBJC_M68K_REG(a6)); } init_table = { sizeof(struct ObjFWRTBase), functionTable, NULL, - lib_init + libInit }; struct Resident resident = { .rt_MatchWord = RTC_MATCHWORD, .rt_MatchTag = &resident, Index: src/runtime/amiga-library.xml ================================================================== --- src/runtime/amiga-library.xml +++ src/runtime/amiga-library.xml @@ -2,11 +2,11 @@ ObjFWRT.h private.h - + Index: src/runtime/linklib/init.m ================================================================== --- src/runtime/linklib/init.m +++ src/runtime/linklib/init.m @@ -63,11 +63,11 @@ #endif struct Library *ObjFWRTBase; void *__objc_class_name_Protocol; -extern bool objc_init(unsigned int version, struct objc_libc *libc); +extern bool objc_init(unsigned int version, struct objc_libC *libC); static void error(const char *string, ULONG arg) { struct Library *IntuitionBase = OpenLibrary("intuition.library", 0); @@ -91,11 +91,11 @@ static void __attribute__((__used__)) ctor(void) { static bool initialized = false; - struct objc_libc libc = { + struct objc_libC libC = { .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free, #ifdef HAVE_SJLJ_EXCEPTIONS @@ -139,11 +139,11 @@ if ((ObjFWRTBase = OpenLibrary(OBJFWRT_AMIGA_LIB, OBJFWRT_LIB_MINOR)) == NULL) error("Failed to open " OBJFWRT_AMIGA_LIB " version %lu!", OBJFWRT_LIB_MINOR); - if (!objc_init(1, &libc)) + if (!objc_init(1, &libC)) error("Failed to initialize " OBJFWRT_AMIGA_LIB "!", 0); initialized = true; } Index: src/runtime/linklib/linklib.m ================================================================== --- src/runtime/linklib/linklib.m +++ src/runtime/linklib/linklib.m @@ -23,23 +23,23 @@ extern struct Library *ObjFWRTBase; #pragma GCC diagnostic ignored "-Warray-parameter" bool -objc_init(unsigned int version, struct objc_libc *libc) +objc_init(unsigned int version, struct objc_libC *libC) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWRTBase; (void)a6; - return ((bool (*)(unsigned int __asm__("d0"), struct objc_libc *__asm__("a0")))(((uintptr_t)ObjFWRTBase) - 30))(version, libc); + return ((bool (*)(unsigned int __asm__("d0"), struct objc_libC *__asm__("a0")))(((uintptr_t)ObjFWRTBase) - 30))(version, libC); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWRTBase) : "r12" ); - return __extension__ ((bool (*)(unsigned int, struct objc_libc *))*(void **)(((uintptr_t)ObjFWRTBase) - 28))(version, libc); + return __extension__ ((bool (*)(unsigned int, struct objc_libC *))*(void **)(((uintptr_t)ObjFWRTBase) - 28))(version, libC); #endif } void __objc_exec_class(struct objc_module *_Nonnull module) Index: src/runtime/private.h ================================================================== --- src/runtime/private.h +++ src/runtime/private.h @@ -215,11 +215,11 @@ } *_Nonnull buckets[256]; }; #if defined(OBJC_COMPILING_AMIGA_LIBRARY) || \ defined(OBJC_COMPILING_AMIGA_LINKLIB) -struct objc_libc { +struct objc_libC { void *_Nullable (*_Nonnull malloc)(size_t); void *_Nullable (*_Nonnull calloc)(size_t, size_t); void *_Nullable (*_Nonnull realloc)(void *_Nullable, size_t); void (*_Nonnull free)(void *_Nullable); # ifdef HAVE_SJLJ_EXCEPTIONS @@ -268,11 +268,11 @@ # define OBJC_M68K_ARG(type, name, reg) \ register type reg_##name __asm__(#reg); \ type name = reg_##name; # endif -extern bool objc_init(unsigned int, struct objc_libc *); +extern bool objc_init(unsigned int, struct objc_libC *); # ifdef HAVE_SJLJ_EXCEPTIONS # define __gnu_objc_personality(version, actions, exClass, ex, ctx) \ __gnu_objc_personality_sj0(version, actions, *exClass, ex, ctx) # else # define __gnu_objc_personality(version, actions, exClass, ex, ctx) \