blob: 3fd07a1f905b474563b1a727b8d3d8fd0654f157 (
plain) (
blame)
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
|
#include <config.h>
#include <aplwc.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "defs.h"
#include "fns.h"
#include "types.h"
#include "nls.h"
static void *
default_alloc(void *aux, size_t size)
{
return malloc(size);
}
static void
default_free(void *aux, void *p)
{
free(p);
}
static void
default_debug(void *aux, char *msg)
{
printf("DEBUG: %s\n", msg);
}
static void
default_fatal(void *aux, char *msg)
{
printf("FATAL: %s\n", msg);
exit(EXIT_FAILURE);
}
void
aplwc_boot(void)
{
init_nls();
}
void
aplwc_init_fns(APLWCFunctions *fns)
{
fns->alloc = default_alloc;
fns->free = default_free;
fns->debug = default_debug;
fns->fatal = default_fatal;
}
APLWC *
aplwc_init(APLWCFunctions *fns, void *aux)
{
size_t size = sizeof(APLWC) + (APLWC_ALIGNMENT - 1) + WS_START_SIZE + (WS_ALIGNMENT - 1);
intptr_t base = (intptr_t)fns->alloc(aux, size);
intptr_t aligned;
aligned = base;
if((aligned % APLWC_ALIGNMENT) != 0)
aligned += APLWC_ALIGNMENT - (aligned % APLWC_ALIGNMENT);
APLWC *aplwc = (APLWC *)aligned;
aplwc->base = (void*)base;
aplwc->fns = fns;
aplwc->aux = aux;
aligned += sizeof(APLWC);
if((aligned % WS_ALIGNMENT) != 0)
aligned += WS_ALIGNMENT - (aligned % WS_ALIGNMENT);
aplwc->ws = (void*)aligned;
aplwc->ws_size = size - (aligned - base);
DEBUG(_("initialized"));
return aplwc;
}
void
aplwc_exit(APLWC *aplwc)
{
DEBUG(_("exiting"));
CALLFN(free, aplwc->base);
}
|