~ubuntu-branches/ubuntu/oneiric/nspr/oneiric-security

« back to all changes in this revision

Viewing changes to mozilla/nsprpub/lib/msgc/src/unixgc.c

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2013-01-10 12:35:22 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20130110123522-pnodrf50v6mkn4hs
Tags: 4.9.4-0ubuntu0.11.10.1
* New upstream release to support security fixes in nss. Dropped the
  following patches:
  - debian/patches/30_pkgconfig.patch (included upstream)
  - debian/patches/40_fix_arm_ftbfs.patch (no longer required)
* debian/patches/30_config_64bits.patch: refresh
* debian/patches/99_configure.patch: regenerate per debian/rules
* debian/libnsp4.symbols: added PR_GetThreadName@Base, PR_GetVersion@Base
  and PR_SetCurrentThreadName@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
 *
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/
9
 
 *
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
13
 
 * License.
14
 
 *
15
 
 * The Original Code is the Netscape Portable Runtime (NSPR).
16
 
 *
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.
21
 
 *
22
 
 * Contributor(s):
23
 
 *
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.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
 
38
 
#include "prlock.h"
39
 
#include "prlog.h"
40
 
#include "prmem.h"
41
 
#include "gcint.h"
42
 
 
43
 
#include <stdio.h>
44
 
#include <sys/types.h>
45
 
#include <sys/stat.h>
46
 
#include <fcntl.h>
47
 
#include <sys/mman.h>
48
 
 
49
 
#define _PR_GC_VMBASE 0x40000000
50
 
 
51
 
#if defined(SOLARIS)
52
 
#define _MD_MMAP_FLAGS MAP_SHARED
53
 
#elif defined(RELIANTUNIX)
54
 
#define _MD_MMAP_FLAGS MAP_PRIVATE|MAP_FIXED
55
 
#else
56
 
#define _MD_MMAP_FLAGS MAP_PRIVATE
57
 
#endif
58
 
 
59
 
static PRInt32 zero_fd = -1;
60
 
static PRLock *zero_fd_lock = NULL;
61
 
 
62
 
void _MD_InitGC(void)
63
 
{
64
 
#ifdef DEBUG
65
 
    /*
66
 
     * Disable using mmap(2) if NSPR_NO_MMAP is set
67
 
     */
68
 
    if (getenv("NSPR_NO_MMAP")) {
69
 
        zero_fd = -2;
70
 
        return;
71
 
    }
72
 
#endif
73
 
    zero_fd = open("/dev/zero",O_RDWR , 0);
74
 
    zero_fd_lock = PR_NewLock();
75
 
}
76
 
 
77
 
/* This static variable is used by _MD_GrowGCHeap and _MD_ExtendGCHeap */
78
 
static void *lastaddr = (void*) _PR_GC_VMBASE;
79
 
 
80
 
void *_MD_GrowGCHeap(PRUint32 *sizep)
81
 
{
82
 
        void *addr;
83
 
        PRUint32 size;
84
 
 
85
 
        size = *sizep;
86
 
 
87
 
        PR_Lock(zero_fd_lock);
88
 
        if (zero_fd < 0) {
89
 
                goto mmap_loses;
90
 
        }
91
 
 
92
 
        /* Extend the mapping */
93
 
        addr = mmap(lastaddr, size, PROT_READ|PROT_WRITE|PROT_EXEC,
94
 
            _MD_MMAP_FLAGS,
95
 
            zero_fd, 0);
96
 
        if (addr == (void*)-1) {
97
 
                zero_fd = -1;
98
 
                goto mmap_loses;
99
 
        }
100
 
        lastaddr = ((char*)addr + size);
101
 
#ifdef DEBUG
102
 
        PR_LOG(_pr_msgc_lm, PR_LOG_WARNING,
103
 
            ("GC: heap extends from %08x to %08x\n",
104
 
            _PR_GC_VMBASE,
105
 
            _PR_GC_VMBASE + (char*)lastaddr - (char*)_PR_GC_VMBASE));
106
 
#endif
107
 
        PR_Unlock(zero_fd_lock);
108
 
        return addr;
109
 
 
110
 
mmap_loses:
111
 
        PR_Unlock(zero_fd_lock);
112
 
        return PR_MALLOC(size);
113
 
}
114
 
 
115
 
/* XXX - This is disabled.  MAP_FIXED just does not work. */
116
 
#if 0
117
 
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
118
 
        PRBool rv = PR_FALSE;
119
 
        void* addr;
120
 
        PRInt32 allocSize = newSize - oldSize;
121
 
 
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) {
126
 
                goto loser;
127
 
        }
128
 
        if (addr != (void*) (base + oldSize)) {
129
 
                munmap(base + oldSize, allocSize);
130
 
                goto loser;
131
 
        }
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));
136
 
        rv = PR_TRUE;
137
 
 
138
 
loser:
139
 
        PR_Unlock(zero_fd_lock);
140
 
        return rv;
141
 
}
142
 
#else
143
 
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
144
 
        return PR_FALSE;
145
 
}
146
 
#endif
147
 
 
148
 
void _MD_FreeGCSegment(void *base, PRInt32 len)
149
 
{
150
 
        if (zero_fd < 0) {
151
 
                PR_DELETE(base);
152
 
        } else {
153
 
                (void) munmap(base, len);
154
 
        }
155
 
}