Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
359 | serge | 1 | /**************************************************************************** |
2 | * |
||
3 | * Open Watcom Project |
||
4 | * |
||
5 | * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | * |
||
7 | * ======================================================================== |
||
8 | * |
||
9 | * This file contains Original Code and/or Modifications of Original |
||
10 | * Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | * Public License version 1.0 (the 'License'). You may not use this file |
||
12 | * except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | * ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | * provided with the Original Code and Modifications, and is also |
||
15 | * available at www.sybase.com/developer/opensource. |
||
16 | * |
||
17 | * The Original Code and all software distributed under the License are |
||
18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | * EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | * NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | * governing rights and limitations under the License. |
||
24 | * |
||
25 | * ======================================================================== |
||
26 | * |
||
27 | * Description: Routines to grow heap (allocate memory from OS). |
||
28 | * |
||
29 | ****************************************************************************/ |
||
30 | |||
31 | |||
32 | //#include "dll.h" // needs to be first |
||
33 | #include "variety.h" |
||
34 | #include |
||
35 | #include |
||
36 | #include |
||
37 | #if defined(__QNX__) |
||
38 | #elif defined(__LINUX__) |
||
39 | #elif defined(__OS2__) |
||
40 | #elif defined(_M_IX86) |
||
41 | // #include "tinyio.h" |
||
42 | #endif |
||
43 | #include "heap.h" |
||
44 | #include "heapacc.h" |
||
45 | |||
46 | #if defined(M_I86) |
||
47 | |||
48 | _WCRTLINK void _fheapgrow( void ) |
||
49 | { |
||
50 | /* multiple heaps are used so growing the far heaps is not necessary */ |
||
51 | } |
||
52 | |||
53 | #endif |
||
54 | |||
55 | |||
56 | #if defined(__SMALL_DATA__) |
||
57 | |||
58 | _WCRTLINK void _heapgrow( void ) |
||
59 | { |
||
60 | _nheapgrow(); |
||
61 | } |
||
62 | |||
63 | #else |
||
64 | |||
65 | _WCRTLINK void _heapgrow( void ) |
||
66 | { |
||
67 | _fheapgrow(); |
||
68 | } |
||
69 | |||
70 | #endif |
||
71 | |||
72 | |||
73 | _WCRTLINK void _nheapgrow( void ) |
||
74 | { |
||
75 | #if defined(__WINDOWS_286__) || defined(__386__) || defined(__AXP__) || defined(__PPC__) || defined(__MIPS__) |
||
76 | _nfree( _nmalloc( 1 ) ); /* get something into the heap */ |
||
77 | #else |
||
78 | unsigned max_paras; |
||
79 | unsigned curr_paras; |
||
80 | unsigned diff_paras; |
||
81 | unsigned expand; |
||
82 | |||
83 | _AccessNHeap(); |
||
84 | /* calculate # pages which always has extra slack space (ie. 0x10) */ |
||
85 | curr_paras = (( _curbrk + 0x10 ) & ~0x0f ) >> 4; |
||
86 | if( curr_paras == 0 ) { |
||
87 | /* we're already at 64k */ |
||
88 | _ReleaseNHeap(); |
||
89 | return; |
||
90 | } |
||
91 | #if defined(__QNX__) |
||
92 | if( qnx_segment_realloc( _DGroup(), 65536L ) == -1 ) { |
||
93 | _ReleaseNHeap(); |
||
94 | return; |
||
95 | } |
||
96 | max_paras = PARAS_IN_64K; |
||
97 | #elif defined(__OS2__) |
||
98 | if( DosReallocSeg( 0, _DGroup() ) ) { |
||
99 | _ReleaseNHeap(); |
||
100 | return; |
||
101 | } |
||
102 | max_paras = PARAS_IN_64K; |
||
103 | #else |
||
104 | if( _osmode != DOS_MODE ) { /* 23-apr-91 */ |
||
105 | max_paras = PARAS_IN_64K; |
||
106 | } else { |
||
107 | max_paras = TinyMaxSet( _psp ); |
||
108 | /* subtract off code size */ |
||
109 | max_paras -= _DGroup() - _psp; |
||
110 | if( max_paras > PARAS_IN_64K ) { |
||
111 | max_paras = PARAS_IN_64K; |
||
112 | } |
||
113 | } |
||
114 | #endif |
||
115 | if( max_paras <= curr_paras ) { |
||
116 | /* '<' -> something is wrong, '==' -> can't change size */ |
||
117 | _ReleaseNHeap(); |
||
118 | return; |
||
119 | } |
||
120 | diff_paras = max_paras - curr_paras; |
||
121 | expand = (( diff_paras + 1 ) << 4 ) - ( _curbrk & 0x0f ); |
||
122 | expand += __LastFree(); /* compensate for _expand's adjustment */ |
||
123 | _ReleaseNHeap(); |
||
124 | _nfree( _nmalloc( expand - ( sizeof( size_t ) + sizeof(frl) ) ) ); |
||
125 | #endif |
||
126 | }><>'>=> |