Index: src/amiga-library.h ================================================================== --- src/amiga-library.h +++ src/amiga-library.h @@ -17,24 +17,51 @@ #import "macros.h" #if defined(OF_COMPILING_AMIGA_LIBRARY) || defined(OF_COMPILING_AMIGA_LINKLIB) struct of_libc { + /* + * Needed by the runtime. Some of them are also used by ObjFW, but we + * need all of them to pass them along to the runtime. + */ 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); int (*_Nonnull vfprintf)(FILE *_Nonnull restrict, - const char *restrict _Nonnull, va_list); - int (*_Nonnull vsnprintf)(const char *_Nonnull restrict, size_t, const char *_Nonnull restrict, va_list); - void (*_Nonnull exit)(int); + int (*_Nonnull fflush)(FILE *_Nonnull); void (*_Nonnull abort)(void); - char *_Nullable (*_Nonnull setlocale)(int, const char *_Nullable); +# ifdef HAVE_SJLJ_EXCEPTIONS + int (*_Nonnull _Unwind_SjLj_RaiseException)(void *_Nonnull); +# else + int (*_Nonnull _Unwind_RaiseException)(void *_Nonnull); +# endif + void (*_Nonnull _Unwind_DeleteException)(void *_Nonnull); + void *_Nullable (*_Nonnull _Unwind_GetLanguageSpecificData)( + void *_Nonnull); + uintptr_t (*_Nonnull _Unwind_GetRegionStart)(void *_Nonnull); + uintptr_t (*_Nonnull _Unwind_GetDataRelBase)(void *_Nonnull); + uintptr_t (*_Nonnull _Unwind_GetTextRelBase)(void *_Nonnull); + uintptr_t (*_Nonnull _Unwind_GetIP)(void *_Nonnull); + uintptr_t (*_Nonnull _Unwind_GetGR)(void *_Nonnull, int); + void (*_Nonnull _Unwind_SetIP)(void *_Nonnull, uintptr_t); + void (*_Nonnull _Unwind_SetGR)(void *_Nonnull, int, uintptr_t); +# ifdef HAVE_SJLJ_EXCEPTIONS + void (*_Nonnull _Unwind_SjLj_Resume)(void *_Nonnull); +# else + void (*_Nonnull _Unwind_Resume)(void *_Nonnull); +# endif void (*_Nonnull __register_frame_info)(const void *_Nonnull, void *_Nonnull); void *_Nullable (*_Nonnull __deregister_frame_info)( const void *_Nonnull); + + /* Needed only by ObjFW. */ + int (*_Nonnull vsnprintf)(const char *_Nonnull restrict, size_t, + const char *_Nonnull restrict, va_list); + void (*_Nonnull exit)(int); + char *_Nullable (*_Nonnull setlocale)(int, const char *_Nullable); }; extern bool of_init(unsigned int version, struct of_libc *libc_, FILE *stderr_); #endif Index: src/amiga-library.m ================================================================== --- src/amiga-library.m +++ src/amiga-library.m @@ -61,10 +61,18 @@ extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif extern bool glue_of_init(void); + +#ifdef OF_AMIGAOS_M68K +void +__init_eh(void) +{ + /* Taken care of by of_init() */ +} +#endif #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; @@ -274,11 +282,20 @@ lib_close(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) if (base->parent != NULL) { - struct ObjFWBase *parent = base->parent; + struct ObjFWBase *parent; + +#ifdef OF_AMIGAOS_M68K + if (base->initialized) + for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++) + libc.__deregister_frame_info( + (&_EH_FRAME_BEGINS__)[i]); +#endif + + parent = base->parent; FreeMem(base->dataSeg - DATA_OFFSET, getDataSize()); FreeMem((char *)base - base->library.lib_NegSize, base->library.lib_NegSize + base->library.lib_PosSize); @@ -382,10 +399,106 @@ va_end(args); return ret; } +int +fflush(FILE *restrict stream) +{ + return libc.fflush(stream); +} + +void +abort(void) +{ + libc.abort(); + + OF_UNREACHABLE +} + +#ifdef HAVE_SJLJ_EXCEPTIONS +int +_Unwind_SjLj_RaiseException(void *ex) +{ + return libc._Unwind_SjLj_RaiseException(ex); +} +#else +int +_Unwind_RaiseException(void *ex) +{ + return libc._Unwind_RaiseException(ex); +} +#endif + +void +_Unwind_DeleteException(void *ex) +{ + libc._Unwind_DeleteException(ex); +} + +void * +_Unwind_GetLanguageSpecificData(void *ctx) +{ + return libc._Unwind_GetLanguageSpecificData(ctx); +} + +uintptr_t +_Unwind_GetRegionStart(void *ctx) +{ + return libc._Unwind_GetRegionStart(ctx); +} + +uintptr_t +_Unwind_GetDataRelBase(void *ctx) +{ + return libc._Unwind_GetDataRelBase(ctx); +} + +uintptr_t +_Unwind_GetTextRelBase(void *ctx) +{ + return libc._Unwind_GetTextRelBase(ctx); +} + +uintptr_t +_Unwind_GetIP(void *ctx) +{ + return libc._Unwind_GetIP(ctx); +} + +uintptr_t +_Unwind_GetGR(void *ctx, int gr) +{ + return libc._Unwind_GetGR(ctx, gr); +} + +void +_Unwind_SetIP(void *ctx, uintptr_t ip) +{ + libc._Unwind_SetIP(ctx, ip); +} + +void +_Unwind_SetGR(void *ctx, int gr, uintptr_t value) +{ + libc._Unwind_SetGR(ctx, gr, value); +} + +#ifdef HAVE_SJLJ_EXCEPTIONS +void +_Unwind_SjLj_Resume(void *ex) +{ + libc._Unwind_SjLj_Resume(ex); +} +#else +void +_Unwind_Resume(void *ex) +{ + libc._Unwind_Resume(ex); +} +#endif + int vsnprintf(char *restrict str, size_t size, const char *restrict fmt, va_list args) { return libc.vsnprintf(str, size, fmt, args); @@ -394,18 +507,10 @@ void exit(int status) { libc.exit(status); - OF_UNREACHABLE -} - -void -abort(void) -{ - libc.abort(); - OF_UNREACHABLE } char * setlocale(int category, const char *locale)