1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
46
47
48
49
50
51
52
53
54
55
56
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
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
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Jonathan Schleifer <js@heap.zone>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "ObjFW-RT.h"
#import "macros.h"
#define BOOL EXEC_BOOL
#include <dos/dos.h>
#include <emul/emulregs.h>
#include <exec/execbase.h>
#include <exec/nodes.h>
#include <exec/resident.h>
#include <exec/types.h>
#include <proto/exec.h>
#undef BOOL
struct ObjFWRTBase {
struct Library library;
BPTR seg_list;
};
/* Forward declarations for all functions in the func_table */
static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
struct ExecBase *exec_base);
static struct Library *lib_open(void);
static BPTR lib_close(void);
static BPTR lib_expunge(void);
static void lib_null(void);
void objc_set_exit(void OF_NO_RETURN_FUNC (*exit_fn_)(int status));
static ULONG func_table[] = {
FUNCARRAY_BEGIN,
FUNCARRAY_32BIT_NATIVE,
(ULONG)lib_open,
(ULONG)lib_close,
(ULONG)lib_expunge,
(ULONG)lib_null,
-1,
FUNCARRAY_32BIT_SYSTEMV,
/* Functions for the glue code */
(ULONG)objc_set_exit,
/* Used by the compiler - these need glue code */
(ULONG)__objc_exec_class,
(ULONG)objc_msg_lookup,
(ULONG)objc_msg_lookup_stret,
(ULONG)objc_msg_lookup_super,
(ULONG)objc_msg_lookup_super_stret,
(ULONG)objc_lookUpClass,
(ULONG)objc_getClass,
(ULONG)objc_getRequiredClass,
(ULONG)objc_exception_throw,
(ULONG)objc_sync_enter,
(ULONG)objc_sync_exit,
(ULONG)objc_getProperty,
(ULONG)objc_setProperty,
(ULONG)objc_getPropertyStruct,
(ULONG)objc_setPropertyStruct,
(ULONG)objc_enumerationMutation,
/* Functions declared in ObjFW-RT.h */
(ULONG)sel_registerName,
(ULONG)sel_getName,
(ULONG)sel_isEqual,
(ULONG)objc_allocateClassPair,
(ULONG)objc_registerClassPair,
(ULONG)objc_getClassList,
(ULONG)objc_copyClassList,
(ULONG)class_isMetaClass,
(ULONG)class_getName,
(ULONG)class_getSuperclass,
(ULONG)class_getInstanceSize,
(ULONG)class_respondsToSelector,
(ULONG)class_conformsToProtocol,
(ULONG)class_getMethodImplementation,
(ULONG)class_getMethodImplementation_stret,
(ULONG)class_getMethodTypeEncoding,
(ULONG)class_addMethod,
(ULONG)class_replaceMethod,
(ULONG)object_getClass,
(ULONG)object_setClass,
(ULONG)object_getClassName,
(ULONG)protocol_getName,
(ULONG)protocol_isEqual,
(ULONG)protocol_conformsToProtocol,
(ULONG)objc_exit,
(ULONG)objc_setUncaughtExceptionHandler,
(ULONG)objc_setForwardHandler,
(ULONG)objc_setEnumerationMutationHandler,
(ULONG)objc_zero_weak_references,
-1,
FUNCARRAY_END
};
static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
struct ExecBase *exec_base);
static struct {
LONG struct_size;
ULONG *func_table;
void *data_table;
struct Library *(*init_func)(struct ObjFWRTBase *base, BPTR seg_list,
struct ExecBase *exec_base);
} init_table = {
.struct_size = sizeof(struct ObjFWRTBase),
func_table,
NULL,
lib_init
};
static struct Resident resident = {
.rt_MatchWord = RTC_MATCHWORD,
.rt_MatchTag = &resident,
.rt_EndSkip = &resident + 1,
.rt_Flags = RTF_AUTOINIT | RTF_PPC,
.rt_Version = OBJFW_RT_LIB_MAJOR * 10 + OBJFW_RT_LIB_MINOR,
.rt_Type = NT_LIBRARY,
.rt_Pri = 0,
.rt_Name = (char *)"objfw-rt.library",
.rt_IdString = (char *)"ObjFW-RT " PACKAGE_VERSION
" \xA9 2008-2017 Jonathan Schleifer",
.rt_Init = &init_table
};
/* Magic required to make this a MorphOS binary */
const ULONG __abox__ = 1;
/* Global variables needed by libnix */
int ThisRequiresConstructorHandling;
struct ExecBase *SysBase;
void *libnix_mempool;
/* Functions passed in from the glue linklib */
static void OF_NO_RETURN_FUNC (*exit_fn)(int status);
void OF_NO_RETURN_FUNC
exit(int status)
{
exit_fn(status);
}
void
objc_set_exit(void OF_NO_RETURN_FUNC (*exit_fn_)(int status))
{
exit_fn = exit_fn_;
}
/* Standard library functions */
static struct Library *lib_init(struct ObjFWRTBase *base, BPTR seg_list,
struct ExecBase *exec_base)
{
SysBase = exec_base;
base->seg_list = seg_list;
return &base->library;
}
static struct Library *
lib_open(void)
{
struct ObjFWRTBase *base = (struct ObjFWRTBase *)REG_A6;
base->library.lib_OpenCnt++;
base->library.lib_Flags &= ~LIBF_DELEXP;
return &base->library;
}
static BPTR
expunge(struct ObjFWRTBase *base)
{
/* Still in use - set delayed expunge flag and refuse to expunge */
if (base->library.lib_OpenCnt > 0) {
base->library.lib_Flags |= LIBF_DELEXP;
return 0;
}
Remove(&base->library.lib_Node);
FreeMem((char *)base - base->library.lib_NegSize,
base->library.lib_NegSize + base->library.lib_PosSize);
return base->seg_list;
}
static BPTR
lib_close(void)
{
struct ObjFWRTBase *base = (struct ObjFWRTBase *)REG_A6;
/* Not used anymore and delayed expunge flag set -> expunge */
if (--base->library.lib_OpenCnt == 0 &&
(base->library.lib_Flags & LIBF_DELEXP))
return expunge(base);
return 0;
}
static BPTR
lib_expunge(void)
{
return expunge((struct ObjFWRTBase *)REG_A6);
}
static void
lib_null(void)
{
}
|