michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "primpl.h" michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: michael@0: /* michael@0: ** The pthreads version doesn't use these functions. michael@0: */ michael@0: void _PR_InitSegs(void) michael@0: { michael@0: } michael@0: michael@0: #else /* _PR_PTHREADS */ michael@0: michael@0: void _PR_InitSegs(void) michael@0: { michael@0: _PR_MD_INIT_SEGS(); michael@0: } michael@0: michael@0: /* michael@0: ** Allocate a memory segment. The size value is rounded up to the native michael@0: ** system page size and a page aligned portion of memory is returned. michael@0: ** This memory is not part of the malloc heap. If "vaddr" is not NULL michael@0: ** then PR tries to allocate the segment at the desired virtual address. michael@0: */ michael@0: PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr) michael@0: { michael@0: PRSegment *seg; michael@0: michael@0: /* calloc the data structure for the segment */ michael@0: seg = PR_NEWZAP(PRSegment); michael@0: michael@0: if (seg) { michael@0: size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift; michael@0: /* michael@0: ** Now, allocate the actual segment memory (or map under some OS) michael@0: ** The OS specific code decides from where or how to allocate memory. michael@0: */ michael@0: if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) { michael@0: PR_DELETE(seg); michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: return seg; michael@0: } michael@0: michael@0: /* michael@0: ** Free a memory segment. michael@0: */ michael@0: void _PR_DestroySegment(PRSegment *seg) michael@0: { michael@0: _PR_MD_FREE_SEGMENT(seg); michael@0: PR_DELETE(seg); michael@0: } michael@0: michael@0: #endif /* _PR_PTHREADS */