/src/nspr/pr/src/memory/prseg.c
Line | Count | Source |
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 | 1 | { |
15 | 1 | } |
16 | | |
17 | | #else /* _PR_PTHREADS */ |
18 | | |
19 | | void _PR_InitSegs(void) |
20 | | { |
21 | | _PR_MD_INIT_SEGS(); |
22 | | } |
23 | | |
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; |
33 | | |
34 | | /* calloc the data structure for the segment */ |
35 | | seg = PR_NEWZAP(PRSegment); |
36 | | |
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 | | } |
48 | | |
49 | | return seg; |
50 | | } |
51 | | |
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 | | } |
60 | | |
61 | | #endif /* _PR_PTHREADS */ |