Debian Codegraph @

nsprpub/pr/src/memory/prseg.c

raw
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/. */
5
6 #include "primpl.h"
7
8 #if defined(_PR_PTHREADS)
9
10 /*
11 ** The pthreads version doesn't use these functions.
12 */
13 void _PR_InitSegs(void) {}
14
15 #else /* _PR_PTHREADS */
16
17 void _PR_InitSegs(void) { _PR_MD_INIT_SEGS(); }
18
19 /*
20 ** Allocate a memory segment. The size value is rounded up to the native
21 ** system page size and a page aligned portion of memory is returned.
22 ** This memory is not part of the malloc heap. If "vaddr" is not NULL
23 ** then PR tries to allocate the segment at the desired virtual address.
24 */
25 PRSegment* _PR_NewSegment(PRUint32 size, void* vaddr) {
26 PRSegment* seg;
27
28 /* calloc the data structure for the segment */
29 seg = PR_NEWZAP(PRSegment);
30
31 if (seg) {
32 size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift;
33 /*
34 ** Now, allocate the actual segment memory (or map under some OS)
35 ** The OS specific code decides from where or how to allocate memory.
36 */
37 if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) {
38 PR_DELETE(seg);
39 return NULL;
40 }
41 }
42
43 return seg;
44 }
45
46 /*
47 ** Free a memory segment.
48 */
49 void _PR_DestroySegment(PRSegment* seg) {
50 _PR_MD_FREE_SEGMENT(seg);
51 PR_DELETE(seg);
52 }
53
54 #endif /* _PR_PTHREADS */