nsprpub/pr/src/memory/prseg.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "primpl.h"
     8 #if defined(_PR_PTHREADS)
    10 /*
    11 ** The pthreads version doesn't use these functions.
    12 */
    13 void _PR_InitSegs(void)
    14 {
    15 }
    17 #else /* _PR_PTHREADS */
    19 void _PR_InitSegs(void)
    20 {
    21 	_PR_MD_INIT_SEGS();
    22 }
    24 /*
    25 ** Allocate a memory segment. The size value is rounded up to the native
    26 ** system page size and a page aligned portion of memory is returned.
    27 ** This memory is not part of the malloc heap. If "vaddr" is not NULL
    28 ** then PR tries to allocate the segment at the desired virtual address.
    29 */
    30 PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr)
    31 {
    32     PRSegment *seg;
    34 	/* calloc the data structure for the segment */
    35     seg = PR_NEWZAP(PRSegment);
    37     if (seg) {
    38 	    size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift;
    39 		/*
    40 		**	Now, allocate the actual segment memory (or map under some OS)
    41 		**	The OS specific code decides from where or how to allocate memory.
    42 		*/
    43 	    if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) {
    44 			PR_DELETE(seg);
    45 			return NULL;
    46     	}
    47 	}
    49     return seg;
    50 }
    52 /*
    53 ** Free a memory segment.
    54 */
    55 void _PR_DestroySegment(PRSegment *seg)
    56 {
    57 	_PR_MD_FREE_SEGMENT(seg);
    58     PR_DELETE(seg);
    59 }
    61 #endif /* _PR_PTHREADS */

mercurial