Add checks to prevent mixing incompatible ABI versions.

main
David Chisnall 8 years ago
parent b81df02b91
commit d11a0311e0

@ -11,6 +11,7 @@
#include <gc/gc.h> #include <gc/gc.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <string.h>
/** /**
* Runtime lock. This is exposed in * Runtime lock. This is exposed in
@ -166,6 +167,12 @@ struct objc_init
// end: objc_init // end: objc_init
#include <dlfcn.h> #include <dlfcn.h>
static enum {
LegacyABI,
NewABI,
UnknownABI
} CurrentABI = UnknownABI;
void registerProtocol(Protocol *proto); void registerProtocol(Protocol *proto);
void __objc_load(struct objc_init *init) void __objc_load(struct objc_init *init)
@ -183,6 +190,19 @@ void __objc_load(struct objc_init *init)
} }
#endif #endif
LOCK_RUNTIME_FOR_SCOPE(); LOCK_RUNTIME_FOR_SCOPE();
BOOL isFirstLoad = NO;
switch (CurrentABI)
{
case LegacyABI:
fprintf(stderr, "Version 2 Objective-C ABI may not be mixed with earlier versions.\n");
abort();
case UnknownABI:
isFirstLoad = YES;
CurrentABI = NewABI;
break;
case NewABI:
break;
}
assert(init->version == 0); assert(init->version == 0);
assert((((uintptr_t)init->sel_end-(uintptr_t)init->sel_begin) % sizeof(*init->sel_begin)) == 0); assert((((uintptr_t)init->sel_end-(uintptr_t)init->sel_begin) % sizeof(*init->sel_begin)) == 0);
assert((((uintptr_t)init->cls_end-(uintptr_t)init->cls_begin) % sizeof(*init->cls_begin)) == 0); assert((((uintptr_t)init->cls_end-(uintptr_t)init->cls_begin) % sizeof(*init->cls_begin)) == 0);
@ -211,6 +231,11 @@ void __objc_load(struct objc_init *init)
{ {
continue; continue;
} }
// As a special case, allow using legacy ABI code with a new runtime.
if (isFirstLoad && (strcmp((*cls)->name, "Protocol")))
{
CurrentABI = UnknownABI;
}
objc_load_class(*cls); objc_load_class(*cls);
} }
#if 0 #if 0
@ -260,6 +285,18 @@ void __objc_exec_class(struct objc_module_abi_8 *module)
{ {
init_runtime(); init_runtime();
switch (CurrentABI)
{
case UnknownABI:
CurrentABI = LegacyABI;
break;
case LegacyABI:
break;
case NewABI:
fprintf(stderr, "Version 2 Objective-C ABI may not be mixed with earlier versions.\n");
abort();
}
// Check that this module uses an ABI version that we recognise. // Check that this module uses an ABI version that we recognise.
// In future, we should pass the ABI version to the class / category load // In future, we should pass the ABI version to the class / category load
// functions so that we can change various structures more easily. // functions so that we can change various structures more easily.

Loading…
Cancel
Save