-
Notifications
You must be signed in to change notification settings - Fork 71
/
sameThread.c
64 lines (45 loc) · 1.61 KB
/
sameThread.c
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
#include "sigjmp_support.h"
#include "pThreadedFFI.h"
#include "vmCallback.h"
#include "pharovm/macros.h"
void sameThreadCallbackEnter(struct _Runner* runner, struct _CallbackInvocation* callback);
void sameThreadCallbackExit(struct _Runner* runner, struct _CallbackInvocation* callback);
void sameThreadPrepareCallback(struct _Runner* runner, struct _CallbackInvocation* callback);
static Runner sameThreadRunner = {
sameThreadCallbackEnter,
sameThreadCallbackExit,
sameThreadPrepareCallback,
NULL
};
Primitive(primitiveGetSameThreadRunnerAddress) {
sqInt externalAddress;
externalAddress = instantiateClassindexableSize(classExternalAddress(), sizeof(void*));
checkFailed();
writeAddress(externalAddress, &sameThreadRunner);
checkFailed();
primitiveEndReturn(externalAddress);
}
void sameThreadCallbackEnter(struct _Runner* runner, struct _CallbackInvocation* callback){
VMCallbackContext *vmcc;
vmcc = malloc(sizeof(VMCallbackContext));
callback->payload = vmcc;
if ((!sigsetjmp(vmcc->trampoline, 0))) {
//Used to mark that is a fake callback!
vmcc->thunkp = NULL;
vmcc->stackp = NULL;
vmcc->intregargsp = NULL;
vmcc->floatregargsp = NULL;
ptEnterInterpreterFromCallback(vmcc);
fprintf(stderr,"Warning; callback failed to invoke\n");
return;
}
free(vmcc);
}
void sameThreadCallbackExit(struct _Runner* runner, struct _CallbackInvocation* callback){
VMCallbackContext *vmcc;
vmcc = (VMCallbackContext*)callback->payload;
ptExitInterpreterToCallback(vmcc);
}
void sameThreadPrepareCallback(struct _Runner* runner, struct _CallbackInvocation* callback){
// I do not do nothing
}