Rev 1296 | Rev 1345 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1296 | Rev 1311 | ||
---|---|---|---|
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: 1296 $ |
8 | $Revision: 1311 $ |
9 | 9 | ||
Line 1062... | Line 1062... | ||
1062 | 1062 | ||
1063 | ; scan for required DLL in list of already loaded for this process, |
1063 | ; scan for required DLL in list of already loaded for this process, |
1064 | ; ignore timestamp |
1064 | ; ignore timestamp |
1065 | mov esi, [CURRENT_TASK] |
1065 | mov esi, [CURRENT_TASK] |
1066 | shl esi, 8 |
- | |
1067 | lea ebx, [esi+SLOT_BASE+APP_OBJ_OFFSET] |
- | |
1068 | mov esi, [ebx+APPOBJ.fd] |
1066 | shl esi, 8 |
- | 1067 | lea edi, [fullname] |
|
- | 1068 | mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr] |
|
- | 1069 | test ebx, ebx |
|
- | 1070 | jz .not_in_process |
|
1069 | lea edi, [fullname] |
1071 | mov esi, [ebx+HDLL.fd] |
1070 | .scan_in_process: |
1072 | .scan_in_process: |
1071 | cmp esi, ebx |
1073 | cmp esi, ebx |
1072 | jz .not_in_process |
- | |
1073 | cmp dword [esi+APPOBJ.magic], 'HDLL' |
- | |
1074 | jnz .next_in_process |
1074 | jz .not_in_process |
1075 | mov eax, [esi+HDLL.parent] |
1075 | mov eax, [esi+HDLL.parent] |
1076 | add eax, DLLDESCR.name |
1076 | add eax, DLLDESCR.name |
1077 | stdcall strncmp, eax, edi, -1 |
1077 | stdcall strncmp, eax, edi, -1 |
1078 | test eax, eax |
1078 | test eax, eax |
Line 1085... | Line 1085... | ||
1085 | mov eax, [ecx+DLLDESCR.exports] |
1085 | mov eax, [ecx+DLLDESCR.exports] |
1086 | sub eax, [ecx+DLLDESCR.defaultbase] |
1086 | sub eax, [ecx+DLLDESCR.defaultbase] |
1087 | add eax, [esi+HDLL.base] |
1087 | add eax, [esi+HDLL.base] |
1088 | ret |
1088 | ret |
1089 | .next_in_process: |
1089 | .next_in_process: |
1090 | mov esi, [esi+APPOBJ.fd] |
1090 | mov esi, [esi+HDLL.fd] |
1091 | jmp .scan_in_process |
1091 | jmp .scan_in_process |
1092 | .not_in_process: |
1092 | .not_in_process: |
Line 1093... | Line 1093... | ||
1093 | 1093 | ||
1094 | ; scan in full list, compare timestamp |
1094 | ; scan in full list, compare timestamp |
Line 1333... | Line 1333... | ||
1333 | stdcall user_alloc, edi |
1333 | stdcall user_alloc, edi |
1334 | test eax, eax |
1334 | test eax, eax |
1335 | jz .fail_and_dereference |
1335 | jz .fail_and_dereference |
1336 | @@: |
1336 | @@: |
1337 | mov [img_base], eax |
1337 | mov [img_base], eax |
- | 1338 | mov eax, HDLL.sizeof |
|
- | 1339 | call malloc |
|
- | 1340 | test eax, eax |
|
- | 1341 | jz .fail_and_free_user |
|
1338 | mov ebx, [CURRENT_TASK] |
1342 | mov ebx, [CURRENT_TASK] |
1339 | shl ebx, 5 |
1343 | shl ebx, 5 |
1340 | mov ebx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1344 | mov edx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1341 | mov eax, HDLL.sizeof |
1345 | mov [eax+HDLL.pid], edx |
- | 1346 | push eax |
|
1342 | call create_kernel_object |
1347 | call init_dlls_in_thread |
- | 1348 | pop ebx |
|
1343 | test eax, eax |
1349 | test eax, eax |
1344 | jz .fail_and_free_user |
1350 | jz .fail_and_free_user |
- | 1351 | mov edx, [eax+HDLL.fd] |
|
- | 1352 | mov [ebx+HDLL.fd], edx |
|
- | 1353 | mov [ebx+HDLL.bk], eax |
|
1345 | mov [eax+APPOBJ.magic], 'HDLL' |
1354 | mov [eax+HDLL.fd], ebx |
1346 | mov [eax+APPOBJ.destroy], destroy_hdll |
1355 | mov [edx+HDLL.bk], ebx |
- | 1356 | mov eax, ebx |
|
1347 | mov ebx, [img_base] |
1357 | mov ebx, [img_base] |
1348 | mov [eax+HDLL.base], ebx |
1358 | mov [eax+HDLL.base], ebx |
1349 | mov [eax+HDLL.size], edi |
1359 | mov [eax+HDLL.size], edi |
1350 | mov [eax+HDLL.refcount], 1 |
1360 | mov [eax+HDLL.refcount], 1 |
1351 | mov [eax+HDLL.parent], esi |
1361 | mov [eax+HDLL.parent], esi |
Line 1372... | Line 1382... | ||
1372 | add edi, 0x1000 |
1382 | add edi, 0x1000 |
1373 | cmp edi, [esi+DLLDESCR.size] |
1383 | cmp edi, [esi+DLLDESCR.size] |
1374 | jb .map_pages_loop |
1384 | jb .map_pages_loop |
Line 1375... | Line 1385... | ||
1375 | 1385 | ||
1376 | ; if real user-mode base is not equal to preferred base, relocate image |
- | |
1377 | mov ebx, [img_base] |
1386 | ; if real user-mode base is not equal to preferred base, relocate image |
1378 | sub ebx, [esi+DLLDESCR.defaultbase] |
1387 | sub ebx, [esi+DLLDESCR.defaultbase] |
1379 | jz @f |
1388 | jz @f |
1380 | stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx |
1389 | stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx |
Line 1401... | Line 1410... | ||
1401 | call dereference_dll |
1410 | call dereference_dll |
1402 | xor eax, eax |
1411 | xor eax, eax |
1403 | ret |
1412 | ret |
1404 | endp |
1413 | endp |
Line -... | Line 1414... | ||
- | 1414 | ||
- | 1415 | ; initialize [APPDATA.dlls_list_ptr] for given thread |
|
- | 1416 | ; DLL is per-process object, so APPDATA.dlls_list_ptr must be |
|
- | 1417 | ; kept in sync for all threads of one process. |
|
- | 1418 | ; out: eax = APPDATA.dlls_list_ptr if all is OK, |
|
- | 1419 | ; NULL if memory allocation failed |
|
- | 1420 | init_dlls_in_thread: |
|
- | 1421 | mov ebx, [current_slot] |
|
- | 1422 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
|
- | 1423 | test eax, eax |
|
- | 1424 | jnz .ret |
|
- | 1425 | push [ebx+APPDATA.dir_table] |
|
- | 1426 | mov eax, 8 |
|
- | 1427 | call malloc |
|
- | 1428 | pop edx |
|
- | 1429 | test eax, eax |
|
- | 1430 | jz .ret |
|
- | 1431 | mov [eax], eax |
|
- | 1432 | mov [eax+4], eax |
|
- | 1433 | mov ecx, [TASK_COUNT] |
|
- | 1434 | mov ebx, SLOT_BASE+256 |
|
- | 1435 | .set: |
|
- | 1436 | cmp [ebx+APPDATA.dir_table], edx |
|
- | 1437 | jnz @f |
|
- | 1438 | mov [ebx+APPDATA.dlls_list_ptr], eax |
|
- | 1439 | @@: |
|
- | 1440 | add ebx, 256 |
|
- | 1441 | dec ecx |
|
- | 1442 | jnz .set |
|
- | 1443 | .ret: |
|
- | 1444 | ret |
|
1405 | 1445 | ||
1406 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
1446 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
1407 | dereference_dll: |
1447 | dereference_dll: |
1408 | sub [esi+DLLDESCR.refcount], eax |
1448 | sub [esi+DLLDESCR.refcount], eax |
1409 | jnz .ret |
1449 | jnz .ret |
Line 1417... | Line 1457... | ||
1417 | call free |
1457 | call free |
1418 | .ret: |
1458 | .ret: |
1419 | ret |
1459 | ret |
Line 1420... | Line 1460... | ||
1420 | 1460 | ||
1421 | destroy_hdll: |
1461 | destroy_hdll: |
1422 | push ebx esi edi |
1462 | push ebx ecx esi edi |
1423 | push eax |
1463 | push eax |
1424 | mov ebx, [eax+HDLL.base] |
1464 | mov ebx, [eax+HDLL.base] |
1425 | mov esi, [eax+HDLL.parent] |
1465 | mov esi, [eax+HDLL.parent] |
1426 | mov edx, [esi+DLLDESCR.size] |
1466 | mov edx, [esi+DLLDESCR.size] |
1427 | ; The following actions require the context of application where HDLL is mapped. |
1467 | ; The following actions require the context of application where HDLL is mapped. |
1428 | ; However, destroy_hdll can be called in the context of OS thread when |
1468 | ; However, destroy_hdll can be called in the context of OS thread when |
1429 | ; cleaning up objects created by the application which is destroyed. |
1469 | ; cleaning up objects created by the application which is destroyed. |
1430 | ; So remember current cr3 and set it to page table of target. |
- | |
1431 | mov eax, [eax+HDLL.pid] |
- | |
1432 | call pid_to_slot |
- | |
1433 | shl eax, 8 |
- | |
1434 | add eax, SLOT_BASE |
1470 | ; So remember current cr3 and set it to page table of target. |
1435 | mov ecx, [eax+APPDATA.dir_table] |
1471 | mov eax, [ecx+APPDATA.dir_table] |
1436 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
1472 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
1437 | ; page table from APPDATA of current thread. |
1473 | ; page table from APPDATA of current thread. |
1438 | ; Also set [current_slot] because it is used by user_free. |
1474 | ; Also set [current_slot] because it is used by user_free. |
1439 | pushf |
1475 | pushf |
1440 | cli |
1476 | cli |
1441 | push [current_slot] |
1477 | push [current_slot] |
1442 | mov [current_slot], eax |
1478 | mov [current_slot], ecx |
1443 | mov eax, cr3 |
1479 | mov ecx, cr3 |
1444 | push eax |
1480 | push ecx |
1445 | mov cr3, ecx |
1481 | mov cr3, eax |
1446 | push ebx ; argument for user_free |
1482 | push ebx ; argument for user_free |
1447 | mov eax, ebx |
1483 | mov eax, ebx |
1448 | shr ebx, 12 |
1484 | shr ebx, 12 |
1449 | push ebx |
1485 | push ebx |
Line 1480... | Line 1516... | ||
1480 | push eax |
1516 | push eax |
1481 | mov esi, [eax+HDLL.parent] |
1517 | mov esi, [eax+HDLL.parent] |
1482 | mov eax, [eax+HDLL.refcount] |
1518 | mov eax, [eax+HDLL.refcount] |
1483 | call dereference_dll |
1519 | call dereference_dll |
1484 | pop eax |
1520 | pop eax |
- | 1521 | mov edx, [eax+HDLL.bk] |
|
- | 1522 | mov ebx, [eax+HDLL.fd] |
|
- | 1523 | mov [ebx+HDLL.bk], edx |
|
1485 | call destroy_kernel_object |
1524 | mov [edx+HDLL.fd], ebx |
- | 1525 | call free |
|
1486 | pop edi esi ebx |
1526 | pop edi esi ecx ebx |
- | 1527 | ret |
|
- | 1528 | ||
- | 1529 | ; ecx -> APPDATA for slot, esi = dlls_list_ptr |
|
- | 1530 | destroy_all_hdlls: |
|
- | 1531 | test esi, esi |
|
- | 1532 | jz .ret |
|
- | 1533 | .loop: |
|
- | 1534 | mov eax, [esi+HDLL.fd] |
|
- | 1535 | cmp eax, esi |
|
- | 1536 | jz free |
|
- | 1537 | call destroy_hdll |
|
- | 1538 | jmp .loop |
|
- | 1539 | .ret: |
|
1487 | ret |
1540 | ret |
Line 1488... | Line 1541... | ||
1488 | 1541 | ||
1489 | align 4 |
1542 | align 4 |
1490 | stop_all_services: |
1543 | stop_all_services: |