forked from adobe-flash/avmplus
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathavmshellMac.cpp
90 lines (70 loc) · 2.45 KB
/
avmshellMac.cpp
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
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
/* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//mac
#include "avmshell.h"
#include "PosixPartialPlatform.h"
#include <sys/signal.h>
#include <unistd.h>
#include <sys/resource.h>
namespace avmshell
{
class MacPlatform : public PosixPartialPlatform
{
public:
MacPlatform(void* stackbase) : stackbase(stackbase) {}
virtual ~MacPlatform() {}
virtual void setTimer(int seconds, AvmTimerCallback callback, void* callbackData);
virtual uintptr_t getMainThreadStackLimit();
private:
void* stackbase;
};
uintptr_t MacPlatform::getMainThreadStackLimit()
{
struct rlimit r;
size_t stackheight = avmshell::kStackSizeFallbackValue;
// https://bugzilla.mozilla.org/show_bug.cgi?id=504976: setting the height to kStackSizeFallbackValue
// is not ideal if the stack is meant to be unlimited but is an OK workaround for the time being.
if (getrlimit(RLIMIT_STACK, &r) == 0 && r.rlim_cur != RLIM_INFINITY)
stackheight = size_t(r.rlim_cur);
return uintptr_t(stackbase) - stackheight + avmshell::kStackMargin;
}
AvmTimerCallback pCallbackFunc = 0;
void* pCallbackData = 0;
void MacPlatform::setTimer(int seconds, AvmTimerCallback callback, void* callbackData)
{
extern void alarmProc(int);
pCallbackFunc = callback;
pCallbackData = callbackData;
signal(SIGALRM, alarmProc);
alarm(seconds);
}
void alarmProc(int /*signum*/)
{
pCallbackFunc(pCallbackData);
}
}
avmshell::MacPlatform* gPlatformHandle = NULL;
avmshell::Platform* avmshell::Platform::GetInstance()
{
AvmAssert(gPlatformHandle != NULL);
return gPlatformHandle;
}
int main(int argc, char *argv[])
{
#ifdef VMCFG_MACH_EXCEPTIONS
avmplus::GenericGuard::staticInit();
#endif
char* dummy;
avmshell::MacPlatform platformInstance(&dummy);
gPlatformHandle = &platformInstance;
int code = avmshell::Shell::run(argc, argv);
if (code == avmshell::OUT_OF_MEMORY)
write(1, "OUT OF MEMORY\n", 14);
#ifdef VMCFG_MACH_EXCEPTIONS
avmplus::GenericGuard::staticDestroy();
#endif
return code;
}