nsprpub/pr/src/memory/prseg.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/memory/prseg.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "primpl.h"
    1.10 +
    1.11 +#if defined(_PR_PTHREADS)
    1.12 +
    1.13 +/*
    1.14 +** The pthreads version doesn't use these functions.
    1.15 +*/
    1.16 +void _PR_InitSegs(void)
    1.17 +{
    1.18 +}
    1.19 +
    1.20 +#else /* _PR_PTHREADS */
    1.21 +
    1.22 +void _PR_InitSegs(void)
    1.23 +{
    1.24 +	_PR_MD_INIT_SEGS();
    1.25 +}
    1.26 +
    1.27 +/*
    1.28 +** Allocate a memory segment. The size value is rounded up to the native
    1.29 +** system page size and a page aligned portion of memory is returned.
    1.30 +** This memory is not part of the malloc heap. If "vaddr" is not NULL
    1.31 +** then PR tries to allocate the segment at the desired virtual address.
    1.32 +*/
    1.33 +PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr)
    1.34 +{
    1.35 +    PRSegment *seg;
    1.36 +
    1.37 +	/* calloc the data structure for the segment */
    1.38 +    seg = PR_NEWZAP(PRSegment);
    1.39 +
    1.40 +    if (seg) {
    1.41 +	    size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift;
    1.42 +		/*
    1.43 +		**	Now, allocate the actual segment memory (or map under some OS)
    1.44 +		**	The OS specific code decides from where or how to allocate memory.
    1.45 +		*/
    1.46 +	    if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) {
    1.47 +			PR_DELETE(seg);
    1.48 +			return NULL;
    1.49 +    	}
    1.50 +	}
    1.51 +
    1.52 +    return seg;
    1.53 +}
    1.54 +
    1.55 +/*
    1.56 +** Free a memory segment.
    1.57 +*/
    1.58 +void _PR_DestroySegment(PRSegment *seg)
    1.59 +{
    1.60 +	_PR_MD_FREE_SEGMENT(seg);
    1.61 +    PR_DELETE(seg);
    1.62 +}
    1.63 +
    1.64 +#endif /* _PR_PTHREADS */

mercurial