1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version 1.1 (the
7 * "License"); you may not use this file except in compliance with the License. You may obtain
8 * a copy of the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
11 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
12 * language governing rights and limitations under the License.
14 * The Original Code is [Open Source Virtual Machine.]
16 * The Initial Developer of the Original Code is Adobe System Incorporated. Portions created
17 * by the Initial Developer are Copyright (C)[ 2004-2006 ] Adobe Systems Incorporated. All Rights
20 * Contributor(s): Adobe AS3 Team
21 * Andreas Gal <gal@mozilla.com>
23 * Alternatively, the contents of this file may be used under the terms of either the GNU
24 * General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public
25 * License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the
26 * LGPL are applicable instead of those above. If you wish to allow use of your version of this
27 * file only under the terms of either the GPL or the LGPL, and not to allow others to use your
28 * version of this file under the terms of the MPL, indicate your decision by deleting provisions
29 * above and replace them with the notice and other provisions required by the GPL or the
30 * LGPL. If you do not delete the provisions above, a recipient may use your version of this file
31 * under the terms of any one of the MPL, the GPL or the LGPL.
33 ***** END LICENSE BLOCK ***** */
39 typedef caddr_t maddr_ptr;
41 typedef void *maddr_ptr;
44 using namespace avmplus;
46 nanojit::Config AvmCore::config;
49 avmplus::AvmLog(char const *msg, ...) {
52 VMPI_vfprintf(stderr, msg, ap);
58 void AvmAssertFail(const char* /* msg */) {
63 #elif defined(__APPLE__)
65 * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are
68 *((int *) NULL) = 0; /* To continue from here in GDB: "return" then "continue". */
69 raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */
71 raise(SIGABRT); /* To continue from here in GDB: "signal 0". */
79 // Due to the per-process heap slots on Windows Mobile, we can often run in to OOM
80 // situations. jemalloc has worked around this problem, and so we use it here.
81 // Using posix_memalign (or other malloc)functions) here only works because the OS
82 // and hardware doesn't check for the execute bit being set.
85 #error MOZ_MEMORY required for building on WINCE
89 nanojit::CodeAlloc::allocCodeChunk(size_t nbytes) {
91 posix_memalign(&buffer, 4096, nbytes);
92 VMPI_setPageProtection(buffer, nbytes, true /* exec */, true /* write */);
97 nanojit::CodeAlloc::freeCodeChunk(void *p, size_t nbytes) {
98 VMPI_setPageProtection(p, nbytes, false /* exec */, true /* write */);
105 nanojit::CodeAlloc::allocCodeChunk(size_t nbytes) {
106 return VirtualAlloc(NULL,
108 MEM_COMMIT | MEM_RESERVE,
109 PAGE_EXECUTE_READWRITE);
113 nanojit::CodeAlloc::freeCodeChunk(void *p, size_t) {
114 VirtualFree(p, 0, MEM_RELEASE);
117 #elif defined(AVMPLUS_OS2)
120 nanojit::CodeAlloc::allocCodeChunk(size_t nbytes) {
122 // alloc from high memory, fallback to low memory if that fails
124 if (DosAllocMem(&addr, nbytes, OBJ_ANY |
125 PAG_COMMIT | PAG_READ | PAG_WRITE | PAG_EXECUTE)) {
126 if (DosAllocMem(&addr, nbytes,
127 PAG_COMMIT | PAG_READ | PAG_WRITE | PAG_EXECUTE)) {
135 nanojit::CodeAlloc::freeCodeChunk(void *p, size_t nbytes) {
139 #elif defined(AVMPLUS_UNIX)
142 nanojit::CodeAlloc::allocCodeChunk(size_t nbytes) {
145 PROT_READ | PROT_WRITE | PROT_EXEC,
146 MAP_PRIVATE | MAP_ANON,
152 nanojit::CodeAlloc::freeCodeChunk(void *p, size_t nbytes) {
153 munmap((maddr_ptr)p, nbytes);
156 #else // !WIN32 && !AVMPLUS_OS2 && !AVMPLUS_UNIX
159 nanojit::CodeAlloc::allocCodeChunk(size_t nbytes) {
160 void* mem = valloc(nbytes);
161 VMPI_setPageProtection(mem, nbytes, true /* exec */, true /* write */);
166 nanojit::CodeAlloc::freeCodeChunk(void *p, size_t nbytes) {
167 VMPI_setPageProtection(p, nbytes, false /* exec */, true /* write */);
173 // All of the allocCodeChunk/freeCodeChunk implementations above allocate
174 // code memory as RWX and then free it, so the explicit page protection api's
178 nanojit::CodeAlloc::markCodeChunkWrite(void*, size_t)
182 nanojit::CodeAlloc::markCodeChunkExec(void*, size_t)