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