ObjFW  Check-in [0d6873e122]

Overview
Comment:runtime: Add initial morphos-library.m

This allows opening and closing the library, but does not do all the
initialization yet and does not export any functions.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0d6873e12208f137967ac9e024c48eab63784ba0600a48b099aa6f436d66e7aa
User & Date: js on 2017-06-13 23:08:34
Other Links: manifest | tags
Context
2017-06-21
20:20
OFHTTPServer: Include the / in the URL path check-in: 2b6fb5530e user: js tags: trunk
2017-06-13
23:08
runtime: Add initial morphos-library.m check-in: 0d6873e122 user: js tags: trunk
2017-06-12
22:29
OFWriteFailedException: Add -[bytesWritten] check-in: 2ae01218ef user: js tags: trunk
Changes

Added src/runtime/morphos-library.m version [ba7732f086].





































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * 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 "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,
	(ULONG)objc_set_exit,
	-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)
{
	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
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 lib_expunge();

	return 0;
}

static BPTR
lib_expunge(void)
{
	struct ObjFWRTBase *base = (struct ObjFWRTBase *)REG_A6;

	/* 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;
	}

	return base->seg_list;
}

static void
lib_null(void)
{
}