Rev 2259 | Rev 2465 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2259 | Rev 2434 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 2259 $ |
8 | $Revision: 2434 $ |
9 | - | ||
10 | 9 | ||
11 | struc MEM_BLOCK |
10 | |
12 | { |
11 | struct MEM_BLOCK |
13 | .list LHEAD |
12 | list LHEAD |
14 | .next_block dd ? ;+8 |
13 | next_block dd ? ;+8 |
15 | .prev_block dd ? ;+4 |
14 | prev_block dd ? ;+4 |
16 | .base dd ? ;+16 |
15 | base dd ? ;+16 |
17 | .size dd ? ;+20 |
- | |
18 | .flags dd ? ;+24 |
16 | size dd ? ;+20 |
Line 19... | Line 17... | ||
19 | .handle dd ? ;+28 |
17 | flags dd ? ;+24 |
20 | .sizeof: |
18 | handle dd ? ;+28 |
21 | } |
19 | ends |
Line 22... | Line -... | ||
22 | - | ||
23 | FREE_BLOCK equ 4 |
- | |
24 | USED_BLOCK equ 8 |
- | |
25 | DONT_FREE_BLOCK equ 10h |
- | |
Line 26... | Line 20... | ||
26 | 20 | ||
27 | virtual at 0 |
21 | FREE_BLOCK equ 4 |
28 | MEM_BLOCK MEM_BLOCK |
22 | USED_BLOCK equ 8 |
29 | end virtual |
23 | DONT_FREE_BLOCK equ 10h |
Line 144... | Line 138... | ||
144 | add edx, 0x1000 |
138 | add edx, 0x1000 |
145 | dec ecx |
139 | dec ecx |
146 | jnz .l1 |
140 | jnz .l1 |
Line 147... | Line 141... | ||
147 | 141 | ||
148 | mov edi, HEAP_BASE ;descriptors |
142 | mov edi, HEAP_BASE ;descriptors |
149 | mov ebx, HEAP_BASE+MEM_BLOCK.sizeof ;free space |
143 | mov ebx, HEAP_BASE+sizeof.MEM_BLOCK ;free space |
Line 150... | Line 144... | ||
150 | mov ecx, HEAP_BASE+MEM_BLOCK.sizeof*2 ;terminator |
144 | mov ecx, HEAP_BASE+sizeof.MEM_BLOCK*2 ;terminator |
151 | 145 | ||
152 | xor eax, eax |
146 | xor eax, eax |
153 | mov [edi+block_next], ebx |
147 | mov [edi+block_next], ebx |
154 | mov [edi+block_prev], eax |
148 | mov [edi+block_prev], eax |
155 | mov [edi+list_fd], eax |
149 | mov [edi+list_fd], eax |
156 | mov [edi+list_bk], eax |
150 | mov [edi+list_bk], eax |
157 | mov [edi+block_base], HEAP_BASE |
151 | mov [edi+block_base], HEAP_BASE |
Line 158... | Line 152... | ||
158 | mov [edi+block_size], 4096*MEM_BLOCK.sizeof |
152 | mov [edi+block_size], 4096*sizeof.MEM_BLOCK |
159 | mov [edi+block_flags], USED_BLOCK |
153 | mov [edi+block_flags], USED_BLOCK |
160 | 154 | ||
Line 166... | Line 160... | ||
166 | mov [edi+block_size], eax |
160 | mov [edi+block_size], eax |
167 | mov [edi+block_flags], USED_BLOCK |
161 | mov [edi+block_flags], USED_BLOCK |
Line 168... | Line 162... | ||
168 | 162 | ||
169 | mov [ebx+block_next], ecx |
163 | mov [ebx+block_next], ecx |
170 | mov [ebx+block_prev], edi |
164 | mov [ebx+block_prev], edi |
Line 171... | Line 165... | ||
171 | mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK.sizeof |
165 | mov [ebx+block_base], HEAP_BASE+4096*sizeof.MEM_BLOCK |
172 | 166 | ||
173 | mov ecx, [pg_data.kernel_pages] |
167 | mov ecx, [pg_data.kernel_pages] |
174 | shl ecx, 12 |
168 | shl ecx, 12 |
175 | sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK.sizeof |
169 | sub ecx, HEAP_BASE-OS_BASE+4096*sizeof.MEM_BLOCK |
176 | mov [heap_size], ecx |
170 | mov [heap_size], ecx |
177 | mov [heap_free], ecx |
171 | mov [heap_free], ecx |
Line 183... | Line 177... | ||
183 | 177 | ||
184 | mov ecx, mem_block_list+63*8 |
178 | mov ecx, mem_block_list+63*8 |
Line 185... | Line 179... | ||
185 | list_add ebx, ecx |
179 | list_add ebx, ecx |
186 | 180 | ||
Line 187... | Line 181... | ||
187 | mov ecx, 4096-3-1 |
181 | mov ecx, 4096-3-1 |
188 | mov eax, HEAP_BASE+MEM_BLOCK.sizeof*4 |
182 | mov eax, HEAP_BASE+sizeof.MEM_BLOCK*4 |
189 | 183 | ||
190 | mov [next_memblock], HEAP_BASE+MEM_BLOCK.sizeof*3 |
184 | mov [next_memblock], HEAP_BASE+sizeof.MEM_BLOCK *3 |
191 | @@: |
185 | @@: |
Line 192... | Line 186... | ||
192 | mov [eax-MEM_BLOCK.sizeof], eax |
186 | mov [eax-sizeof.MEM_BLOCK], eax |
Line 193... | Line 187... | ||
193 | add eax, MEM_BLOCK.sizeof |
187 | add eax, sizeof.MEM_BLOCK |
194 | loop @B |
188 | loop @B |
195 | 189 | ||
196 | mov [eax-MEM_BLOCK.sizeof], dword 0 |
190 | mov [eax-sizeof.MEM_BLOCK], dword 0 |
Line 582... | Line 576... | ||
582 | restore block_size |
576 | restore block_size |
583 | restore block_flags |
577 | restore block_flags |
Line 584... | Line 578... | ||
584 | 578 | ||
Line 585... | Line 579... | ||
585 | ;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;; |
579 | ;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;; |
Line 586... | Line 580... | ||
586 | 580 | ||
587 | HEAP_TOP equ 0x5FC00000 |
581 | HEAP_TOP equ 0x80000000 |
Line 588... | Line 582... | ||
588 | 582 | ||
Line 852... | Line 846... | ||
852 | pop ebx |
846 | pop ebx |
853 | pop esi |
847 | pop esi |
854 | ret |
848 | ret |
855 | endp |
849 | endp |
Line -... | Line 850... | ||
- | 850 | ||
- | 851 | ||
- | 852 | align 4 |
|
- | 853 | proc user_unmap stdcall, base:dword, offset:dword, size:dword |
|
- | 854 | ||
- | 855 | push ebx |
|
- | 856 | ||
- | 857 | mov ebx, [base] ; must be valid pointer |
|
- | 858 | test ebx, ebx |
|
- | 859 | jz .error |
|
- | 860 | ||
- | 861 | mov edx, [offset] ; check offset |
|
- | 862 | add edx, ebx ; must be below 2Gb app limit |
|
- | 863 | js .error |
|
- | 864 | ||
- | 865 | shr ebx, 12 ; chek block attributes |
|
- | 866 | lea ebx, [page_tabs+ebx*4] |
|
- | 867 | mov eax, [ebx-4] ; block attributes |
|
- | 868 | test al, USED_BLOCK |
|
- | 869 | jz .error |
|
- | 870 | test al, DONT_FREE_BLOCK |
|
- | 871 | jnz .error |
|
- | 872 | ||
- | 873 | shr edx, 12 |
|
- | 874 | lea edx, [page_tabs+edx*4] ; unmap offset |
|
- | 875 | ||
- | 876 | mov ecx, [size] |
|
- | 877 | add ecx, 4095 |
|
- | 878 | shr ecx, 12 ; unmap size in pages |
|
- | 879 | ||
- | 880 | shr eax, 12 ; block size + 1 page |
|
- | 881 | lea ebx, [ebx+eax*4-4] ; block end ptr |
|
- | 882 | lea eax, [edx+ecx*4] ; unmap end ptr |
|
- | 883 | ||
- | 884 | cmp eax, ebx ; check for overflow |
|
- | 885 | ja .error |
|
- | 886 | ||
- | 887 | mov ebx, [offset] |
|
- | 888 | and ebx, not 4095 ; is it required ? |
|
- | 889 | ||
- | 890 | .unmap: |
|
- | 891 | mov eax, [edx] ; get page addres |
|
- | 892 | test al, 1 ; page mapped ? |
|
- | 893 | jz @F |
|
- | 894 | test eax, PG_SHARED ; page shared ? |
|
- | 895 | jnz @F |
|
- | 896 | mov [page_tabs+edx*4], dword 2 |
|
- | 897 | ; mark page as reserved |
|
- | 898 | invlpg [ebx] ; when we start using |
|
- | 899 | call free_page ; empty c-o-w page instead this ? |
|
- | 900 | @@: |
|
- | 901 | add ebx, 4096 |
|
- | 902 | add edx, 4 |
|
- | 903 | dec ecx |
|
- | 904 | jnz .unmap |
|
- | 905 | ||
- | 906 | pop ebx |
|
- | 907 | or al, 1 ; return non zero on success |
|
- | 908 | ret |
|
- | 909 | .error: |
|
- | 910 | pop ebx |
|
- | 911 | xor eax, eax ; something wrong |
|
- | 912 | ret |
|
- | 913 | endp |
|
- | 914 | ||
856 | 915 | align 4 |
|
857 | user_normalize: |
916 | user_normalize: |
858 | ; in: esi=heap_base, edi=heap_top |
917 | ; in: esi=heap_base, edi=heap_top |
859 | ; out: eax=0 <=> OK |
918 | ; out: eax=0 <=> OK |
860 | ; destroys: ebx,edx,esi,edi |
919 | ; destroys: ebx,edx,esi,edi |
Line 1290... | Line 1349... | ||
1290 | 1349 | ||
1291 | add ecx, 4095 |
1350 | add ecx, 4095 |
1292 | and ecx, -4096 |
1351 | and ecx, -4096 |
Line 1293... | Line 1352... | ||
1293 | mov [size], ecx |
1352 | mov [size], ecx |
1294 | 1353 | ||
1295 | mov eax, SMEM.sizeof |
1354 | mov eax, sizeof.SMEM |
1296 | call malloc |
1355 | call malloc |
1297 | test eax, eax |
1356 | test eax, eax |
1298 | mov esi, eax |
1357 | mov esi, eax |
Line 1352... | Line 1411... | ||
1352 | ja .fail |
1411 | ja .fail |
Line 1353... | Line 1412... | ||
1353 | 1412 | ||
1354 | mov ebx, [CURRENT_TASK] |
1413 | mov ebx, [CURRENT_TASK] |
1355 | shl ebx, 5 |
1414 | shl ebx, 5 |
1356 | mov ebx, [CURRENT_TASK+ebx+4] |
1415 | mov ebx, [CURRENT_TASK+ebx+4] |
Line 1357... | Line 1416... | ||
1357 | mov eax, SMAP.sizeof |
1416 | mov eax, sizeof.SMAP |
1358 | 1417 | ||
1359 | call create_kernel_object |
1418 | call create_kernel_object |
1360 | test eax, eax |
1419 | test eax, eax |