1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
44
#include <sys/types.h>
49
#define _PR_GC_VMBASE 0x40000000
52
#define _MD_MMAP_FLAGS MAP_SHARED
53
#elif defined(RELIANTUNIX)
54
#define _MD_MMAP_FLAGS MAP_PRIVATE|MAP_FIXED
56
#define _MD_MMAP_FLAGS MAP_PRIVATE
59
static PRInt32 zero_fd = -1;
60
static PRLock *zero_fd_lock = NULL;
66
* Disable using mmap(2) if NSPR_NO_MMAP is set
68
if (getenv("NSPR_NO_MMAP")) {
73
zero_fd = open("/dev/zero",O_RDWR , 0);
74
zero_fd_lock = PR_NewLock();
77
/* This static variable is used by _MD_GrowGCHeap and _MD_ExtendGCHeap */
78
static void *lastaddr = (void*) _PR_GC_VMBASE;
80
void *_MD_GrowGCHeap(PRUint32 *sizep)
87
PR_Lock(zero_fd_lock);
92
/* Extend the mapping */
93
addr = mmap(lastaddr, size, PROT_READ|PROT_WRITE|PROT_EXEC,
96
if (addr == (void*)-1) {
100
lastaddr = ((char*)addr + size);
102
PR_LOG(_pr_msgc_lm, PR_LOG_WARNING,
103
("GC: heap extends from %08x to %08x\n",
105
_PR_GC_VMBASE + (char*)lastaddr - (char*)_PR_GC_VMBASE));
107
PR_Unlock(zero_fd_lock);
111
PR_Unlock(zero_fd_lock);
112
return PR_MALLOC(size);
115
/* XXX - This is disabled. MAP_FIXED just does not work. */
117
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
118
PRBool rv = PR_FALSE;
120
PRInt32 allocSize = newSize - oldSize;
122
PR_Lock(zero_fd_lock);
123
addr = mmap(base + oldSize, allocSize, PROT_READ|PROT_WRITE|PROT_EXEC,
124
_MD_MMAP_FLAGS | MAP_FIXED, zero_fd, 0);
125
if (addr == (void*)-1) {
128
if (addr != (void*) (base + oldSize)) {
129
munmap(base + oldSize, allocSize);
132
lastaddr = ((char*)base + newSize);
133
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
134
("GC: heap now extends from %p to %p",
135
base, base + newSize));
139
PR_Unlock(zero_fd_lock);
143
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
148
void _MD_FreeGCSegment(void *base, PRInt32 len)
153
(void) munmap(base, len);