Rev 1275 | Rev 1292 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1275 | Rev 1289 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2008. 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: 1275 $ |
8 | $Revision: 1289 $ |
9 | 9 | ||
Line 472... | Line 472... | ||
472 | dec [count] |
472 | dec [count] |
473 | jnz @b |
473 | jnz @b |
474 | xor eax, eax |
474 | xor eax, eax |
475 | ret |
475 | ret |
476 | .ok: |
476 | .ok: |
477 | mov ebx, [pSym] |
477 | mov eax, [pSym] |
478 | mov eax, [ebx+8] |
478 | mov eax, [eax+8] |
479 | ret |
479 | ret |
480 | endp |
480 | endp |
Line 481... | Line 481... | ||
481 | 481 | ||
482 | align 4 |
482 | align 4 |
Line 679... | Line 679... | ||
679 | xor eax, eax |
679 | xor eax, eax |
680 | ret |
680 | ret |
681 | endp |
681 | endp |
Line 682... | Line 682... | ||
682 | 682 | ||
683 | align 4 |
683 | align 4 |
684 | proc fix_coff_symbols stdcall, sec:dword, symbols:dword,\ |
684 | proc fix_coff_symbols stdcall uses ebx esi, sec:dword, symbols:dword,\ |
685 | sym_count:dword, strings:dword, imports:dword |
685 | sym_count:dword, strings:dword, imports:dword |
686 | locals |
686 | locals |
687 | retval dd ? |
687 | retval dd ? |
Line 741... | Line 741... | ||
741 | mov eax, [retval] |
741 | mov eax, [retval] |
742 | ret |
742 | ret |
743 | endp |
743 | endp |
Line 744... | Line 744... | ||
744 | 744 | ||
745 | align 4 |
745 | align 4 |
- | 746 | proc fix_coff_relocs stdcall uses ebx esi, coff:dword, sym:dword, \ |
|
746 | proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword |
747 | delta:dword |
747 | locals |
748 | locals |
748 | n_sec dd ? |
749 | n_sec dd ? |
Line 749... | Line 750... | ||
749 | endl |
750 | endl |
750 | 751 | ||
751 | mov eax, [coff] |
752 | mov eax, [coff] |
- | 753 | movzx ebx, [eax+CFH.nSections] |
|
752 | movzx ebx, [eax+CFH.nSections] |
754 | mov [n_sec], ebx |
753 | mov [n_sec], ebx |
- | |
754 | .fix_sec: |
755 | lea esi, [eax+20] |
755 | mov esi, [sec] |
756 | .fix_sec: |
Line 756... | Line 757... | ||
756 | mov edi, [esi+CFS.PtrReloc] |
757 | mov edi, [esi+CFS.PtrReloc] |
757 | add edi, [coff] |
758 | add edi, [coff] |
758 | 759 | ||
759 | movzx ecx, [esi+CFS.NumReloc] |
760 | movzx ecx, [esi+CFS.NumReloc] |
760 | test ecx, ecx |
761 | test ecx, ecx |
761 | jz .next |
762 | jz .next |
762 | .next_reloc: |
763 | .reloc_loop: |
763 | mov ebx, [edi+CRELOC.SymIndex] |
764 | mov ebx, [edi+CRELOC.SymIndex] |
Line 780... | Line 781... | ||
780 | jmp .fix |
781 | jmp .fix |
781 | .dir_32: |
782 | .dir_32: |
782 | mov eax, [edi+CRELOC.VirtualAddress] |
783 | mov eax, [edi+CRELOC.VirtualAddress] |
783 | add eax, [esi+CFS.VirtualAddress] |
784 | add eax, [esi+CFS.VirtualAddress] |
784 | .fix: |
785 | .fix: |
- | 786 | add eax, [delta] |
|
785 | add [eax], edx |
787 | add [eax], edx |
- | 788 | .next_reloc: |
|
- | 789 | add edi, 10 |
|
- | 790 | dec ecx |
|
- | 791 | jnz .reloc_loop |
|
- | 792 | .next: |
|
- | 793 | add esi, COFF_SECTION_SIZE |
|
- | 794 | dec [n_sec] |
|
- | 795 | jnz .fix_sec |
|
- | 796 | .exit: |
|
- | 797 | ret |
|
- | 798 | endp |
|
- | 799 | ||
- | 800 | proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \ |
|
- | 801 | delta:dword |
|
- | 802 | locals |
|
- | 803 | n_sec dd ? |
|
- | 804 | endl |
|
- | 805 | ||
- | 806 | mov eax, [coff] |
|
- | 807 | movzx ebx, [eax+CFH.nSections] |
|
- | 808 | mov [n_sec], ebx |
|
- | 809 | lea esi, [eax+20] |
|
- | 810 | mov edx, [delta] |
|
- | 811 | .fix_sec: |
|
- | 812 | mov edi, [esi+CFS.PtrReloc] |
|
- | 813 | add edi, [coff] |
|
- | 814 | ||
- | 815 | movzx ecx, [esi+CFS.NumReloc] |
|
- | 816 | test ecx, ecx |
|
- | 817 | jz .next |
|
- | 818 | .reloc_loop: |
|
- | 819 | cmp [edi+CRELOC.Type], 6 |
|
- | 820 | jne .next_reloc |
|
- | 821 | .dir_32: |
|
- | 822 | mov eax, [edi+CRELOC.VirtualAddress] |
|
- | 823 | add eax, [esi+CFS.VirtualAddress] |
|
- | 824 | add [eax+edx], edx |
|
- | 825 | .next_reloc: |
|
786 | add edi, 10 |
826 | add edi, 10 |
787 | dec ecx |
827 | dec ecx |
788 | jnz .next_reloc |
828 | jnz .reloc_loop |
789 | .next: |
829 | .next: |
790 | add [sec], COFF_SECTION_SIZE |
830 | add esi, COFF_SECTION_SIZE |
791 | dec [n_sec] |
831 | dec [n_sec] |
792 | jnz .fix_sec |
832 | jnz .fix_sec |
793 | .exit: |
833 | .exit: |
794 | ret |
834 | ret |
795 | endp |
835 | endp |
Line 903... | Line 943... | ||
903 | [strings], ebx |
943 | [strings], ebx |
904 | test eax, eax |
944 | test eax, eax |
905 | jz .link_fail |
945 | jz .link_fail |
Line 906... | Line 946... | ||
906 | 946 | ||
907 | mov ebx, [coff] |
- | |
908 | add ebx, 20 |
947 | mov ebx, [coff] |
Line 909... | Line -... | ||
909 | stdcall fix_coff_relocs, [coff], ebx, [sym] |
- | |
910 | 948 | stdcall fix_coff_relocs, ebx, [sym], 0 |
|
911 | mov ebx, [coff] |
949 | |
912 | stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion |
950 | stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion |
Line 913... | Line 951... | ||
913 | test eax, eax |
951 | test eax, eax |
Line 981... | Line 1019... | ||
981 | endp |
1019 | endp |
Line 982... | Line 1020... | ||
982 | 1020 | ||
983 | align 4 |
1021 | align 4 |
984 | proc load_library stdcall, file_name:dword |
1022 | proc load_library stdcall, file_name:dword |
- | 1023 | locals |
|
- | 1024 | fullname rb 260 |
|
985 | locals |
1025 | fileinfo rb 40 |
986 | coff dd ? |
- | |
987 | sym dd ? |
- | |
988 | strings dd ? |
- | |
989 | img_size dd ? |
1026 | coff dd ? |
990 | img_base dd ? |
- | |
991 | exports dd ? |
1027 | img_base dd ? |
Line 992... | Line 1028... | ||
992 | endl |
1028 | endl |
Line -... | Line 1029... | ||
- | 1029 | ||
- | 1030 | cli |
|
- | 1031 | ||
- | 1032 | ; resolve file name |
|
993 | 1033 | mov ebx, [file_name] |
|
994 | cli |
1034 | lea edi, [fullname+1] |
995 | 1035 | mov byte [edi-1], '/' |
|
Line -... | Line 1036... | ||
- | 1036 | stdcall get_full_file_name, edi, 259 |
|
- | 1037 | test al, al |
|
- | 1038 | jz .fail |
|
- | 1039 | ||
- | 1040 | ; scan for required DLL in list of already loaded for this process, |
|
- | 1041 | ; ignore timestamp |
|
- | 1042 | mov esi, [CURRENT_TASK] |
|
- | 1043 | shl esi, 8 |
|
- | 1044 | lea ebx, [esi+SLOT_BASE+APP_OBJ_OFFSET] |
|
- | 1045 | mov esi, [ebx+APPOBJ.fd] |
|
- | 1046 | lea edi, [fullname] |
|
- | 1047 | .scan_in_process: |
|
- | 1048 | cmp esi, ebx |
|
- | 1049 | jz .not_in_process |
|
- | 1050 | cmp dword [esi+APPOBJ.magic], 'HDLL' |
|
- | 1051 | jnz .next_in_process |
|
- | 1052 | mov eax, [esi+HDLL.parent] |
|
- | 1053 | add eax, DLLDESCR.name |
|
- | 1054 | stdcall strncmp, eax, edi, -1 |
|
- | 1055 | test eax, eax |
|
- | 1056 | jnz .next_in_process |
|
- | 1057 | ; simple variant: load DLL which is already loaded in this process |
|
- | 1058 | ; just increment reference counters and return address of exports table |
|
- | 1059 | inc [esi+HDLL.refcount] |
|
- | 1060 | mov ecx, [esi+HDLL.parent] |
|
- | 1061 | inc [ecx+DLLDESCR.refcount] |
|
- | 1062 | mov eax, [ecx+DLLDESCR.exports] |
|
- | 1063 | sub eax, [ecx+DLLDESCR.defaultbase] |
|
- | 1064 | add eax, [esi+HDLL.base] |
|
- | 1065 | ret |
|
- | 1066 | .next_in_process: |
|
- | 1067 | mov esi, [esi+APPOBJ.fd] |
|
- | 1068 | jmp .scan_in_process |
|
- | 1069 | .not_in_process: |
|
- | 1070 | ||
- | 1071 | ; scan in full list, compare timestamp |
|
- | 1072 | lea eax, [fileinfo] |
|
- | 1073 | stdcall get_fileinfo, edi, eax |
|
- | 1074 | test eax, eax |
|
- | 1075 | jnz .fail |
|
- | 1076 | mov esi, [dll_list.fd] |
|
- | 1077 | .scan_for_dlls: |
|
- | 1078 | cmp esi, dll_list |
|
- | 1079 | jz .load_new |
|
- | 1080 | lea eax, [esi+DLLDESCR.name] |
|
- | 1081 | stdcall strncmp, eax, edi, -1 |
|
- | 1082 | test eax, eax |
|
- | 1083 | jnz .continue_scan |
|
- | 1084 | .test_prev_dll: |
|
- | 1085 | mov eax, dword [fileinfo+24] ; last modified time |
|
- | 1086 | mov edx, dword [fileinfo+28] ; last modified date |
|
- | 1087 | cmp dword [esi+DLLDESCR.timestamp], eax |
|
- | 1088 | jnz .continue_scan |
|
- | 1089 | cmp dword [esi+DLLDESCR.timestamp+4], edx |
|
- | 1090 | jz .dll_already_loaded |
|
- | 1091 | .continue_scan: |
|
- | 1092 | mov esi, [esi+DLLDESCR.fd] |
|
- | 1093 | jmp .scan_for_dlls |
|
- | 1094 | ||
- | 1095 | ; new DLL |
|
- | 1096 | .load_new: |
|
996 | stdcall load_file, [file_name] |
1097 | ; load file |
- | 1098 | stdcall load_file, edi |
|
- | 1099 | test eax, eax |
|
- | 1100 | jz .fail |
|
- | 1101 | mov [coff], eax |
|
- | 1102 | mov dword [fileinfo+32], ebx |
|
- | 1103 | ||
- | 1104 | ; allocate DLLDESCR struct; size is DLLDESCR.sizeof plus size of DLL name |
|
- | 1105 | mov esi, edi |
|
- | 1106 | mov ecx, -1 |
|
- | 1107 | xor eax, eax |
|
- | 1108 | repnz scasb |
|
- | 1109 | not ecx |
|
- | 1110 | lea eax, [ecx+DLLDESCR.sizeof] |
|
- | 1111 | push ecx |
|
- | 1112 | call malloc |
|
- | 1113 | pop ecx |
|
- | 1114 | test eax, eax |
|
- | 1115 | jz .fail_and_free_coff |
|
- | 1116 | ; save timestamp |
|
- | 1117 | lea edi, [eax+DLLDESCR.name] |
|
- | 1118 | rep movsb |
|
- | 1119 | mov esi, eax |
|
- | 1120 | mov eax, dword [fileinfo+24] |
|
- | 1121 | mov dword [esi+DLLDESCR.timestamp], eax |
|
- | 1122 | mov eax, dword [fileinfo+28] |
|
- | 1123 | mov dword [esi+DLLDESCR.timestamp+4], eax |
|
- | 1124 | ; initialize DLLDESCR struct |
|
- | 1125 | and dword [esi+DLLDESCR.refcount], 0 ; no HDLLs yet; later it will be incremented |
|
- | 1126 | mov [esi+DLLDESCR.fd], dll_list |
|
- | 1127 | mov eax, [dll_list.bk] |
|
- | 1128 | mov [dll_list.bk], esi |
|
- | 1129 | mov [esi+DLLDESCR.bk], eax |
|
997 | test eax, eax |
1130 | mov [eax+DLLDESCR.fd], esi |
998 | jz .fail |
1131 | |
Line 999... | Line 1132... | ||
999 | 1132 | ; calculate size of loaded DLL |
|
1000 | mov [coff], eax |
1133 | mov edx, [coff] |
1001 | movzx ecx, [eax+CFH.nSections] |
1134 | movzx ecx, [edx+CFH.nSections] |
1002 | xor ebx, ebx |
1135 | xor ebx, ebx |
1003 | 1136 | ||
1004 | lea edx, [eax+20] |
1137 | add edx, 20 |
1005 | @@: |
1138 | @@: |
1006 | add ebx, [edx+CFS.SizeOfRawData] |
1139 | add ebx, [edx+CFS.SizeOfRawData] |
- | 1140 | add ebx, 15 |
|
1007 | add ebx, 15 |
1141 | and ebx, not 15 |
1008 | and ebx, not 15 |
- | |
1009 | add edx, COFF_SECTION_SIZE |
1142 | add edx, COFF_SECTION_SIZE |
- | 1143 | dec ecx |
|
- | 1144 | jnz @B |
|
- | 1145 | ; it must be nonzero and not too big |
|
- | 1146 | mov [esi+DLLDESCR.size], ebx |
|
1010 | dec ecx |
1147 | test ebx, ebx |
1011 | jnz @B |
- | |
1012 | mov [img_size], ebx |
1148 | jz .fail_and_free_dll |
- | 1149 | cmp ebx, MAX_DEFAULT_DLL_ADDR-MIN_DEFAULT_DLL_ADDR |
|
- | 1150 | ja .fail_and_free_dll |
|
- | 1151 | ; allocate memory for kernel-side image |
|
- | 1152 | stdcall kernel_alloc, ebx |
|
- | 1153 | test eax, eax |
|
- | 1154 | jz .fail_and_free_dll |
|
- | 1155 | mov [esi+DLLDESCR.data], eax |
|
- | 1156 | ; calculate preferred base address |
|
1013 | 1157 | add ebx, 0x1FFF |
|
- | 1158 | and ebx, not 0xFFF |
|
- | 1159 | mov ecx, [dll_cur_addr] |
|
- | 1160 | lea edx, [ecx+ebx] |
|
- | 1161 | cmp edx, MAX_DEFAULT_DLL_ADDR |
|
1014 | call init_heap |
1162 | jb @f |
Line -... | Line 1163... | ||
- | 1163 | mov ecx, MIN_DEFAULT_DLL_ADDR |
|
- | 1164 | lea edx, [ecx+ebx] |
|
1015 | stdcall user_alloc, [img_size] |
1165 | @@: |
1016 | 1166 | mov [esi+DLLDESCR.defaultbase], ecx |
|
1017 | test eax, eax |
1167 | mov [dll_cur_addr], edx |
- | 1168 | ||
1018 | jz .fail |
1169 | ; copy sections and set correct values for VirtualAddress'es in headers |
- | 1170 | push esi |
|
1019 | mov [img_base], eax |
1171 | mov edx, [coff] |
1020 | 1172 | movzx ebx, [edx+CFH.nSections] |
|
- | 1173 | mov edi, eax |
|
1021 | mov edx, [coff] |
1174 | add edx, 20 |
- | 1175 | xor eax, eax |
|
- | 1176 | cld |
|
1022 | movzx ebx, [edx+CFH.nSections] |
1177 | @@: |
1023 | mov edi, [img_base] |
1178 | mov [edx+CFS.VirtualAddress], ecx |
1024 | lea eax, [edx+20] |
1179 | add ecx, [edx+CFS.SizeOfRawData] |
1025 | @@: |
1180 | mov esi, [edx+CFS.PtrRawData] |
1026 | mov [eax+CFS.VirtualAddress], edi |
1181 | push ecx |
1027 | mov esi, [eax+CFS.PtrRawData] |
1182 | mov ecx, [edx+CFS.SizeOfRawData] |
1028 | test esi, esi |
- | |
1029 | jnz .copy |
- | |
1030 | add edi, [eax+CFS.SizeOfRawData] |
1183 | test esi, esi |
1031 | jmp .next |
1184 | jnz .copy |
- | 1185 | rep stosb |
|
1032 | .copy: |
1186 | jmp .next |
- | 1187 | .copy: |
|
1033 | add esi, edx |
1188 | add esi, [coff] |
- | 1189 | rep movsb |
|
1034 | mov ecx, [eax+CFS.SizeOfRawData] |
1190 | .next: |
1035 | cld |
1191 | pop ecx |
1036 | rep movsb |
1192 | add edi, 15 ;-new_app_base |
- | 1193 | add ecx, 15 |
|
Line -... | Line 1194... | ||
- | 1194 | and edi, -16 |
|
- | 1195 | and ecx, -16 |
|
- | 1196 | add edx, COFF_SECTION_SIZE |
|
- | 1197 | dec ebx |
|
1037 | .next: |
1198 | jnz @B |
- | 1199 | pop esi |
|
- | 1200 | ||
- | 1201 | ; save some additional data from COFF file |
|
- | 1202 | ; later we will use COFF header, headers for sections and symbol table |
|
1038 | add edi, 15 ;-new_app_base |
1203 | ; and also relocations table for all sections |
- | 1204 | mov edx, [coff] |
|
- | 1205 | mov ebx, [edx+CFH.pSymTable] |
|
- | 1206 | mov edi, dword [fileinfo+32] |
|
- | 1207 | sub edi, ebx |
|
- | 1208 | jc .fail_and_free_data |
|
- | 1209 | mov [esi+DLLDESCR.symbols_lim], edi |
|
- | 1210 | add ebx, edx |
|
- | 1211 | movzx ecx, [edx+CFH.nSections] |
|
- | 1212 | lea ecx, [ecx*5] |
|
- | 1213 | lea edi, [edi+ecx*8+20] |
|
- | 1214 | add edx, 20 |
|
- | 1215 | @@: |
|
- | 1216 | movzx eax, [edx+CFS.NumReloc] |
|
- | 1217 | lea eax, [eax*5] |
|
- | 1218 | lea edi, [edi+eax*2] |
|
- | 1219 | add edx, COFF_SECTION_SIZE |
|
- | 1220 | sub ecx, 5 |
|
- | 1221 | jnz @b |
|
- | 1222 | stdcall kernel_alloc, edi |
|
- | 1223 | test eax, eax |
|
1039 | and edi, -16 |
1224 | jz .fail_and_free_data |
- | 1225 | mov edx, [coff] |
|
- | 1226 | movzx ecx, [edx+CFH.nSections] |
|
- | 1227 | lea ecx, [ecx*5] |
|
- | 1228 | lea ecx, [ecx*2+5] |
|
- | 1229 | mov [esi+DLLDESCR.coff_hdr], eax |
|
1040 | add eax, COFF_SECTION_SIZE |
1230 | push esi |
- | 1231 | mov esi, edx |
|
- | 1232 | mov edi, eax |
|
- | 1233 | rep movsd |
|
- | 1234 | pop esi |
|
- | 1235 | mov [esi+DLLDESCR.symbols_ptr], edi |
|
- | 1236 | push esi |
|
- | 1237 | mov ecx, [edx+CFH.nSymbols] |
|
- | 1238 | mov [esi+DLLDESCR.symbols_num], ecx |
|
- | 1239 | mov ecx, [esi+DLLDESCR.symbols_lim] |
|
- | 1240 | mov esi, ebx |
|
- | 1241 | rep movsb |
|
- | 1242 | pop esi |
|
- | 1243 | mov ebx, [esi+DLLDESCR.coff_hdr] |
|
- | 1244 | push esi |
|
- | 1245 | movzx eax, [edx+CFH.nSections] |
|
- | 1246 | lea edx, [ebx+20] |
|
- | 1247 | @@: |
|
- | 1248 | movzx ecx, [edx+CFS.NumReloc] |
|
- | 1249 | lea ecx, [ecx*5] |
|
- | 1250 | mov esi, [edx+CFS.PtrReloc] |
|
- | 1251 | mov [edx+CFS.PtrReloc], edi |
|
- | 1252 | sub [edx+CFS.PtrReloc], ebx |
|
- | 1253 | add esi, [coff] |
|
- | 1254 | shr ecx, 1 |
|
- | 1255 | rep movsd |
|
- | 1256 | adc ecx, ecx |
|
- | 1257 | rep movsw |
|
- | 1258 | add edx, COFF_SECTION_SIZE |
|
- | 1259 | dec eax |
|
- | 1260 | jnz @b |
|
- | 1261 | pop esi |
|
1041 | dec ebx |
1262 | |
1042 | jnz @B |
- | |
1043 | 1263 | ; fixup symbols |
|
1044 | mov ebx, [edx+CFH.pSymTable] |
- | |
Line -... | Line 1264... | ||
- | 1264 | mov edx, ebx |
|
- | 1265 | mov eax, [ebx+CFH.nSymbols] |
|
1045 | add ebx, edx |
1266 | add edx, 20 |
- | 1267 | mov ecx, [esi+DLLDESCR.symbols_num] |
|
- | 1268 | lea ecx, [ecx*9] |
|
- | 1269 | add ecx, ecx |
|
Line 1046... | Line 1270... | ||
1046 | mov [sym], ebx |
1270 | add ecx, [esi+DLLDESCR.symbols_ptr] |
1047 | mov ecx, [edx+CFH.nSymbols] |
- | |
1048 | add ecx,ecx |
1271 | |
1049 | lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE |
1272 | stdcall fix_coff_symbols, edx, [esi+DLLDESCR.symbols_ptr], eax,\ |
Line -... | Line 1273... | ||
- | 1273 | ecx, 0 |
|
1050 | add ecx, [sym] |
1274 | ; test eax, eax |
1051 | mov [strings], ecx |
- | |
1052 | - | ||
1053 | lea eax, [edx+20] |
1275 | ; jnz @F |
1054 | - | ||
1055 | stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\ |
- | |
1056 | [strings], dword 0 |
- | |
1057 | test eax, eax |
- | |
1058 | jnz @F |
- | |
1059 | - | ||
Line -... | Line 1276... | ||
- | 1276 | ; |
|
- | 1277 | ;@@: |
|
- | 1278 | ||
1060 | @@: |
1279 | stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],szEXPORTS |
- | 1280 | test eax, eax |
|
1061 | mov edx, [coff] |
1281 | jnz @F |
Line 1062... | Line 1282... | ||
1062 | movzx ebx, [edx+CFH.nSections] |
1282 | |
- | 1283 | stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],sz_EXPORTS |
|
- | 1284 | @@: |
|
- | 1285 | mov [esi+DLLDESCR.exports], eax |
|
- | 1286 | ||
- | 1287 | ; fix relocs in the hidden copy in kernel memory to default address |
|
- | 1288 | ; it is first fix; usually this will be enough, but second fix |
|
- | 1289 | ; can be necessary if real load address will not equal assumption |
|
- | 1290 | mov eax, [esi+DLLDESCR.data] |
|
1063 | mov edi, new_app_base |
1291 | sub eax, [esi+DLLDESCR.defaultbase] |
1064 | lea eax, [edx+20] |
1292 | stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax |
1065 | @@: |
1293 | |
- | 1294 | stdcall kernel_free, [coff] |
|
- | 1295 | ||
- | 1296 | .dll_already_loaded: |
|
- | 1297 | inc [esi+DLLDESCR.refcount] |
|
- | 1298 | push esi |
|
- | 1299 | call init_heap |
|
- | 1300 | pop esi |
|
- | 1301 | ||
- | 1302 | mov edi, [esi+DLLDESCR.size] |
|
- | 1303 | stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi |
|
- | 1304 | test eax, eax |
|
- | 1305 | jnz @f |
|
- | 1306 | stdcall user_alloc, edi |
|
- | 1307 | test eax, eax |
|
- | 1308 | jz .fail_and_dereference |
|
- | 1309 | @@: |
|
- | 1310 | mov [img_base], eax |
|
- | 1311 | mov ebx, [CURRENT_TASK] |
|
- | 1312 | shl ebx, 5 |
|
- | 1313 | add ebx, [CURRENT_TASK+ebx+TASKDATA.pid] |
|
- | 1314 | mov eax, HDLL.sizeof |
|
- | 1315 | call create_kernel_object |
|
- | 1316 | test eax, eax |
|
- | 1317 | jz .fail_and_free_user |
|
- | 1318 | mov [eax+APPOBJ.magic], 'HDLL' |
|
- | 1319 | mov [eax+APPOBJ.destroy], destroy_hdll |
|
- | 1320 | mov ebx, [img_base] |
|
- | 1321 | mov [eax+HDLL.base], ebx |
|
- | 1322 | mov [eax+HDLL.size], edi |
|
- | 1323 | mov [eax+HDLL.refcount], 1 |
|
- | 1324 | mov [eax+HDLL.parent], esi |
|
- | 1325 | mov edx, ebx |
|
- | 1326 | shr edx, 12 |
|
- | 1327 | or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK |
|
- | 1328 | ; copy entries of page table from kernel-side image to usermode |
|
- | 1329 | ; use copy-on-write for user-mode image, so map as readonly |
|
- | 1330 | xor edi, edi |
|
- | 1331 | mov ecx, [esi+DLLDESCR.data] |
|
- | 1332 | shr ecx, 12 |
|
- | 1333 | .map_pages_loop: |
|
- | 1334 | mov eax, [page_tabs+ecx*4] |
|
- | 1335 | and eax, not 0xFFF |
|
Line -... | Line 1336... | ||
- | 1336 | or al, PG_USER |
|
1066 | add [eax+CFS.VirtualAddress], edi ;patch user space offset |
1337 | xchg eax, [page_tabs+edx*4] |
- | 1338 | test al, 1 |
|
- | 1339 | jz @f |
|
1067 | add eax, COFF_SECTION_SIZE |
1340 | call free_page |
1068 | dec ebx |
1341 | @@: |
- | 1342 | invlpg [ebx+edi] |
|
- | 1343 | inc ecx |
|
- | 1344 | inc edx |
|
- | 1345 | add edi, 0x1000 |
|
- | 1346 | cmp edi, [esi+DLLDESCR.size] |
|
- | 1347 | jb .map_pages_loop |
|
- | 1348 | ||
- | 1349 | ; if real user-mode base is not equal to preferred base, relocate image |
|
1069 | jnz @B |
1350 | mov ebx, [img_base] |
- | 1351 | sub ebx, [esi+DLLDESCR.defaultbase] |
|
- | 1352 | jz @f |
|
1070 | 1353 | stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx |
|
1071 | add edx, 20 |
- | |
1072 | stdcall fix_coff_relocs, [coff], edx, [sym] |
- | |
1073 | 1354 | @@: |
|
1074 | mov ebx, [coff] |
1355 | |
1075 | stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szEXPORTS |
1356 | mov eax, [esi+DLLDESCR.exports] |
- | 1357 | sub eax, [esi+DLLDESCR.defaultbase] |
|
- | 1358 | add eax, [img_base] |
|
- | 1359 | ret |
|
- | 1360 | .fail_and_free_data: |
|
- | 1361 | stdcall kernel_free, [esi+DLLDESCR.data] |
|
- | 1362 | .fail_and_free_dll: |
|
- | 1363 | mov eax, esi |
|
1076 | test eax, eax |
1364 | call free |
Line -... | Line 1365... | ||
- | 1365 | .fail_and_free_coff: |
|
- | 1366 | stdcall kernel_free, [coff] |
|
- | 1367 | .fail: |
|
- | 1368 | xor eax, eax |
|
- | 1369 | ret |
|
- | 1370 | .fail_and_free_user: |
|
- | 1371 | stdcall user_free, [img_base] |
|
- | 1372 | .fail_and_dereference: |
|
- | 1373 | mov eax, 1 ; delete 1 reference |
|
- | 1374 | call dereference_dll |
|
- | 1375 | xor eax, eax |
|
- | 1376 | ret |
|
- | 1377 | endp |
|
- | 1378 | ||
- | 1379 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
|
- | 1380 | dereference_dll: |
|
- | 1381 | sub [esi+DLLDESCR.refcount], eax |
|
- | 1382 | jnz .ret |
|
- | 1383 | mov eax, [esi+DLLDESCR.fd] |
|
- | 1384 | mov edx, [esi+DLLDESCR.bk] |
|
- | 1385 | mov [eax+DLLDESCR.bk], edx |
|
- | 1386 | mov [edx+DLLDESCR.fd], eax |
|
- | 1387 | stdcall kernel_free, [esi+DLLDESCR.symbols_ptr] |
|
- | 1388 | stdcall kernel_free, [esi+DLLDESCR.data] |
|
- | 1389 | mov eax, esi |
|
- | 1390 | call free |
|
- | 1391 | .ret: |
|
- | 1392 | ret |
|
- | 1393 | ||
- | 1394 | destroy_hdll: |
|
- | 1395 | push ebx esi edi |
|
- | 1396 | push eax |
|
- | 1397 | mov ebx, [eax+HDLL.base] |
|
- | 1398 | push ebx ; argument for user_free |
|
- | 1399 | push eax |
|
- | 1400 | mov esi, [eax+HDLL.parent] |
|
- | 1401 | mov edx, [esi+DLLDESCR.size] |
|
- | 1402 | mov eax, ebx |
|
- | 1403 | shr ebx, 12 |
|
- | 1404 | push ebx |
|
- | 1405 | mov esi, [esi+DLLDESCR.data] |
|
- | 1406 | shr esi, 12 |
|
- | 1407 | .unmap_loop: |
|
- | 1408 | push eax |
|
- | 1409 | mov eax, 2 |
|
- | 1410 | xchg eax, [page_tabs+ebx*4] |
|
- | 1411 | cmp eax, [page_tabs+esi*4] |
|
- | 1412 | jnz @f |
|
- | 1413 | call free_page |
|
- | 1414 | @@: |
|
- | 1415 | pop eax |
|
- | 1416 | invlpg [eax] |
|
- | 1417 | add eax, 0x1000 |
|
- | 1418 | inc ebx |
|
1077 | jnz @F |
1419 | inc esi |
1078 | 1420 | sub edx, 0x1000 |
|
1079 | mov ebx, [coff] |
1421 | ja .unmap_loop |
1080 | stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],sz_EXPORTS |
1422 | pop ebx eax |
1081 | @@: |
1423 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |