Rev 1289 | Rev 1296 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1289 | Rev 1292 | ||
---|---|---|---|
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: 1289 $ |
8 | $Revision: 1292 $ |
9 | 9 | ||
Line 1308... | Line 1308... | ||
1308 | jz .fail_and_dereference |
1308 | jz .fail_and_dereference |
1309 | @@: |
1309 | @@: |
1310 | mov [img_base], eax |
1310 | mov [img_base], eax |
1311 | mov ebx, [CURRENT_TASK] |
1311 | mov ebx, [CURRENT_TASK] |
1312 | shl ebx, 5 |
1312 | shl ebx, 5 |
1313 | add ebx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1313 | mov ebx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1314 | mov eax, HDLL.sizeof |
1314 | mov eax, HDLL.sizeof |
1315 | call create_kernel_object |
1315 | call create_kernel_object |
1316 | test eax, eax |
1316 | test eax, eax |
1317 | jz .fail_and_free_user |
1317 | jz .fail_and_free_user |
1318 | mov [eax+APPOBJ.magic], 'HDLL' |
1318 | mov [eax+APPOBJ.magic], 'HDLL' |
Line 1382... | Line 1382... | ||
1382 | jnz .ret |
1382 | jnz .ret |
1383 | mov eax, [esi+DLLDESCR.fd] |
1383 | mov eax, [esi+DLLDESCR.fd] |
1384 | mov edx, [esi+DLLDESCR.bk] |
1384 | mov edx, [esi+DLLDESCR.bk] |
1385 | mov [eax+DLLDESCR.bk], edx |
1385 | mov [eax+DLLDESCR.bk], edx |
1386 | mov [edx+DLLDESCR.fd], eax |
1386 | mov [edx+DLLDESCR.fd], eax |
1387 | stdcall kernel_free, [esi+DLLDESCR.symbols_ptr] |
1387 | stdcall kernel_free, [esi+DLLDESCR.coff_hdr] |
1388 | stdcall kernel_free, [esi+DLLDESCR.data] |
1388 | stdcall kernel_free, [esi+DLLDESCR.data] |
1389 | mov eax, esi |
1389 | mov eax, esi |
1390 | call free |
1390 | call free |
1391 | .ret: |
1391 | .ret: |
1392 | ret |
1392 | ret |
Line 1393... | Line 1393... | ||
1393 | 1393 | ||
1394 | destroy_hdll: |
1394 | destroy_hdll: |
1395 | push ebx esi edi |
1395 | push ebx esi edi |
1396 | push eax |
1396 | push eax |
1397 | mov ebx, [eax+HDLL.base] |
- | |
1398 | push ebx ; argument for user_free |
- | |
1399 | push eax |
1397 | mov ebx, [eax+HDLL.base] |
1400 | mov esi, [eax+HDLL.parent] |
1398 | mov esi, [eax+HDLL.parent] |
- | 1399 | mov edx, [esi+DLLDESCR.size] |
|
- | 1400 | ; The following actions require the context of application where HDLL is mapped. |
|
- | 1401 | ; However, destroy_hdll can be called in the context of OS thread when |
|
- | 1402 | ; cleaning up objects created by the application which is destroyed. |
|
- | 1403 | ; So remember current cr3 and set it to page table of target. |
|
- | 1404 | mov eax, [eax+HDLL.pid] |
|
- | 1405 | call pid_to_slot |
|
- | 1406 | shl eax, 8 |
|
- | 1407 | add eax, SLOT_BASE |
|
- | 1408 | mov ecx, [eax+APPDATA.dir_table] |
|
- | 1409 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
|
- | 1410 | ; page table from APPDATA of current thread. |
|
- | 1411 | ; Also set [current_slot] because it is used by user_free. |
|
- | 1412 | pushf |
|
- | 1413 | cli |
|
- | 1414 | push [current_slot] |
|
- | 1415 | mov [current_slot], eax |
|
- | 1416 | mov eax, cr3 |
|
- | 1417 | push eax |
|
- | 1418 | mov cr3, ecx |
|
1401 | mov edx, [esi+DLLDESCR.size] |
1419 | push ebx ; argument for user_free |
1402 | mov eax, ebx |
1420 | mov eax, ebx |
1403 | shr ebx, 12 |
1421 | shr ebx, 12 |
1404 | push ebx |
1422 | push ebx |
1405 | mov esi, [esi+DLLDESCR.data] |
1423 | mov esi, [esi+DLLDESCR.data] |
1406 | shr esi, 12 |
1424 | shr esi, 12 |
1407 | .unmap_loop: |
1425 | .unmap_loop: |
1408 | push eax |
1426 | push eax |
1409 | mov eax, 2 |
1427 | mov eax, 2 |
1410 | xchg eax, [page_tabs+ebx*4] |
1428 | xchg eax, [page_tabs+ebx*4] |
- | 1429 | mov ecx, [page_tabs+esi*4] |
|
- | 1430 | and eax, not 0xFFF |
|
- | 1431 | and ecx, not 0xFFF |
|
1411 | cmp eax, [page_tabs+esi*4] |
1432 | cmp eax, ecx |
1412 | jnz @f |
1433 | jz @f |
1413 | call free_page |
1434 | call free_page |
1414 | @@: |
1435 | @@: |
1415 | pop eax |
1436 | pop eax |
1416 | invlpg [eax] |
1437 | invlpg [eax] |
1417 | add eax, 0x1000 |
1438 | add eax, 0x1000 |
1418 | inc ebx |
1439 | inc ebx |
1419 | inc esi |
1440 | inc esi |
1420 | sub edx, 0x1000 |
1441 | sub edx, 0x1000 |
1421 | ja .unmap_loop |
1442 | ja .unmap_loop |
1422 | pop ebx eax |
1443 | pop ebx |
- | 1444 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |
|
- | 1445 | call user_free |
|
- | 1446 | ; Restore context. |
|
- | 1447 | pop eax |
|
- | 1448 | mov cr3, eax |
|
- | 1449 | pop [current_slot] |
|
- | 1450 | popf |
|
- | 1451 | ; Ok, cheating is done. |
|
- | 1452 | pop eax |
|
1423 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |
1453 | push eax |
1424 | mov esi, [eax+HDLL.parent] |
1454 | mov esi, [eax+HDLL.parent] |
1425 | mov eax, [eax+HDLL.refcount] |
1455 | mov eax, [eax+HDLL.refcount] |
1426 | call dereference_dll |
- | |
1427 | call user_free |
1456 | call dereference_dll |
1428 | pop eax |
1457 | pop eax |
1429 | call destroy_kernel_object |
1458 | call destroy_kernel_object |
1430 | pop edi esi ebx |
1459 | pop edi esi ebx |