ObjFW  Diff

Differences From Artifact [e8efb8926f]:

To Artifact [5fd34ee158]:


19
20
21
22
23
24
25


26
27
28
29
30
31
32

33
34

35
36
37
38
39
40
41

#import "ObjFW_RT.h"
#import "private.h"
#import "macros.h"

#include <proto/exec.h>



#import "inline.h"

#include <stdio.h>
#include <stdlib.h>

#if defined(OF_AMIGAOS_M68K)
# include <stabs.h>

#elif defined(OF_MORPHOS)
# include <constructor.h>

#endif

#ifdef HAVE_SJLJ_EXCEPTIONS
extern int _Unwind_SjLj_RaiseException(void *);
#else
extern int _Unwind_RaiseException(void *);
#endif







>
>







>


>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#import "ObjFW_RT.h"
#import "private.h"
#import "macros.h"

#include <proto/exec.h>

struct ObjFWRTBase;

#import "inline.h"

#include <stdio.h>
#include <stdlib.h>

#if defined(OF_AMIGAOS_M68K)
# include <stabs.h>
# define SYM(name) __asm__("_" name)
#elif defined(OF_MORPHOS)
# include <constructor.h>
# define SYM(name) __asm__(name)
#endif

#ifdef HAVE_SJLJ_EXCEPTIONS
extern int _Unwind_SjLj_RaiseException(void *);
#else
extern int _Unwind_RaiseException(void *);
#endif
54
55
56
57
58
59
60








































































































61
62
63
64
65
66
67
extern void _Unwind_Resume(void *);
#endif
extern void __register_frame_info(const void *, void *);
extern void __deregister_frame_info(const void *);

struct Library *ObjFWRTBase;
void *__objc_class_name_Protocol;









































































































static void
ctor(void)
{
	static bool initialized = false;
	struct objc_libc libc = {
		.malloc = malloc,







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
extern void _Unwind_Resume(void *);
#endif
extern void __register_frame_info(const void *, void *);
extern void __deregister_frame_info(const void *);

struct Library *ObjFWRTBase;
void *__objc_class_name_Protocol;

void linklib___objc_exec_class(void *module) SYM("__objc_exec_class");
IMP linklib_objc_msg_lookup(id object, SEL selector) SYM("objc_msg_lookup");
IMP linklib_objc_msg_lookup_stret(id object, SEL selector)
    SYM("objc_msg_lookup_stret");
IMP linklib_objc_msg_lookup_super(struct objc_super *super, SEL selector)
    SYM("objc_msg_lookup_super");
IMP linklib_objc_msg_lookup_super_stret(struct objc_super *super, SEL selector)
    SYM("objc_msg_lookup_super_stret");
Class linklib_objc_lookUpClass(const char *name) SYM("objc_lookUpClass");
Class linklib_objc_getClass(const char *name) SYM("objc_getClass");
Class linklib_objc_getRequiredClass(const char *name)
    SYM("objc_getRequiredClass");
Class linklib_objc_lookup_class(const char *name) SYM("objc_lookup_class");
Class linklib_objc_get_class(const char *name) SYM("objc_get_class");
void linklib_objc_exception_throw(id object) SYM("objc_exception_throw");
int linklib_objc_sync_enter(id object) SYM("objc_sync_enter");
int linklib_objc_sync_exit(id object) SYM("objc_sync_exit");
id linklib_objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic)
    SYM("objc_getProperty");
void linklib_objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value,
    bool atomic, signed char copy) SYM("objc_setProperty");
void linklib_objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size,
    bool atomic, bool strong) SYM("objc_getPropertyStruct");
void linklib_objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size,
    bool atomic, bool strong) SYM("objc_setPropertyStruct");
void linklib_objc_enumerationMutation(id object)
    SYM("objc_enumerationMutation");
#ifdef HAVE_SJLJ_EXCEPTIONS
int linklib___gnu_objc_personality_sj0(int version, int actions,
    uint64_t exClass, void *ex, void *ctx) SYM("__gnu_objc_personality_sj0");
#else
int linklib___gnu_objc_personality_v0(int version, int actions,
    uint64_t exClass, void *ex, void *ctx) SYM("__gnu_objc_personality_v0");
#endif
id linklib_objc_retain(id object) SYM("objc_retain");
id linklib_objc_retainBlock(id block) SYM("objc_retainBlock");
id linklib_objc_retainAutorelease(id object) SYM("objc_retainAutorelease");
void linklib_objc_release(id object) SYM("objc_release");
id linklib_objc_autorelease(id object) SYM("objc_autorelease");
id linklib_objc_autoreleaseReturnValue(id object)
    SYM("objc_autoreleaseReturnValue");
id linklib_objc_retainAutoreleaseReturnValue(id object)
    SYM("objc_retainAutoreleaseReturnValue");
id linklib_objc_retainAutoreleasedReturnValue(id object)
    SYM("objc_retainAutoreleasedReturnValue");
id linklib_objc_storeStrong(id *object, id value) SYM("objc_storeStrong");
id linklib_objc_storeWeak(id *object, id value) SYM("objc_storeWeak");
id linklib_objc_loadWeakRetained(id *object) SYM("objc_loadWeakRetained");
id linklib_objc_initWeak(id *object, id value) SYM("objc_initWeak");
void linklib_objc_destroyWeak(id *object) SYM("objc_destroyWeak");
id linklib_objc_loadWeak(id *object) SYM("objc_loadWeak");
void linklib_objc_copyWeak(id *dest, id *src) SYM("objc_copyWeak");
void linklib_objc_moveWeak(id *dest, id *src) SYM("objc_moveWeak");
SEL linklib_sel_registerName(const char *name) SYM("sel_registerName");
const char *linklib_sel_getName(SEL selector) SYM("sel_getName");
bool linklib_sel_isEqual(SEL selector1, SEL selector2) SYM("sel_isEqual");
Class linklib_objc_allocateClassPair(Class superclass, const char *name,
    size_t extraBytes) SYM("objc_allocateClassPair");
void linklib_objc_registerClassPair(Class class) SYM("objc_registerClassPair");
unsigned int linklib_objc_getClassList(Class *buffer, unsigned int count)
    SYM("objc_getClassList");
Class *linklib_objc_copyClassList(unsigned int *length)
    SYM("objc_copyClassList");
bool linklib_class_isMetaClass(Class class) SYM("class_isMetaClass");
const char *linklib_class_getName(Class class) SYM("class_getName");
Class linklib_class_getSuperclass(Class class) SYM("class_getSuperclass");
unsigned long linklib_class_getInstanceSize(Class class)
    SYM("class_getInstanceSize");
bool linklib_class_respondsToSelector(Class class, SEL selector)
    SYM("class_respondsToSelector");
bool linklib_class_conformsToProtocol(Class class, Protocol *protocol)
    SYM("class_conformsToProtocol");
IMP linklib_class_getMethodImplementation(Class class, SEL selector)
    SYM("class_getMethodImplementation");
IMP linklib_class_getMethodImplementation_stret(Class class, SEL selector)
    SYM("class_getMethodImplementation_stret");
const char *linklib_class_getMethodTypeEncoding(Class class, SEL selector)
    SYM("class_getMethodTypeEncoding");
bool linklib_class_addMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding) SYM("class_addMethod");
IMP linklib_class_replaceMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding) SYM("class_replaceMethod");
Class linklib_object_getClass(id object) SYM("object_getClass");
Class linklib_object_setClass(id object, Class class) SYM("object_setClass");
const char *linklib_object_getClassName(id object)
    SYM("object_getClassName");
const char *linklib_protocol_getName(Protocol *protocol)
    SYM("protocol_getName");
bool linklib_protocol_isEqual(Protocol *protocol1, Protocol *protocol2)
    SYM("protocol_isEqual");
bool linklib_protocol_conformsToProtocol(Protocol *protocol1,
    Protocol *protocol2) SYM("protocol_conformsToProtocol");
void linklib_objc_exit(void) SYM("objc_exit");
objc_uncaught_exception_handler_t linklib_objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler_t handler)
    SYM("objc_setUncaughtExceptionHandler");
void linklib_objc_setForwardHandler(IMP forward, IMP stretForward)
    SYM("objc_setForwardHandler");
void linklib_objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler_t handler)
    SYM("objc_setEnumerationMutationHandler");
void linklib_objc_zero_weak_references(id value)
    SYM("objc_zero_weak_references");

static void
ctor(void)
{
	static bool initialized = false;
	struct objc_libc libc = {
		.malloc = malloc,
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

	if ((ObjFWRTBase = OpenLibrary(OBJFW_RT_AMIGA_LIB,
	    OBJFW_RT_LIB_MINOR)) == NULL) {
		fputs("Failed to open " OBJFW_RT_AMIGA_LIB "!\n", stderr);
		abort();
	}

	if (!objc_init_m68k(1, &libc, stdout, stderr)) {
		fputs("Failed to initialize " OBJFW_RT_AMIGA_LIB "!\n", stderr);
		abort();
	}

	initialized = true;
}








|







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

	if ((ObjFWRTBase = OpenLibrary(OBJFW_RT_AMIGA_LIB,
	    OBJFW_RT_LIB_MINOR)) == NULL) {
		fputs("Failed to open " OBJFW_RT_AMIGA_LIB "!\n", stderr);
		abort();
	}

	if (!objc_init(1, &libc, stdout, stderr)) {
		fputs("Failed to initialize " OBJFW_RT_AMIGA_LIB "!\n", stderr);
		abort();
	}

	initialized = true;
}

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383


384

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420



421
422
423
424
425
426

427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
DESTRUCTOR_P(ObjFWRT, 4000)
{
	dtor();
}
#endif

void
__objc_exec_class(void *module)
{
	/*
	 * The compiler generates constructors that call into this, so it is
	 * possible that we are not set up yet when we get called.
	 */
	ctor();

	__objc_exec_class_m68k(module);
}

IMP
objc_msg_lookup(id object, SEL selector)
{
	return objc_msg_lookup_m68k(object, selector);
}

IMP
objc_msg_lookup_stret(id object, SEL selector)
{
	return objc_msg_lookup_stret_m68k(object, selector);
}

IMP
objc_msg_lookup_super(struct objc_super *super, SEL selector)
{
	return objc_msg_lookup_super_m68k(super, selector);
}

IMP
objc_msg_lookup_super_stret(struct objc_super *super, SEL selector)
{
	return objc_msg_lookup_super_stret_m68k(super, selector);
}

Class
objc_lookUpClass(const char *name)
{
	return objc_lookUpClass_m68k(name);
}

Class
objc_getClass(const char *name)
{
	return objc_getClass_m68k(name);
}

Class
objc_getRequiredClass(const char *name)
{
	return objc_getRequiredClass_m68k(name);
}

Class
objc_lookup_class(const char *name)
{
	return objc_lookup_class_m68k(name);
}

Class
objc_get_class(const char *name)
{
	return objc_get_class_m68k(name);
}

void
objc_exception_throw(id object)
{
#ifdef OF_AMIGAOS_M68K
	/*
	 * This does not use the glue code to hack around a compiler bug.
	 *
	 * When using the generated inline stubs, the compiler does not emit
	 * any frame information, making the unwind fail. As unwind always
	 * starts from objc_exception_throw(), this means exceptions would
	 * never work. If, however, we're using a function pointer instead of
	 * the inline stub, the compiler does generate a frame and everything
	 * works fine.
	 */
	register void *a6 __asm__("a6") = ObjFWRTBase;
	uintptr_t throw = (((uintptr_t)ObjFWRTBase) - 0x60);
	((void (*)(id __asm__("a0")))throw)(object);
	(void)a6;
#else
	objc_exception_throw_m68k(object);
#endif

	OF_UNREACHABLE
}

int
objc_sync_enter(id object)
{
	return objc_sync_enter_m68k(object);
}

int
objc_sync_exit(id object)
{
	return objc_sync_exit_m68k(object);
}

id
objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic)
{
	return objc_getProperty_m68k(self, _cmd, offset, atomic);
}

void
objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, bool atomic,
    signed char copy)
{
	objc_setProperty_m68k(self, _cmd, offset, value, atomic, copy);
}

void
objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic,
    bool strong)
{
	objc_getPropertyStruct_m68k(dest, src, size, atomic, strong);
}

void
objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic,
    bool strong)
{
	objc_setPropertyStruct_m68k(dest, src, size, atomic, strong);
}

void
objc_enumerationMutation(id object)
{
#ifdef OF_AMIGAOS_M68K
	/*
	 * This does not use the glue code to hack around a compiler bug.
	 *
	 * When using the generated inline stubs, the compiler does not emit
	 * any frame information, making the unwind fail. As a result
	 * objc_enumerationMutation() might throw an exception that could never
	 * be caught. If, however, we're using a function pointer instead of
	 * the inline stub, the compiler does generate a frame and everything
	 * works fine.
	 */
	register void *a6 __asm__("a6") = ObjFWRTBase;
	uintptr_t enumerationMutation = (((uintptr_t)ObjFWRTBase) - 0x8A);
	((void (*)(id __asm__("a0")))enumerationMutation)(object);
	(void)a6;
#else
	objc_enumerationMutation_m68k(object);
#endif

	OF_UNREACHABLE
}

#ifdef HAVE_SJLJ_EXCEPTIONS
int
__gnu_objc_personality_sj0(int version, int actions, uint64_t exClass,
    void *ex, void *ctx)
{
	return __gnu_objc_personality_sj0_m68k(version, actions, &exClass,
	    ex, ctx);
}
#else
int
__gnu_objc_personality_v0(int version, int actions, uint64_t exClass,
    void *ex, void *ctx)
{
	return __gnu_objc_personality_v0_m68k(version, actions, &exClass,
	    ex, ctx);
}
#endif

id
objc_retain(id object)
{
	return objc_retain_m68k(object);
}

id
objc_retainBlock(id block)
{
	return objc_retainBlock_m68k(block);
}

id
objc_retainAutorelease(id object)
{
	return objc_retainAutorelease_m68k(object);
}

void
objc_release(id object)
{
	objc_release_m68k(object);
}

id
objc_autorelease(id object)
{
	return objc_autorelease_m68k(object);
}

id
objc_autoreleaseReturnValue(id object)
{
	return objc_autoreleaseReturnValue_m68k(object);
}

id
objc_retainAutoreleaseReturnValue(id object)
{
	return objc_retainAutoreleaseReturnValue_m68k(object);
}

id
objc_retainAutoreleasedReturnValue(id object)
{
	return objc_retainAutoreleasedReturnValue_m68k(object);
}

id
objc_storeStrong(id *object, id value)
{
	return objc_storeStrong_m68k(object, value);
}

id
objc_storeWeak(id *object, id value)



{
	return objc_storeWeak_m68k(object, value);
}

id
objc_loadWeakRetained(id *object)
{
	return objc_loadWeakRetained_m68k(object);
}

id
objc_initWeak(id *object, id value)
{
	return objc_initWeak_m68k(object, value);
}

void


objc_destroyWeak(id *object)

{
	objc_destroyWeak_m68k(object);
}

id
objc_loadWeak(id *object)
{
	return objc_loadWeak_m68k(object);
}

void
objc_copyWeak(id *dest, id *src)
{
	objc_copyWeak_m68k(dest, src);
}

void
objc_moveWeak(id *dest, id *src)



{
	objc_moveWeak_m68k(dest, src);
}

SEL
sel_registerName(const char *name)
{
	return sel_registerName_m68k(name);
}

const char *
sel_getName(SEL selector)
{
	return sel_getName_m68k(selector);
}

bool
sel_isEqual(SEL selector1, SEL selector2)



{
	return sel_isEqual_m68k(selector1, selector2);
}

Class
objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)

{
	return objc_allocateClassPair_m68k(superclass, name, extraBytes);
}

void
objc_registerClassPair(Class class)
{
	objc_registerClassPair_m68k(class);
}

unsigned int
objc_getClassList(Class *buffer, unsigned int count)
{
	return objc_getClassList_m68k(buffer, count);
}

Class *
objc_copyClassList(unsigned int *length)
{
	return objc_copyClassList_m68k(length);
}

bool
class_isMetaClass(Class class)
{
	return class_isMetaClass_m68k(class);
}

const char *
class_getName(Class class)
{
	return class_getName_m68k(class);
}

Class
class_getSuperclass(Class class)
{
	return class_getSuperclass_m68k(class);
}

unsigned long
class_getInstanceSize(Class class)
{
	return class_getInstanceSize_m68k(class);
}

bool
class_respondsToSelector(Class class, SEL selector)
{
	return class_respondsToSelector_m68k(class, selector);
}

bool
class_conformsToProtocol(Class class, Protocol *protocol)
{
	return class_conformsToProtocol_m68k(class, protocol);
}

IMP
class_getMethodImplementation(Class class, SEL selector)
{
	return class_getMethodImplementation_m68k(class, selector);
}

IMP
class_getMethodImplementation_stret(Class class, SEL selector)
{
	return class_getMethodImplementation_stret_m68k(class, selector);
}

const char *
class_getMethodTypeEncoding(Class class, SEL selector)
{
	return class_getMethodTypeEncoding_m68k(class, selector);
}

bool
class_addMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding)
{
	return class_addMethod_m68k(class, selector, implementation,
	    typeEncoding);
}

IMP
class_replaceMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding)
{
	return class_replaceMethod_m68k(class, selector, implementation,
	    typeEncoding);
}

Class
object_getClass(id object)
{
	return object_getClass_m68k(object);
}

Class
object_setClass(id object, Class class)
{
	return object_setClass_m68k(object, class);
}

const char *
object_getClassName(id object)
{
	return object_getClassName_m68k(object);
}

const char *
protocol_getName(Protocol *protocol)
{
	return protocol_getName_m68k(protocol);
}

bool
protocol_isEqual(Protocol *protocol1, Protocol *protocol2)
{
	return protocol_isEqual_m68k(protocol1, protocol2);
}

bool
protocol_conformsToProtocol(Protocol *protocol1, Protocol *protocol2)
{
	return protocol_conformsToProtocol_m68k(protocol1, protocol2);
}

void
objc_exit(void)
{
	objc_exit_m68k();
}

objc_uncaught_exception_handler_t

objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t handler)
{
	return objc_setUncaughtExceptionHandler_m68k(handler);
}

void
objc_setForwardHandler(IMP forward, IMP stretForward)
{
	objc_setForwardHandler_m68k(forward, stretForward);
}

void

objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler_t handler)
{
	objc_setEnumerationMutationHandler_m68k(handler);
}

void
objc_zero_weak_references(id value)
{
	objc_zero_weak_references_m68k(value);
}







|







|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

















|






|

|



|

|



|

|



|
|

|



|
|

|



|
|

|



|

















|







|


|
<



|


|
<




|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|
>
>
>
|
<
<
<

|

|



|

|



>
>
|
>
|
<
<
<

|

|



|

|



|
>
>
>
|
<
<
<

|

|



|

|



|
>
>
>
|
<
<
<

|
>

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|

|



|


|
<



|


|




|

|



|

|



|

|



|

|



|

|



|

|



|

|



>
|

|



|

|



>
|

|



|

|

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
DESTRUCTOR_P(ObjFWRT, 4000)
{
	dtor();
}
#endif

void
linklib___objc_exec_class(void *module)
{
	/*
	 * The compiler generates constructors that call into this, so it is
	 * possible that we are not set up yet when we get called.
	 */
	ctor();

	__objc_exec_class(module);
}

IMP
linklib_objc_msg_lookup(id object, SEL selector)
{
	return objc_msg_lookup(object, selector);
}

IMP
linklib_objc_msg_lookup_stret(id object, SEL selector)
{
	return objc_msg_lookup_stret(object, selector);
}

IMP
linklib_objc_msg_lookup_super(struct objc_super *super, SEL selector)
{
	return objc_msg_lookup_super(super, selector);
}

IMP
linklib_objc_msg_lookup_super_stret(struct objc_super *super, SEL selector)
{
	return objc_msg_lookup_super_stret(super, selector);
}

Class
linklib_objc_lookUpClass(const char *name)
{
	return objc_lookUpClass(name);
}

Class
linklib_objc_getClass(const char *name)
{
	return objc_getClass(name);
}

Class
linklib_objc_getRequiredClass(const char *name)
{
	return objc_getRequiredClass(name);
}

Class
linklib_objc_lookup_class(const char *name)
{
	return objc_lookup_class(name);
}

Class
linklib_objc_get_class(const char *name)
{
	return objc_get_class(name);
}

void
linklib_objc_exception_throw(id object)
{
#ifdef OF_AMIGAOS_M68K
	/*
	 * This does not use the glue code to hack around a compiler bug.
	 *
	 * When using the generated inline stubs, the compiler does not emit
	 * any frame information, making the unwind fail. As unwind always
	 * starts from objc_exception_throw(), this means exceptions would
	 * never work. If, however, we're using a function pointer instead of
	 * the inline stub, the compiler does generate a frame and everything
	 * works fine.
	 */
	register void *a6 __asm__("a6") = ObjFWRTBase;
	uintptr_t throw = (((uintptr_t)ObjFWRTBase) - 0x60);
	((void (*)(id __asm__("a0")))throw)(object);
	(void)a6;
#else
	objc_exception_throw(object);
#endif

	OF_UNREACHABLE
}

int
linklib_objc_sync_enter(id object)
{
	return objc_sync_enter(object);
}

int
linklib_objc_sync_exit(id object)
{
	return objc_sync_exit(object);
}

id
linklib_objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic)
{
	return objc_getProperty(self, _cmd, offset, atomic);
}

void
linklib_objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value,
    bool atomic, signed char copy)
{
	objc_setProperty(self, _cmd, offset, value, atomic, copy);
}

void
linklib_objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size,
    bool atomic, bool strong)
{
	objc_getPropertyStruct(dest, src, size, atomic, strong);
}

void
linklib_objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size,
    bool atomic, bool strong)
{
	objc_setPropertyStruct(dest, src, size, atomic, strong);
}

void
linklib_objc_enumerationMutation(id object)
{
#ifdef OF_AMIGAOS_M68K
	/*
	 * This does not use the glue code to hack around a compiler bug.
	 *
	 * When using the generated inline stubs, the compiler does not emit
	 * any frame information, making the unwind fail. As a result
	 * objc_enumerationMutation() might throw an exception that could never
	 * be caught. If, however, we're using a function pointer instead of
	 * the inline stub, the compiler does generate a frame and everything
	 * works fine.
	 */
	register void *a6 __asm__("a6") = ObjFWRTBase;
	uintptr_t enumerationMutation = (((uintptr_t)ObjFWRTBase) - 0x8A);
	((void (*)(id __asm__("a0")))enumerationMutation)(object);
	(void)a6;
#else
	objc_enumerationMutation(object);
#endif

	OF_UNREACHABLE
}

#ifdef HAVE_SJLJ_EXCEPTIONS
int
linklib___gnu_objc_personality_sj0(int version, int actions, uint64_t exClass,
    void *ex, void *ctx)
{
	return __gnu_objc_personality_sj0(version, actions, &exClass, ex, ctx);

}
#else
int
linklib___gnu_objc_personality_v0(int version, int actions, uint64_t exClass,
    void *ex, void *ctx)
{
	return __gnu_objc_personality_v0(version, actions, &exClass, ex, ctx);

}
#endif

id
linklib_objc_retain(id object)
{
	return objc_retain(object);
}

id
linklib_objc_retainBlock(id block)
{
	return objc_retainBlock(block);
}

id
linklib_objc_retainAutorelease(id object)
{
	return objc_retainAutorelease(object);
}

void
linklib_objc_release(id object)
{
	objc_release(object);
}

id
linklib_objc_autorelease(id object)
{
	return objc_autorelease(object);
}

id
linklib_objc_autoreleaseReturnValue(id object)
{
	return objc_autoreleaseReturnValue(object);
}

id
linklib_objc_retainAutoreleaseReturnValue(id object)
{
	return objc_retainAutoreleaseReturnValue(object);
}

id
linklib_objc_retainAutoreleasedReturnValue(id object)
{
	return objc_retainAutoreleasedReturnValue(object);
}

id
linklib_objc_storeStrong(id *object, id value)
{
	return objc_storeStrong(object, value);
}

id
linklib_objc_storeWeak(id *object, id value)
{
	return objc_storeWeak(object, value);
}




id
linklib_objc_loadWeakRetained(id *object)
{
	return objc_loadWeakRetained(object);
}

id
linklib_objc_initWeak(id *object, id value)
{
	return objc_initWeak(object, value);
}

void
linklib_objc_destroyWeak(id *object)
{
	objc_destroyWeak(object);
}




id
linklib_objc_loadWeak(id *object)
{
	return objc_loadWeak(object);
}

void
linklib_objc_copyWeak(id *dest, id *src)
{
	objc_copyWeak(dest, src);
}

void
linklib_objc_moveWeak(id *dest, id *src)
{
	objc_moveWeak(dest, src);
}




SEL
linklib_sel_registerName(const char *name)
{
	return sel_registerName(name);
}

const char *
linklib_sel_getName(SEL selector)
{
	return sel_getName(selector);
}

bool
linklib_sel_isEqual(SEL selector1, SEL selector2)
{
	return sel_isEqual(selector1, selector2);
}




Class
linklib_objc_allocateClassPair(Class superclass, const char *name,
    size_t extraBytes)
{
	return objc_allocateClassPair(superclass, name, extraBytes);
}

void
linklib_objc_registerClassPair(Class class)
{
	objc_registerClassPair(class);
}

unsigned int
linklib_objc_getClassList(Class *buffer, unsigned int count)
{
	return objc_getClassList(buffer, count);
}

Class *
linklib_objc_copyClassList(unsigned int *length)
{
	return objc_copyClassList(length);
}

bool
linklib_class_isMetaClass(Class class)
{
	return class_isMetaClass(class);
}

const char *
linklib_class_getName(Class class)
{
	return class_getName(class);
}

Class
linklib_class_getSuperclass(Class class)
{
	return class_getSuperclass(class);
}

unsigned long
linklib_class_getInstanceSize(Class class)
{
	return class_getInstanceSize(class);
}

bool
linklib_class_respondsToSelector(Class class, SEL selector)
{
	return class_respondsToSelector(class, selector);
}

bool
linklib_class_conformsToProtocol(Class class, Protocol *protocol)
{
	return class_conformsToProtocol(class, protocol);
}

IMP
linklib_class_getMethodImplementation(Class class, SEL selector)
{
	return class_getMethodImplementation(class, selector);
}

IMP
linklib_class_getMethodImplementation_stret(Class class, SEL selector)
{
	return class_getMethodImplementation_stret(class, selector);
}

const char *
linklib_class_getMethodTypeEncoding(Class class, SEL selector)
{
	return class_getMethodTypeEncoding(class, selector);
}

bool
linklib_class_addMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding)
{
	return class_addMethod(class, selector, implementation, typeEncoding);

}

IMP
linklib_class_replaceMethod(Class class, SEL selector, IMP implementation,
    const char *typeEncoding)
{
	return class_replaceMethod(class, selector, implementation,
	    typeEncoding);
}

Class
linklib_object_getClass(id object)
{
	return object_getClass(object);
}

Class
linklib_object_setClass(id object, Class class)
{
	return object_setClass(object, class);
}

const char *
linklib_object_getClassName(id object)
{
	return object_getClassName(object);
}

const char *
linklib_protocol_getName(Protocol *protocol)
{
	return protocol_getName(protocol);
}

bool
linklib_protocol_isEqual(Protocol *protocol1, Protocol *protocol2)
{
	return protocol_isEqual(protocol1, protocol2);
}

bool
linklib_protocol_conformsToProtocol(Protocol *protocol1, Protocol *protocol2)
{
	return protocol_conformsToProtocol(protocol1, protocol2);
}

void
linklib_objc_exit(void)
{
	objc_exit();
}

objc_uncaught_exception_handler_t
linklib_objc_setUncaughtExceptionHandler(
    objc_uncaught_exception_handler_t handler)
{
	return objc_setUncaughtExceptionHandler(handler);
}

void
linklib_objc_setForwardHandler(IMP forward, IMP stretForward)
{
	objc_setForwardHandler(forward, stretForward);
}

void
linklib_objc_setEnumerationMutationHandler(
    objc_enumeration_mutation_handler_t handler)
{
	objc_setEnumerationMutationHandler(handler);
}

void
linklib_objc_zero_weak_references(id value)
{
	objc_zero_weak_references(value);
}