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 ***** */
38 typedef caddr_t maddr_ptr;
40 typedef void *maddr_ptr;
43 using namespace avmplus;
53 VMPI_setPageProtection(void *address,
58 DWORD oldProtectFlags = 0;
59 DWORD newProtectFlags = 0;
60 if ( executableFlag && writeableFlag ) {
61 newProtectFlags = PAGE_EXECUTE_READWRITE;
62 } else if ( executableFlag ) {
63 newProtectFlags = PAGE_EXECUTE_READ;
64 } else if ( writeableFlag ) {
65 newProtectFlags = PAGE_READWRITE;
67 newProtectFlags = PAGE_READONLY;
71 MEMORY_BASIC_INFORMATION mbi;
73 VirtualQuery(address, &mbi, sizeof(MEMORY_BASIC_INFORMATION));
74 size_t markSize = size > mbi.RegionSize ? mbi.RegionSize : size;
76 retval = VirtualProtect(address, markSize, newProtectFlags, &oldProtectFlags);
79 address = (char*) address + markSize;
81 } while(size > 0 && retval);
83 // We should not be clobbering PAGE_GUARD protections
84 NanoAssert((oldProtectFlags & PAGE_GUARD) == 0);
87 #elif defined(AVMPLUS_OS2)
90 VMPI_setPageProtection(void *address,
95 ULONG flags = PAG_READ;
102 address = (void*)((size_t)address & ~(0xfff));
103 size = (size + 0xfff) & ~(0xfff);
105 ULONG attribFlags = PAG_FREE;
109 ULONG retval = DosQueryMem(address, &range, &attrib);
110 NanoAssert(retval == 0);
112 // exit if this is the start of the next memory object
113 if (attrib & attribFlags) {
116 attribFlags |= PAG_BASE;
118 range = size > range ? range : size;
119 retval = DosSetMem(address, range, flags);
120 NanoAssert(retval == 0);
122 address = (char*)address + range;
127 #else // !WIN32 && !AVMPLUS_OS2
129 void VMPI_setPageProtection(void *address,
134 int bitmask = sysconf(_SC_PAGESIZE) - 1;
135 // mprotect requires that the addresses be aligned on page boundaries
136 void *endAddress = (void*) ((char*)address + size);
137 void *beginPage = (void*) ((size_t)address & ~bitmask);
138 void *endPage = (void*) (((size_t)endAddress + bitmask) & ~bitmask);
139 size_t sizePaged = (size_t)endPage - (size_t)beginPage;
141 int flags = PROT_READ;
142 if (executableFlag) {
148 int retval = mprotect((maddr_ptr)beginPage, (unsigned int)sizePaged, flags);
149 NanoAssert(retval == 0);