Rev 4423 | Rev 5565 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4423 | Rev 5201 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2012. 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: 4423 $ |
8 | $Revision: 5201 $ |
9 | 9 | ||
Line 121... | Line 121... | ||
121 | cmp edx, srv.fd-SRV.fd |
121 | cmp edx, srv.fd-SRV.fd |
122 | je .not_load |
122 | je .not_load |
Line 123... | Line 123... | ||
123 | 123 | ||
124 | stdcall strncmp, edx, [sz_name], 16 |
124 | stdcall strncmp, edx, [sz_name], 16 |
- | 125 | test eax, eax |
|
125 | test eax, eax |
126 | mov eax, edx |
Line 126... | Line 127... | ||
126 | je .ok |
127 | je .nothing |
127 | 128 | ||
128 | mov edx, [edx+SRV.fd] |
129 | mov edx, [edx+SRV.fd] |
129 | jmp @B |
130 | jmp @B |
130 | .not_load: |
- | |
131 | mov eax, [sz_name] |
131 | .not_load: |
132 | ; Try to load .dll driver first. If not, fallback to .obj. |
132 | mov eax, [sz_name] |
133 | push edi |
133 | push edi |
134 | sub esp, 36 |
134 | sub esp, 36 |
135 | mov edi, esp |
135 | mov edi, esp |
Line 148... | Line 148... | ||
148 | mov byte [edi+16], 0 |
148 | mov byte [edi+16], 0 |
149 | mov edi, esp |
149 | mov edi, esp |
150 | stdcall load_pe_driver, edi, 0 |
150 | stdcall load_pe_driver, edi, 0 |
151 | add esp, 36 |
151 | add esp, 36 |
152 | pop edi |
152 | pop edi |
153 | test eax, eax |
- | |
154 | jnz .nothing |
- | |
155 | pop ebp |
- | |
156 | jmp load_driver |
- | |
157 | .ok: |
- | |
158 | mov eax, edx |
- | |
159 | .nothing: |
153 | .nothing: |
160 | ret |
154 | ret |
161 | endp |
155 | endp |
Line 162... | Line 156... | ||
162 | 156 | ||
Line 792... | Line 786... | ||
792 | jnz .fix_sec |
786 | jnz .fix_sec |
793 | .exit: |
787 | .exit: |
794 | ret |
788 | ret |
795 | endp |
789 | endp |
Line 796... | Line -... | ||
796 | - | ||
797 | align 4 |
- | |
798 | proc load_driver stdcall, driver_name:dword |
- | |
799 | locals |
- | |
800 | coff dd ? |
- | |
801 | sym dd ? |
- | |
802 | strings dd ? |
- | |
803 | img_size dd ? |
- | |
804 | img_base dd ? |
- | |
805 | start dd ? |
- | |
806 | - | ||
807 | file_name rb 13+16+4+1 ; '/sys/drivers/ |
- | |
808 | endl |
- | |
809 | - | ||
810 | lea edx, [file_name] |
- | |
811 | mov dword [edx], '/sys' |
- | |
812 | mov dword [edx+4], '/dri' |
- | |
813 | mov dword [edx+8], 'vers' |
- | |
814 | mov byte [edx+12], '/' |
- | |
815 | mov esi, [driver_name] |
- | |
816 | .redo: |
- | |
817 | lea edx, [file_name] |
- | |
818 | lea edi, [edx+13] |
- | |
819 | mov ecx, 16 |
- | |
820 | @@: |
- | |
821 | lodsb |
- | |
822 | test al, al |
- | |
823 | jz @f |
- | |
824 | stosb |
- | |
825 | loop @b |
- | |
826 | @@: |
- | |
827 | mov dword [edi], '.obj' |
- | |
828 | mov byte [edi+4], 0 |
- | |
829 | stdcall load_file, edx |
- | |
830 | - | ||
831 | test eax, eax |
- | |
832 | jz .exit |
- | |
833 | - | ||
834 | mov [coff], eax |
- | |
835 | - | ||
836 | movzx ecx, [eax+COFF_HEADER.nSections] |
- | |
837 | xor ebx, ebx |
- | |
838 | - | ||
839 | lea edx, [eax+20] |
- | |
840 | @@: |
- | |
841 | add ebx, [edx+COFF_SECTION.SizeOfRawData] |
- | |
842 | add ebx, 15 |
- | |
843 | and ebx, not 15 |
- | |
844 | add edx, sizeof.COFF_SECTION |
- | |
845 | dec ecx |
- | |
846 | jnz @B |
- | |
847 | mov [img_size], ebx |
- | |
848 | - | ||
849 | stdcall kernel_alloc, ebx |
- | |
850 | test eax, eax |
- | |
851 | jz .fail |
- | |
852 | mov [img_base], eax |
- | |
853 | - | ||
854 | mov edi, eax |
- | |
855 | xor eax, eax |
- | |
856 | mov ecx, [img_size] |
- | |
857 | add ecx, 4095 |
- | |
858 | and ecx, not 4095 |
- | |
859 | shr ecx, 2 |
- | |
860 | cld |
- | |
861 | rep stosd |
- | |
862 | - | ||
863 | mov edx, [coff] |
- | |
864 | movzx ebx, [edx+COFF_HEADER.nSections] |
- | |
865 | mov edi, [img_base] |
- | |
866 | lea eax, [edx+20] |
- | |
867 | @@: |
- | |
868 | mov [eax+COFF_SECTION.VirtualAddress], edi |
- | |
869 | mov esi, [eax+COFF_SECTION.PtrRawData] |
- | |
870 | test esi, esi |
- | |
871 | jnz .copy |
- | |
872 | add edi, [eax+COFF_SECTION.SizeOfRawData] |
- | |
873 | jmp .next |
- | |
874 | .copy: |
- | |
875 | add esi, edx |
- | |
876 | mov ecx, [eax+COFF_SECTION.SizeOfRawData] |
- | |
877 | cld |
- | |
878 | rep movsb |
- | |
879 | .next: |
- | |
880 | add edi, 15 |
- | |
881 | and edi, not 15 |
- | |
882 | add eax, sizeof.COFF_SECTION |
- | |
883 | dec ebx |
- | |
884 | jnz @B |
- | |
885 | - | ||
886 | mov ebx, [edx+COFF_HEADER.pSymTable] |
- | |
887 | add ebx, edx |
- | |
888 | mov [sym], ebx |
- | |
889 | mov ecx, [edx+COFF_HEADER.nSymbols] |
- | |
890 | add ecx, ecx |
- | |
891 | lea ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
- | |
892 | add ecx, [sym] |
- | |
893 | mov [strings], ecx |
- | |
894 | - | ||
895 | lea eax, [edx+20] |
- | |
896 | - | ||
897 | stdcall fix_coff_symbols, eax, [sym], [edx+COFF_HEADER.nSymbols], \ |
- | |
898 | [strings], __exports |
- | |
899 | test eax, eax |
- | |
900 | jz .link_fail |
- | |
901 | - | ||
902 | mov ebx, [coff] |
- | |
903 | stdcall fix_coff_relocs, ebx, [sym], 0 |
- | |
904 | - | ||
905 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szVersion |
- | |
906 | test eax, eax |
- | |
907 | jz .link_fail |
- | |
908 | - | ||
909 | mov eax, [eax] |
- | |
910 | shr eax, 16 |
- | |
911 | cmp eax, DRV_COMPAT |
- | |
912 | jb .ver_fail |
- | |
913 | - | ||
914 | cmp eax, DRV_CURRENT |
- | |
915 | ja .ver_fail |
- | |
916 | - | ||
917 | mov ebx, [coff] |
- | |
918 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szSTART |
- | |
919 | mov [start], eax |
- | |
920 | - | ||
921 | stdcall kernel_free, [coff] |
- | |
922 | - | ||
923 | mov ebx, [start] |
- | |
924 | stdcall ebx, DRV_ENTRY |
- | |
925 | test eax, eax |
- | |
926 | jnz .ok |
- | |
927 | - | ||
928 | stdcall kernel_free, [img_base] |
- | |
929 | - | ||
930 | xor eax, eax |
- | |
931 | ret |
- | |
932 | .ok: |
- | |
933 | mov ebx, [img_base] |
- | |
934 | mov [eax+SRV.base], ebx |
- | |
935 | mov ecx, [start] |
- | |
936 | mov [eax+SRV.entry], ecx |
- | |
937 | ret |
- | |
938 | - | ||
939 | .ver_fail: |
- | |
940 | mov esi, msg_CR |
- | |
941 | call sys_msg_board_str |
- | |
942 | mov esi, [driver_name] |
- | |
943 | call sys_msg_board_str |
- | |
944 | mov esi, msg_CR |
- | |
945 | call sys_msg_board_str |
- | |
946 | mov esi, msg_version |
- | |
947 | call sys_msg_board_str |
- | |
948 | mov esi, msg_www |
- | |
949 | call sys_msg_board_str |
- | |
950 | jmp .cleanup |
- | |
951 | - | ||
952 | .link_fail: |
- | |
953 | mov esi, msg_module |
- | |
954 | call sys_msg_board_str |
- | |
955 | mov esi, [driver_name] |
- | |
956 | call sys_msg_board_str |
- | |
957 | mov esi, msg_CR |
- | |
958 | call sys_msg_board_str |
- | |
959 | .cleanup: |
- | |
960 | stdcall kernel_free, [img_base] |
- | |
961 | .fail: |
- | |
962 | stdcall kernel_free, [coff] |
- | |
963 | .exit: |
- | |
964 | xor eax, eax |
- | |
965 | ret |
- | |
966 | endp |
- | |
967 | 790 | ||
968 | ; in: edx -> COFF_SECTION struct |
791 | ; in: edx -> COFF_SECTION struct |
969 | ; out: eax = alignment as mask for bits to drop |
792 | ; out: eax = alignment as mask for bits to drop |
970 | coff_get_align: |
793 | coff_get_align: |
971 | ; Rules: |
794 | ; Rules: |
Line 1007... | Line 830... | ||
1007 | 830 | ||
1008 | ; scan for required DLL in list of already loaded for this process, |
831 | ; scan for required DLL in list of already loaded for this process, |
1009 | ; ignore timestamp |
832 | ; ignore timestamp |
Line 1010... | Line 833... | ||
1010 | cli |
833 | cli |
1011 | - | ||
1012 | mov esi, [CURRENT_TASK] |
834 | |
1013 | shl esi, 8 |
835 | mov esi, [current_process] |
1014 | lea edi, [fullname] |
836 | lea edi, [fullname] |
1015 | mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr] |
837 | mov ebx, [esi+PROC.dlls_list_ptr] |
1016 | test ebx, ebx |
838 | test ebx, ebx |
1017 | jz .not_in_process |
839 | jz .not_in_process |
1018 | mov esi, [ebx+HDLL.fd] |
840 | mov esi, [ebx+HDLL.fd] |
Line 1370... | Line 1192... | ||
1370 | ; DLL is per-process object, so APPDATA.dlls_list_ptr must be |
1192 | ; DLL is per-process object, so APPDATA.dlls_list_ptr must be |
1371 | ; kept in sync for all threads of one process. |
1193 | ; kept in sync for all threads of one process. |
1372 | ; out: eax = APPDATA.dlls_list_ptr if all is OK, |
1194 | ; out: eax = APPDATA.dlls_list_ptr if all is OK, |
1373 | ; NULL if memory allocation failed |
1195 | ; NULL if memory allocation failed |
1374 | init_dlls_in_thread: |
1196 | init_dlls_in_thread: |
1375 | mov ebx, [current_slot] |
1197 | mov ebx, [current_process] |
1376 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
1198 | mov eax, [ebx+PROC.dlls_list_ptr] |
1377 | test eax, eax |
1199 | test eax, eax |
1378 | jnz .ret |
1200 | jnz .ret |
1379 | push [ebx+APPDATA.dir_table] |
- | |
- | 1201 | ||
1380 | mov eax, 8 |
1202 | mov eax, 8 |
1381 | call malloc |
1203 | call malloc ; FIXME |
1382 | pop edx |
- | |
1383 | test eax, eax |
1204 | test eax, eax |
1384 | jz .ret |
1205 | jz .ret |
- | 1206 | ||
1385 | mov [eax], eax |
1207 | mov [eax], eax |
1386 | mov [eax+4], eax |
1208 | mov [eax+4], eax |
1387 | mov ecx, [TASK_COUNT] |
- | |
1388 | mov ebx, SLOT_BASE+256 |
- | |
1389 | .set: |
1209 | |
1390 | cmp [ebx+APPDATA.dir_table], edx |
1210 | mov ebx, [current_process] |
1391 | jnz @f |
- | |
1392 | mov [ebx+APPDATA.dlls_list_ptr], eax |
1211 | mov [ebx+PROC.dlls_list_ptr], eax |
1393 | @@: |
- | |
1394 | add ebx, 256 |
- | |
1395 | dec ecx |
- | |
1396 | jnz .set |
- | |
1397 | .ret: |
1212 | .ret: |
1398 | ret |
1213 | ret |
Line 1399... | Line 1214... | ||
1399 | 1214 | ||
1400 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
1215 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
Line 1412... | Line 1227... | ||
1412 | .ret: |
1227 | .ret: |
1413 | ret |
1228 | ret |
Line 1414... | Line 1229... | ||
1414 | 1229 | ||
1415 | destroy_hdll: |
1230 | destroy_hdll: |
1416 | push ebx ecx esi edi |
- | |
1417 | push eax |
1231 | push ebx ecx esi edi |
1418 | mov ebx, [eax+HDLL.base] |
1232 | mov ebx, [eax+HDLL.base] |
1419 | mov esi, [eax+HDLL.parent] |
1233 | mov esi, [eax+HDLL.parent] |
1420 | mov edx, [esi+DLLDESCR.size] |
- | |
1421 | ; The following actions require the context of application where HDLL is mapped. |
- | |
1422 | ; However, destroy_hdll can be called in the context of OS thread when |
- | |
1423 | ; cleaning up objects created by the application which is destroyed. |
- | |
1424 | ; So remember current cr3 and set it to page table of target. |
- | |
1425 | mov eax, [ecx+APPDATA.dir_table] |
- | |
1426 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
- | |
1427 | ; page table from APPDATA of current thread. |
- | |
1428 | ; Also set [current_slot] because it is used by user_free. |
- | |
1429 | pushf |
- | |
1430 | cli |
- | |
1431 | push [current_slot] |
- | |
1432 | mov [current_slot], ecx |
- | |
1433 | mov ecx, cr3 |
- | |
1434 | push ecx |
- | |
1435 | mov cr3, eax |
- | |
1436 | push ebx ; argument for user_free |
- | |
1437 | mov eax, ebx |
- | |
1438 | shr ebx, 12 |
- | |
1439 | push ebx |
- | |
1440 | mov esi, [esi+DLLDESCR.data] |
- | |
1441 | shr esi, 12 |
- | |
1442 | .unmap_loop: |
- | |
1443 | push eax |
- | |
1444 | mov eax, 2 |
- | |
1445 | xchg eax, [page_tabs+ebx*4] |
- | |
1446 | mov ecx, [page_tabs+esi*4] |
- | |
1447 | and eax, not 0xFFF |
- | |
1448 | and ecx, not 0xFFF |
- | |
1449 | cmp eax, ecx |
- | |
1450 | jz @f |
- | |
1451 | call free_page |
1234 | mov edx, [esi+DLLDESCR.size] |
1452 | @@: |
- | |
1453 | pop eax |
- | |
1454 | invlpg [eax] |
- | |
1455 | add eax, 0x1000 |
- | |
1456 | inc ebx |
- | |
1457 | inc esi |
- | |
1458 | sub edx, 0x1000 |
- | |
1459 | ja .unmap_loop |
- | |
1460 | pop ebx |
- | |
1461 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |
- | |
1462 | call user_free |
- | |
1463 | ; Restore context. |
- | |
1464 | pop eax |
- | |
1465 | mov cr3, eax |
- | |
1466 | pop [current_slot] |
- | |
1467 | popf |
- | |
1468 | ; Ok, cheating is done. |
- | |
1469 | pop eax |
1235 | |
1470 | push eax |
1236 | push eax |
1471 | mov esi, [eax+HDLL.parent] |
1237 | mov esi, [eax+HDLL.parent] |
1472 | mov eax, [eax+HDLL.refcount] |
1238 | mov eax, [eax+HDLL.refcount] |
1473 | call dereference_dll |
1239 | call dereference_dll |