ObjFW  Check-in [c5c95f9fe2]

Overview
Comment:runtime: Let objc_init() take a version number
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c5c95f9fe27d4accd92da1fc3a9c5dce375b8118b1138c61d9d3c502e5ed62e6
User & Date: js on 2018-05-11 19:42:29
Other Links: manifest | tags
Context
2018-05-13
02:09
runtime: Port Amiga library to MorphOS check-in: 95e1ba8d63 user: js tags: trunk
2018-05-11
19:42
runtime: Let objc_init() take a version number check-in: c5c95f9fe2 user: js tags: trunk
17:59
runtime: Support to open Amiga lib multiple times check-in: 2376865a0f user: js tags: trunk
Changes

Modified src/runtime/ObjFW_RT.sfd from [eb7972f642] to [7b15336d97].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
==base _ObjFWRTBase
==basetype struct Library *
==libname objfw_rt.library
==bias 30
==public
* Functions for the linklib
void objc_init(struct objc_libc *libc, FILE *stdout, FILE *stdin)(a0,a1,a2)
* Used by the compiler - these need glue code
void glue___objc_exec_class(void *_Nonnull module)(a0)
IMP _Nonnull glue_objc_msg_lookup(id _Nullable obj, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_stret(id _Nullable obj, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_super(struct objc_super *_Nonnull super, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_super_stret(struct objc_super *_Nonnull super, SEL _Nonnull sel)(a0,a1)
Class _Nullable glue_objc_lookUpClass(const char *_Nonnull name)(a0)






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
==base _ObjFWRTBase
==basetype struct Library *
==libname objfw_rt.library
==bias 30
==public
* Functions for the linklib
bool objc_init(unsigned int version, struct objc_libc *libc, FILE *stdout, FILE *stdin)(d0,a0,a1,a2)
* Used by the compiler - these need glue code
void glue___objc_exec_class(void *_Nonnull module)(a0)
IMP _Nonnull glue_objc_msg_lookup(id _Nullable obj, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_stret(id _Nullable obj, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_super(struct objc_super *_Nonnull super, SEL _Nonnull sel)(a0,a1)
IMP _Nonnull glue_objc_msg_lookup_super_stret(struct objc_super *_Nonnull super, SEL _Nonnull sel)(a0,a1)
Class _Nullable glue_objc_lookUpClass(const char *_Nonnull name)(a0)

Modified src/runtime/amiga-library.m from [c1362b9b23] to [3a04605e77].

145
146
147
148
149
150
151


152
153
154
155
156
157
158
	child->library.lib_OpenCnt = 1;
	child->parent = base;

	data_size = (uintptr_t)&__data_size -
	    ((uintptr_t)&__a4_init - DATA_OFFSET);

	if ((child->data_seg = AllocMem(data_size, MEMF_ANY)) == NULL) {


		base->library.lib_OpenCnt--;
		return NULL;
	}

	memcpy(child->data_seg, base->data_seg - DATA_OFFSET, data_size);

	datadata_relocs = get_datadata_relocs();







>
>







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	child->library.lib_OpenCnt = 1;
	child->parent = base;

	data_size = (uintptr_t)&__data_size -
	    ((uintptr_t)&__a4_init - DATA_OFFSET);

	if ((child->data_seg = AllocMem(data_size, MEMF_ANY)) == NULL) {
		FreeMem((char *)child - child->library.lib_NegSize,
		    child->library.lib_NegSize + child->library.lib_PosSize);
		base->library.lib_OpenCnt--;
		return NULL;
	}

	memcpy(child->data_seg, base->data_seg - DATA_OFFSET, data_size);

	datadata_relocs = get_datadata_relocs();
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
OBJC_M68K_FUNC(lib_close, struct ObjFWRTBase *base OBJC_M68K_REG("a6"))
{
	OBJC_M68K_ARG(struct ObjFWRTBase *, base, REG_A6)

	if (base->parent != NULL) {
		struct ObjFWRTBase *parent;

		if (base->initialized &&
		    (size_t)_EH_FRAME_BEGINS__ == (size_t)_EH_FRAME_OBJECTS__)
			for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
				base->libc.__deregister_frame_info(
				    (&_EH_FRAME_BEGINS__)[i]);

		parent = base->parent;

		FreeMem(base->data_seg - DATA_OFFSET, (uintptr_t)&__data_size -







|
<







204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
OBJC_M68K_FUNC(lib_close, struct ObjFWRTBase *base OBJC_M68K_REG("a6"))
{
	OBJC_M68K_ARG(struct ObjFWRTBase *, base, REG_A6)

	if (base->parent != NULL) {
		struct ObjFWRTBase *parent;

		if (base->initialized)

			for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
				base->libc.__deregister_frame_info(
				    (&_EH_FRAME_BEGINS__)[i]);

		parent = base->parent;

		FreeMem(base->data_seg - DATA_OFFSET, (uintptr_t)&__data_size -
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

static void *
lib_null(void)
{
	return 0;
}

static void __saveds
objc_init(struct ObjFWRTBase *base OBJC_M68K_REG("a6"),
    struct objc_libc *libc OBJC_M68K_REG("a0"),
    FILE *stdout_ OBJC_M68K_REG("a1"), FILE *stderr_ OBJC_M68K_REG("a2"))
{

	uintptr_t *iter, *iter0;




	memcpy(&base->libc, libc, sizeof(base->libc));

	stdout = stdout_;
	stderr = stderr_;

	if ((size_t)_EH_FRAME_BEGINS__ == (size_t)_EH_FRAME_OBJECTS__)


		for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
			base->libc.__register_frame_info(
			    (&_EH_FRAME_BEGINS__)[i],
			    (&_EH_FRAME_OBJECTS__)[i]);

	iter0 = &__CTOR_LIST__[1];
	for (iter = iter0; *iter != 0; iter++);

	while (iter > iter0) {
		void (*ctor)(void) = (void (*)(void))*--iter;
		ctor();
	}

	base->initialized = true;


}

void *
malloc(size_t size)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");








|
|



>

>
>
>






|
>
>
|
|
<
|










>
>







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

static void *
lib_null(void)
{
	return 0;
}

static bool __saveds
objc_init(unsigned int version OBJC_M68K_REG("d0"),
    struct objc_libc *libc OBJC_M68K_REG("a0"),
    FILE *stdout_ OBJC_M68K_REG("a1"), FILE *stderr_ OBJC_M68K_REG("a2"))
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");
	uintptr_t *iter, *iter0;

	if (version > 1)
		return false;

	memcpy(&base->libc, libc, sizeof(base->libc));

	stdout = stdout_;
	stderr = stderr_;

	if ((size_t)_EH_FRAME_BEGINS__ != (size_t)_EH_FRAME_OBJECTS__)
		return false;

	for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
		base->libc.__register_frame_info((&_EH_FRAME_BEGINS__)[i],

		    (&_EH_FRAME_OBJECTS__)[i]);

	iter0 = &__CTOR_LIST__[1];
	for (iter = iter0; *iter != 0; iter++);

	while (iter > iter0) {
		void (*ctor)(void) = (void (*)(void))*--iter;
		ctor();
	}

	base->initialized = true;

	return true;
}

void *
malloc(size_t size)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
	ret = base->libc.vfprintf(stream, fmt, args);
	va_end(args);

	return ret;
}

int
fputs(const char *restrict s, FILE *restrict stream)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");

	return base->libc.fputs(s, stream);
}

void
exit(int status)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");








|



|







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
	ret = base->libc.vfprintf(stream, fmt, args);
	va_end(args);

	return ret;
}

int
fflush(FILE *restrict stream)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");

	return base->libc.fflush(stream);
}

void
exit(int status)
{
	register struct ObjFWRTBase *base OBJC_M68K_REG("a6");

Modified src/runtime/linklib/linklib.m from [6215304d3d] to [d9e16b337b].

57
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

	libc = (struct objc_libc){
		.malloc = malloc,
		.calloc = calloc,
		.realloc = realloc,
		.free = free,
		.vfprintf = vfprintf,
		.fputs = fputs,
		.exit = exit,
		.abort = abort,
		._Unwind_RaiseException = _Unwind_RaiseException,
		._Unwind_DeleteException = _Unwind_DeleteException,
		._Unwind_GetLanguageSpecificData =
		    _Unwind_GetLanguageSpecificData,
		._Unwind_GetRegionStart = _Unwind_GetRegionStart,
		._Unwind_GetDataRelBase = _Unwind_GetDataRelBase,
		._Unwind_GetTextRelBase = _Unwind_GetTextRelBase,
		._Unwind_GetIP = _Unwind_GetIP,
		._Unwind_GetGR = _Unwind_GetGR,
		._Unwind_SetIP = _Unwind_SetIP,
		._Unwind_SetGR = _Unwind_SetGR,
		._Unwind_Resume = _Unwind_Resume,
		.__register_frame_info = __register_frame_info,
		.__deregister_frame_info = __deregister_frame_info,
	};

	objc_init(&libc, stdout, stderr);




	initialized = true;
}

OF_DESTRUCTOR()
{
	CloseLibrary(ObjFWRTBase);







|

















>
|
>
>
>







57
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

	libc = (struct objc_libc){
		.malloc = malloc,
		.calloc = calloc,
		.realloc = realloc,
		.free = free,
		.vfprintf = vfprintf,
		.fflush = fflush,
		.exit = exit,
		.abort = abort,
		._Unwind_RaiseException = _Unwind_RaiseException,
		._Unwind_DeleteException = _Unwind_DeleteException,
		._Unwind_GetLanguageSpecificData =
		    _Unwind_GetLanguageSpecificData,
		._Unwind_GetRegionStart = _Unwind_GetRegionStart,
		._Unwind_GetDataRelBase = _Unwind_GetDataRelBase,
		._Unwind_GetTextRelBase = _Unwind_GetTextRelBase,
		._Unwind_GetIP = _Unwind_GetIP,
		._Unwind_GetGR = _Unwind_GetGR,
		._Unwind_SetIP = _Unwind_SetIP,
		._Unwind_SetGR = _Unwind_SetGR,
		._Unwind_Resume = _Unwind_Resume,
		.__register_frame_info = __register_frame_info,
		.__deregister_frame_info = __deregister_frame_info,
	};

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

	initialized = true;
}

OF_DESTRUCTOR()
{
	CloseLibrary(ObjFWRTBase);

Modified src/runtime/private.h from [5f7c093a7a] to [948a1c76b2].

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    defined(OBJC_COMPILING_AMIGA_LINKLIB)
extern struct objc_libc {
	void *(*malloc)(size_t);
	void *(*calloc)(size_t, size_t);
	void *(*realloc)(void *, size_t);
	void (*free)(void *);
	int (*vfprintf)(FILE *, const char *, va_list);
	int (*fputs)(const char *, FILE *);
	void (*exit)(int);
	void (*abort)(void);
	int (*_Unwind_RaiseException)(void *_Nonnull);
	void (*_Unwind_DeleteException)(void *_Nonnull);
	void *(*_Unwind_GetLanguageSpecificData)(void *_Nonnull);
	uintptr_t (*_Unwind_GetRegionStart)(void *_Nonnull);
	uintptr_t (*_Unwind_GetDataRelBase)(void *_Nonnull);







|







138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    defined(OBJC_COMPILING_AMIGA_LINKLIB)
extern struct objc_libc {
	void *(*malloc)(size_t);
	void *(*calloc)(size_t, size_t);
	void *(*realloc)(void *, size_t);
	void (*free)(void *);
	int (*vfprintf)(FILE *, const char *, va_list);
	int (*fflush)(FILE *);
	void (*exit)(int);
	void (*abort)(void);
	int (*_Unwind_RaiseException)(void *_Nonnull);
	void (*_Unwind_DeleteException)(void *_Nonnull);
	void *(*_Unwind_GetLanguageSpecificData)(void *_Nonnull);
	uintptr_t (*_Unwind_GetRegionStart)(void *_Nonnull);
	uintptr_t (*_Unwind_GetDataRelBase)(void *_Nonnull);
336
337
338
339
340
341
342

343
344
345
346
# endif
#endif

#define OBJC_ERROR(...)							\
	{								\
		fprintf(stderr, "[objc @ " __FILE__ ":%d] ", __LINE__);	\
		fprintf(stderr, __VA_ARGS__);				\

		fputs("\n", stderr);					\
		abort();						\
		OF_UNREACHABLE						\
	}







>
|



336
337
338
339
340
341
342
343
344
345
346
347
# endif
#endif

#define OBJC_ERROR(...)							\
	{								\
		fprintf(stderr, "[objc @ " __FILE__ ":%d] ", __LINE__);	\
		fprintf(stderr, __VA_ARGS__);				\
		fprintf(stderr, "\n");					\
		fflush(stderr);						\
		abort();						\
		OF_UNREACHABLE						\
	}