Rev 6758 | Rev 7124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
6502 | pathoswith | 3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
||
2288 | clevermous | 5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 6792 $ |
||
9 | |||
10 | |||
11 | GREEDY_KERNEL equ 0 |
||
12 | |||
2384 | hidnplayr | 13 | struct APP_HEADER_00_ |
14 | banner dq ? |
||
15 | version dd ? ;+8 |
||
16 | start dd ? ;+12 |
||
17 | i_end dd ? ;+16 |
||
18 | mem_size dd ? ;+20 |
||
19 | i_param dd ? ;+24 |
||
20 | ends |
||
2288 | clevermous | 21 | |
2384 | hidnplayr | 22 | struct APP_HEADER_01_ |
23 | banner dq ? |
||
24 | version dd ? ;+8 |
||
25 | start dd ? ;+12 |
||
26 | i_end dd ? ;+16 |
||
27 | mem_size dd ? ;+20 |
||
28 | stack_top dd ? ;+24 |
||
29 | i_param dd ? ;+28 |
||
30 | i_icon dd ? ;+32 |
||
31 | ends |
||
2288 | clevermous | 32 | |
6333 | serge | 33 | struct APP_HDR |
34 | cmdline rd 1 ;0x00 |
||
35 | path rd 1 ;0x04 |
||
36 | eip rd 1 ;0x08 |
||
37 | esp rd 1 ;0x0C |
||
38 | _edata rd 1 ;0x10 |
||
39 | _emem rd 1 ;0x14 |
||
40 | img_base rd 1 ;0x18 |
||
41 | img_size rd 1 |
||
42 | filename_size rd 1 |
||
43 | cmdline_size rd 1 |
||
6502 | pathoswith | 44 | path_string rd 1 |
2384 | hidnplayr | 45 | ends |
2288 | clevermous | 46 | |
47 | macro _clear_ op |
||
48 | { mov ecx, op/4 |
||
49 | xor eax, eax |
||
50 | cld |
||
51 | rep stosd |
||
52 | } |
||
53 | |||
6333 | serge | 54 | align 4 |
55 | _strnlen: |
||
56 | mov edx, ecx |
||
57 | xor eax, eax |
||
58 | repne scasb |
||
59 | jne @F |
||
60 | inc ecx |
||
61 | @@: |
||
62 | mov eax, edx |
||
63 | sub eax, ecx |
||
64 | retn |
||
65 | |||
2288 | clevermous | 66 | fs_execute_from_sysdir: |
67 | xor ebx, ebx |
||
68 | fs_execute_from_sysdir_param: |
||
6792 | pathoswith | 69 | stdcall kernel_alloc, maxPathLength |
70 | push eax ebx |
||
71 | mov esi, ebp |
||
72 | mov edi, eax |
||
73 | xor eax, eax |
||
74 | call getFullPath |
||
75 | pop ecx ebx |
||
2288 | clevermous | 76 | xor edx, edx |
77 | proc fs_execute |
||
6792 | pathoswith | 78 | ; edx = flags |
79 | ; ecx -> cmdline |
||
80 | ; ebx -> absolute file path |
||
81 | ; eax = string length |
||
6502 | pathoswith | 82 | locals |
83 | cmdline rd 1 |
||
84 | flags rd 1 |
||
85 | slot rd 1 |
||
86 | slot_base rd 1 |
||
87 | ; app header data |
||
88 | hdr_cmdline rd 1 |
||
89 | hdr_path rd 1 |
||
90 | hdr_eip rd 1 |
||
91 | hdr_esp rd 1 |
||
92 | hdr_edata rd 1 |
||
93 | hdr_emem rd 1 |
||
94 | file_base rd 1 |
||
95 | file_size rd 1 |
||
96 | filename_size rd 1 |
||
97 | cmdline_size rd 1 |
||
98 | path_string rd 1 |
||
99 | endl |
||
2288 | clevermous | 100 | |
6333 | serge | 101 | mov [flags], edx |
6792 | pathoswith | 102 | mov [cmdline], ecx |
103 | mov [path_string], ebx |
||
104 | mov [filename_size], eax |
||
105 | mov esi, -ERROR_FILE_NOT_FOUND |
||
6502 | pathoswith | 106 | test eax, eax |
107 | jz .err_file |
||
6792 | pathoswith | 108 | stdcall load_file, ebx |
2288 | clevermous | 109 | test eax, eax |
110 | jz .err_file |
||
111 | |||
112 | mov [file_base], eax |
||
113 | mov [file_size], ebx |
||
114 | lea ebx, [hdr_cmdline] |
||
115 | call test_app_header |
||
116 | mov esi, -0x1F |
||
117 | test eax, eax |
||
118 | jz .err_hdr |
||
119 | |||
3534 | clevermous | 120 | call lock_application_table |
5130 | serge | 121 | call alloc_thread_slot |
6502 | pathoswith | 122 | mov esi, -0x20 ; too many processes |
2288 | clevermous | 123 | test eax, eax |
6333 | serge | 124 | jz .err_0 |
2288 | clevermous | 125 | |
126 | mov [slot], eax |
||
127 | shl eax, 8 |
||
6333 | serge | 128 | lea edi, [SLOT_BASE+eax] |
129 | mov [slot_base], edi |
||
6502 | pathoswith | 130 | ; clean extended information about process |
6333 | serge | 131 | mov ecx, 256/4 |
132 | xor eax, eax |
||
133 | cld |
||
134 | rep stosd |
||
2288 | clevermous | 135 | ; write application name |
6502 | pathoswith | 136 | stdcall strrchr, [path_string], '/' |
137 | lea esi, [eax+1] ; -> name without path |
||
138 | mov ecx, 11 |
||
139 | mov edi, [slot_base] |
||
2288 | clevermous | 140 | @@: |
6502 | pathoswith | 141 | call utf8to16 |
142 | call uni2ansi_char |
||
2288 | clevermous | 143 | cmp al, '.' |
6502 | pathoswith | 144 | jz @f |
2288 | clevermous | 145 | test al, al |
6502 | pathoswith | 146 | jz @f |
2288 | clevermous | 147 | stosb |
6502 | pathoswith | 148 | loop @b |
149 | @@: |
||
6333 | serge | 150 | mov edi, [cmdline] |
151 | xor eax, eax |
||
152 | test edi, edi |
||
6502 | pathoswith | 153 | jz @f |
6333 | serge | 154 | mov ecx, 65535 |
155 | call _strnlen |
||
156 | cmp eax, 256 |
||
6502 | pathoswith | 157 | jb @f |
6333 | serge | 158 | lea ebx, [eax+1] |
159 | add [hdr_emem], ebx |
||
160 | @@: |
||
161 | mov [cmdline_size], eax |
||
162 | stdcall create_process, [hdr_emem] |
||
6502 | pathoswith | 163 | mov esi, -30 ; no memory |
2288 | clevermous | 164 | test eax, eax |
6333 | serge | 165 | jz .err_hdr |
2288 | clevermous | 166 | |
6263 | serge | 167 | mov ebx, [sys_proc+LHEAD.prev] |
168 | __list_add eax, ebx, sys_proc |
||
6333 | serge | 169 | mov ebx, [hdr_emem] |
5130 | serge | 170 | mov [eax+PROC.mem_used], ebx |
2288 | clevermous | 171 | mov ebx, [slot_base] |
5130 | serge | 172 | mov [ebx+APPDATA.process], eax |
173 | lea edx, [ebx+APPDATA.list] |
||
174 | lea ecx, [eax+PROC.thr_list] |
||
175 | list_add_tail edx, ecx |
||
6502 | pathoswith | 176 | mov eax, [cmdline_size] |
177 | add eax, sizeof.APP_HDR |
||
178 | stdcall kernel_alloc, eax |
||
6333 | serge | 179 | mov [ebx+APPDATA.exec_params], eax |
180 | mov edi, eax |
||
181 | lea esi, [hdr_cmdline] |
||
182 | mov ecx, sizeof.APP_HDR/4 |
||
183 | rep movsd |
||
184 | mov ecx, [cmdline_size] |
||
185 | mov esi, [cmdline] |
||
186 | rep movsb |
||
2288 | clevermous | 187 | lea eax, [hdr_cmdline] |
6333 | serge | 188 | stdcall set_app_params , [slot], eax, [flags] |
6502 | pathoswith | 189 | mov eax, [process_number] ;set result |
6333 | serge | 190 | call unlock_application_table |
191 | ret |
||
2288 | clevermous | 192 | |
6333 | serge | 193 | .err_0: |
3534 | clevermous | 194 | call unlock_application_table |
2288 | clevermous | 195 | .err_hdr: |
196 | stdcall kernel_free, [file_base] |
||
197 | .err_file: |
||
6502 | pathoswith | 198 | stdcall kernel_free, [path_string] |
2288 | clevermous | 199 | mov eax, esi |
200 | ret |
||
201 | endp |
||
202 | |||
203 | align 4 |
||
204 | test_app_header: |
||
205 | virtual at eax |
||
2384 | hidnplayr | 206 | APP_HEADER_00 APP_HEADER_00_ |
2288 | clevermous | 207 | end virtual |
208 | virtual at eax |
||
2384 | hidnplayr | 209 | APP_HEADER_01 APP_HEADER_01_ |
2288 | clevermous | 210 | end virtual |
211 | |||
212 | cmp dword [eax], 'MENU' |
||
213 | jne .fail |
||
214 | cmp word [eax+4], 'ET' |
||
215 | jne .fail |
||
216 | |||
217 | cmp [eax+6], word '00' |
||
218 | jne .check_01_header |
||
219 | |||
220 | mov ecx, [APP_HEADER_00.start] |
||
6333 | serge | 221 | mov [ebx+APP_HDR.eip], ecx |
2288 | clevermous | 222 | mov edx, [APP_HEADER_00.mem_size] |
6333 | serge | 223 | mov [ebx+APP_HDR._emem], edx |
2288 | clevermous | 224 | shr edx, 1 |
225 | sub edx, 0x10 |
||
6333 | serge | 226 | mov [ebx+APP_HDR.esp], edx |
2288 | clevermous | 227 | mov ecx, [APP_HEADER_00.i_param] |
6333 | serge | 228 | mov [ebx+APP_HDR.cmdline], ecx |
229 | mov [ebx+APP_HDR.path], 0 |
||
2288 | clevermous | 230 | mov edx, [APP_HEADER_00.i_end] |
6333 | serge | 231 | mov [ebx+APP_HDR._edata], edx |
2288 | clevermous | 232 | ret |
233 | |||
234 | .check_01_header: |
||
235 | |||
236 | cmp [eax+6], word '01' |
||
237 | je @f |
||
238 | cmp [eax+6], word '02' |
||
239 | jne .fail |
||
240 | @@: |
||
241 | mov ecx, [APP_HEADER_01.start] |
||
6333 | serge | 242 | mov [ebx+0x08], ecx |
2288 | clevermous | 243 | mov edx, [APP_HEADER_01.mem_size] |
244 | |||
245 | ; \begin{diamond}[20.08.2006] |
||
246 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
||
247 | ; fit in allocated memory to prevent kernel faults) |
||
248 | cmp edx, [APP_HEADER_01.i_end] |
||
249 | jb .fail |
||
250 | ; \end{diamond}[20.08.2006] |
||
251 | |||
6333 | serge | 252 | mov [ebx+APP_HDR._emem], edx |
2288 | clevermous | 253 | mov ecx, [APP_HEADER_01.stack_top] |
6333 | serge | 254 | mov [ebx+APP_HDR.esp], ecx |
2288 | clevermous | 255 | mov edx, [APP_HEADER_01.i_param] |
6333 | serge | 256 | mov [ebx+APP_HDR.cmdline], edx |
2288 | clevermous | 257 | mov ecx, [APP_HEADER_01.i_icon] |
6333 | serge | 258 | mov [ebx+APP_HDR.path], ecx |
2288 | clevermous | 259 | mov edx, [APP_HEADER_01.i_end] |
6333 | serge | 260 | mov [ebx+APP_HDR._edata], edx |
2288 | clevermous | 261 | ret |
262 | .fail: |
||
263 | xor eax, eax |
||
264 | ret |
||
265 | |||
266 | align 4 |
||
5130 | serge | 267 | alloc_thread_slot: |
2288 | clevermous | 268 | ;input: |
269 | ; none |
||
270 | ;result: |
||
5130 | serge | 271 | ; eax=[new_thread_slot]<>0 - ok |
2288 | clevermous | 272 | ; 0 - failed. |
273 | ;This function find least empty slot. |
||
274 | ;It doesn't increase [TASK_COUNT]! |
||
5130 | serge | 275 | |
276 | |||
277 | mov edx, thr_slot_map |
||
278 | pushfd |
||
279 | cli |
||
280 | .l1: |
||
281 | bsf eax, [edx] |
||
282 | jnz .found |
||
283 | add edx, 4 |
||
284 | cmp edx, thr_slot_map+32 |
||
285 | jb .l1 |
||
286 | |||
287 | popfd |
||
2288 | clevermous | 288 | xor eax, eax |
289 | ret |
||
5130 | serge | 290 | .found: |
291 | btr [edx], eax |
||
292 | sub edx, thr_slot_map |
||
293 | lea eax, [eax+edx*8] |
||
294 | popfd |
||
295 | ret |
||
2288 | clevermous | 296 | |
297 | align 4 |
||
6333 | serge | 298 | proc create_process stdcall, app_size:dword |
2288 | clevermous | 299 | locals |
5130 | serge | 300 | process dd ? |
2288 | clevermous | 301 | app_tabs dd ? |
302 | endl |
||
303 | |||
5130 | serge | 304 | push ebx |
305 | push esi |
||
306 | push edi |
||
307 | |||
2288 | clevermous | 308 | xor eax, eax |
5130 | serge | 309 | mov [process], eax |
2288 | clevermous | 310 | |
311 | mov eax, [app_size] |
||
6333 | serge | 312 | add eax, 0x3FFFFF |
313 | shr eax, 22 |
||
314 | mov [app_tabs], eax |
||
2288 | clevermous | 315 | |
5130 | serge | 316 | stdcall kernel_alloc, 0x2000 |
2288 | clevermous | 317 | test eax, eax |
318 | jz .fail |
||
5130 | serge | 319 | mov [process], eax |
2288 | clevermous | 320 | |
5130 | serge | 321 | lea edi, [eax+PROC.heap_lock] |
5595 | serge | 322 | mov ecx, (PROC.ht_free-PROC.heap_lock)/4 |
5130 | serge | 323 | |
324 | list_init eax |
||
325 | add eax, PROC.thr_list |
||
326 | list_init eax |
||
327 | |||
2288 | clevermous | 328 | xor eax, eax |
329 | cld |
||
330 | rep stosd |
||
331 | |||
5595 | serge | 332 | mov [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3 |
333 | mov [edi+4], dword 3 ;reserve handles for stdin stdout and stderr |
||
5202 | serge | 334 | mov ecx, (PROC.pdt_0 - PROC.htab)/4 |
5595 | serge | 335 | add edi, 8 |
336 | inc eax |
||
5202 | serge | 337 | @@: |
338 | stosd |
||
339 | inc eax |
||
340 | cmp eax, ecx |
||
341 | jbe @B |
||
342 | |||
5130 | serge | 343 | mov eax, edi |
344 | call get_pg_addr |
||
345 | mov [edi-4096+PROC.pdt_0_phys], eax |
||
346 | |||
2288 | clevermous | 347 | mov ecx, (OS_BASE shr 20)/4 |
5130 | serge | 348 | xor eax, eax |
349 | rep stosd |
||
350 | |||
351 | mov ecx, (OS_BASE shr 20)/4 |
||
352 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
||
2288 | clevermous | 353 | rep movsd |
354 | |||
5130 | serge | 355 | mov eax, [edi-8192+PROC.pdt_0_phys] |
5356 | serge | 356 | or eax, PG_SWR |
2288 | clevermous | 357 | mov [edi-4096+(page_tabs shr 20)], eax |
358 | |||
6333 | serge | 359 | lea edx, [edi-4096] |
360 | mov esi, [app_tabs] |
||
2288 | clevermous | 361 | |
6333 | serge | 362 | .alloc_page_dir: |
2288 | clevermous | 363 | call alloc_page |
364 | test eax, eax |
||
365 | jz .fail |
||
6333 | serge | 366 | or eax, PG_UWR |
367 | mov [edx], eax |
||
2288 | clevermous | 368 | |
6333 | serge | 369 | mov edi, [tmp_task_ptab] |
370 | stdcall map_page, edi, eax, PG_SWR |
||
371 | mov ecx, 1024 |
||
2288 | clevermous | 372 | xor eax, eax |
373 | rep stosd |
||
374 | |||
6333 | serge | 375 | add edx, 4 |
376 | dec esi |
||
377 | jnz .alloc_page_dir |
||
2288 | clevermous | 378 | |
6333 | serge | 379 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
5130 | serge | 380 | mov eax, [process] |
381 | |||
382 | pop edi |
||
383 | pop esi |
||
384 | pop ebx |
||
2288 | clevermous | 385 | ret |
386 | .fail: |
||
6333 | serge | 387 | mov ecx, [process] |
388 | jcxz @F |
||
389 | |||
390 | call destroy_process |
||
2288 | clevermous | 391 | @@: |
392 | xor eax, eax |
||
5130 | serge | 393 | pop edi |
394 | pop esi |
||
395 | pop ebx |
||
2288 | clevermous | 396 | ret |
397 | endp |
||
398 | |||
399 | align 4 |
||
400 | proc destroy_page_table stdcall, pg_tab:dword |
||
401 | |||
402 | push esi |
||
403 | |||
404 | mov esi, [pg_tab] |
||
405 | mov ecx, 1024 |
||
406 | .free: |
||
407 | mov eax, [esi] |
||
408 | test eax, 1 |
||
409 | jz .next |
||
5130 | serge | 410 | test eax, 2 |
411 | jz .next |
||
2288 | clevermous | 412 | test eax, 1 shl 9 |
413 | jnz .next ;skip shared pages |
||
414 | call free_page |
||
415 | .next: |
||
416 | add esi, 4 |
||
417 | dec ecx |
||
418 | jnz .free |
||
419 | pop esi |
||
420 | ret |
||
421 | endp |
||
422 | |||
423 | align 4 |
||
5130 | serge | 424 | destroy_process: ;fastcall ecx= ptr to process |
2288 | clevermous | 425 | |
5130 | serge | 426 | lea eax, [ecx+PROC.thr_list] |
427 | cmp eax, [eax+LHEAD.next] |
||
428 | jne .exit |
||
2288 | clevermous | 429 | |
5130 | serge | 430 | align 4 |
431 | .internal: |
||
432 | push ecx |
||
2288 | clevermous | 433 | |
6263 | serge | 434 | mov esi, ecx |
435 | list_del esi |
||
436 | |||
437 | mov esi, [esi+PROC.dlls_list_ptr] |
||
5130 | serge | 438 | call destroy_all_hdlls |
2288 | clevermous | 439 | |
5130 | serge | 440 | mov esi, [esp] |
441 | add esi, PROC.pdt_0 |
||
442 | mov edi, (0x80000000 shr 20)/4 |
||
2288 | clevermous | 443 | .destroy: |
444 | mov eax, [esi] |
||
445 | test eax, 1 |
||
446 | jz .next |
||
447 | and eax, not 0xFFF |
||
5356 | serge | 448 | stdcall map_page, [tmp_task_ptab], eax, PG_SWR |
2288 | clevermous | 449 | stdcall destroy_page_table, [tmp_task_ptab] |
450 | mov eax, [esi] |
||
451 | call free_page |
||
452 | .next: |
||
453 | add esi, 4 |
||
454 | dec edi |
||
455 | jnz .destroy |
||
456 | |||
5130 | serge | 457 | call kernel_free ;ecx still in stack |
458 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
||
2288 | clevermous | 459 | .exit: |
460 | ret |
||
461 | |||
462 | align 4 |
||
463 | get_pid: |
||
464 | mov eax, [TASK_BASE] |
||
465 | mov eax, [eax+TASKDATA.pid] |
||
466 | ret |
||
467 | |||
468 | pid_to_slot: |
||
469 | ;Input: |
||
470 | ; eax - pid of process |
||
471 | ;Output: |
||
472 | ; eax - slot of process or 0 if process don't exists |
||
473 | ;Search process by PID. |
||
474 | push ebx |
||
475 | push ecx |
||
476 | mov ebx, [TASK_COUNT] |
||
477 | shl ebx, 5 |
||
478 | mov ecx, 2*32 |
||
479 | |||
480 | .loop: |
||
481 | ;ecx=offset of current process info entry |
||
482 | ;ebx=maximum permitted offset |
||
483 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
||
484 | jz .endloop ;skip empty slots |
||
485 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
||
486 | jz .pid_found |
||
487 | .endloop: |
||
488 | add ecx, 32 |
||
489 | cmp ecx, ebx |
||
490 | jle .loop |
||
491 | |||
492 | pop ecx |
||
493 | pop ebx |
||
494 | xor eax, eax |
||
495 | ret |
||
496 | |||
497 | .pid_found: |
||
498 | shr ecx, 5 |
||
499 | mov eax, ecx ;convert offset to index of slot |
||
500 | pop ecx |
||
501 | pop ebx |
||
502 | ret |
||
503 | |||
504 | check_region: |
||
505 | ;input: |
||
506 | ; esi - start of buffer |
||
507 | ; edx - size of buffer |
||
508 | ;result: |
||
509 | ; eax = 1 region lays in app memory |
||
510 | ; eax = 0 region don't lays in app memory |
||
5130 | serge | 511 | |
512 | mov eax, 1 |
||
513 | ret |
||
514 | if 0 |
||
2288 | clevermous | 515 | mov eax, [CURRENT_TASK] |
516 | ; jmp check_process_region |
||
517 | ;----------------------------------------------------------------------------- |
||
518 | ;check_process_region: |
||
519 | ;input: |
||
520 | ; eax - slot |
||
521 | ; esi - start of buffer |
||
522 | ; edx - size of buffer |
||
523 | ;result: |
||
524 | ; eax = 1 region lays in app memory |
||
525 | ; eax = 0 region don't lays in app memory |
||
526 | |||
527 | test edx, edx |
||
528 | jle .ok |
||
529 | shl eax, 5 |
||
530 | cmp word [CURRENT_TASK+eax+0xa], 0 |
||
531 | jnz .failed |
||
532 | shl eax, 3 |
||
533 | mov eax, [SLOT_BASE+eax+0xb8] |
||
534 | test eax, eax |
||
535 | jz .failed |
||
536 | |||
537 | mov eax, 1 |
||
538 | ret |
||
539 | .ok: |
||
540 | mov eax, 1 |
||
541 | ret |
||
542 | .failed: |
||
543 | xor eax, eax |
||
544 | ret |
||
5130 | serge | 545 | end if |
2288 | clevermous | 546 | |
547 | align 4 |
||
548 | proc read_process_memory |
||
549 | ;Input: |
||
550 | ; eax - process slot |
||
551 | ; ecx - buffer address |
||
552 | ; edx - buffer size |
||
553 | ; esi - start address in other process |
||
554 | ;Output: |
||
555 | ; eax - number of bytes read. |
||
556 | locals |
||
557 | slot dd ? |
||
558 | buff dd ? |
||
559 | r_count dd ? |
||
560 | offset dd ? |
||
561 | tmp_r_cnt dd ? |
||
562 | endl |
||
563 | |||
564 | mov [slot], eax |
||
565 | mov [buff], ecx |
||
566 | and [r_count], 0 |
||
567 | mov [tmp_r_cnt], edx |
||
568 | mov [offset], esi |
||
569 | |||
570 | pushad |
||
571 | .read_mem: |
||
572 | mov edx, [offset] |
||
573 | mov ebx, [tmp_r_cnt] |
||
574 | |||
575 | mov ecx, 0x400000 |
||
576 | and edx, 0x3FFFFF |
||
577 | sub ecx, edx |
||
578 | cmp ecx, ebx |
||
579 | jbe @f |
||
580 | mov ecx, ebx |
||
581 | @@: |
||
582 | cmp ecx, 0x8000 |
||
583 | jna @F |
||
584 | mov ecx, 0x8000 |
||
585 | @@: |
||
586 | mov ebx, [offset] |
||
587 | |||
588 | push ecx |
||
589 | stdcall map_memEx, [proc_mem_map], \ |
||
5356 | serge | 590 | [slot], ebx, ecx, PG_READ |
2288 | clevermous | 591 | pop ecx |
592 | |||
593 | mov esi, [offset] |
||
594 | and esi, 0xfff |
||
595 | sub eax, esi |
||
596 | jbe .ret |
||
597 | cmp ecx, eax |
||
598 | jbe @f |
||
599 | mov ecx, eax |
||
600 | mov [tmp_r_cnt], eax |
||
601 | @@: |
||
602 | add esi, [proc_mem_map] |
||
603 | mov edi, [buff] |
||
604 | mov edx, ecx |
||
605 | rep movsb |
||
606 | add [r_count], edx |
||
607 | |||
608 | add [offset], edx |
||
609 | sub [tmp_r_cnt], edx |
||
610 | jnz .read_mem |
||
611 | .ret: |
||
612 | popad |
||
613 | mov eax, [r_count] |
||
614 | ret |
||
615 | endp |
||
616 | |||
617 | align 4 |
||
618 | proc write_process_memory |
||
619 | ;Input: |
||
620 | ; eax - process slot |
||
621 | ; ecx - buffer address |
||
622 | ; edx - buffer size |
||
623 | ; esi - start address in other process |
||
624 | ;Output: |
||
625 | ; eax - number of bytes written |
||
626 | |||
627 | locals |
||
628 | slot dd ? |
||
629 | buff dd ? |
||
630 | w_count dd ? |
||
631 | offset dd ? |
||
632 | tmp_w_cnt dd ? |
||
633 | endl |
||
634 | |||
635 | mov [slot], eax |
||
636 | mov [buff], ecx |
||
637 | and [w_count], 0 |
||
638 | mov [tmp_w_cnt], edx |
||
639 | mov [offset], esi |
||
640 | |||
641 | pushad |
||
642 | .read_mem: |
||
643 | mov edx, [offset] |
||
644 | mov ebx, [tmp_w_cnt] |
||
645 | |||
646 | mov ecx, 0x400000 |
||
647 | and edx, 0x3FFFFF |
||
648 | sub ecx, edx |
||
649 | cmp ecx, ebx |
||
650 | jbe @f |
||
651 | mov ecx, ebx |
||
652 | @@: |
||
653 | cmp ecx, 0x8000 |
||
654 | jna @F |
||
655 | mov ecx, 0x8000 |
||
656 | @@: |
||
657 | mov ebx, [offset] |
||
658 | push ecx |
||
659 | stdcall map_memEx, [proc_mem_map], \ |
||
5356 | serge | 660 | [slot], ebx, ecx, PG_SWR |
2288 | clevermous | 661 | pop ecx |
662 | |||
663 | mov edi, [offset] |
||
664 | and edi, 0xfff |
||
665 | sub eax, edi |
||
666 | jbe .ret |
||
667 | cmp ecx, eax |
||
668 | jbe @f |
||
669 | mov ecx, eax |
||
670 | mov [tmp_w_cnt], eax |
||
671 | @@: |
||
672 | add edi, [proc_mem_map] |
||
673 | mov esi, [buff] |
||
674 | mov edx, ecx |
||
675 | rep movsb |
||
676 | |||
677 | add [w_count], edx |
||
678 | add [offset], edx |
||
679 | sub [tmp_w_cnt], edx |
||
680 | jnz .read_mem |
||
681 | .ret: |
||
682 | popad |
||
683 | mov eax, [w_count] |
||
684 | ret |
||
685 | endp |
||
686 | |||
4105 | Serge | 687 | ;ebx = 1 - kernel thread |
688 | ;ecx=thread entry point |
||
689 | ;edx=thread stack pointer |
||
690 | ;creation flags 0x01 - debugged |
||
691 | ; 0x02 - kernel |
||
692 | |||
2288 | clevermous | 693 | align 4 |
694 | proc new_sys_threads |
||
695 | locals |
||
4105 | Serge | 696 | slot dd ? |
697 | flags dd ? |
||
2288 | clevermous | 698 | app_cmdline dd ? ;0x00 |
699 | app_path dd ? ;0x04 |
||
700 | app_eip dd ? ;0x08 |
||
701 | app_esp dd ? ;0x0C |
||
702 | app_mem dd ? ;0x10 |
||
703 | endl |
||
704 | |||
4105 | Serge | 705 | shl ebx, 1 |
706 | mov [flags], ebx |
||
2288 | clevermous | 707 | |
708 | xor eax, eax |
||
709 | mov [app_eip], ecx |
||
710 | mov [app_cmdline], eax |
||
711 | mov [app_esp], edx |
||
712 | mov [app_path], eax |
||
4105 | Serge | 713 | |
3534 | clevermous | 714 | call lock_application_table |
2288 | clevermous | 715 | |
5130 | serge | 716 | call alloc_thread_slot |
2288 | clevermous | 717 | test eax, eax |
718 | jz .failed |
||
719 | |||
720 | mov [slot], eax |
||
721 | |||
722 | mov esi, [current_slot] |
||
723 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
||
724 | |||
725 | mov edi, eax |
||
726 | shl edi, 8 |
||
727 | add edi, SLOT_BASE |
||
728 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
||
729 | mov ecx, 256/4 |
||
730 | xor eax, eax |
||
731 | cld |
||
732 | rep stosd ;clean extended information about new thread |
||
733 | mov esi, ebx |
||
734 | mov edi, edx |
||
735 | mov ecx, 11 |
||
736 | rep movsb ;copy process name |
||
737 | |||
738 | |||
739 | mov eax, [ebx+APPDATA.tls_base] |
||
740 | test eax, eax |
||
741 | jz @F |
||
742 | |||
743 | push edx |
||
744 | stdcall user_alloc, 4096 |
||
745 | pop edx |
||
746 | test eax, eax |
||
747 | jz .failed1;eax=0 |
||
748 | @@: |
||
749 | mov [edx+APPDATA.tls_base], eax |
||
750 | |||
6090 | serge | 751 | mov eax, [ebx+APPDATA.process] |
752 | mov [edx+APPDATA.process], eax |
||
753 | |||
754 | lea ebx, [edx+APPDATA.list] |
||
755 | lea ecx, [eax+PROC.thr_list] |
||
756 | list_add_tail ebx, ecx ;add thread to process child's list |
||
757 | |||
2288 | clevermous | 758 | lea eax, [app_cmdline] |
6333 | serge | 759 | stdcall set_app_params , [slot], eax, [flags] |
2288 | clevermous | 760 | |
761 | mov eax, [process_number] ;set result |
||
3534 | clevermous | 762 | call unlock_application_table |
2288 | clevermous | 763 | ret |
764 | .failed: |
||
765 | xor eax, eax |
||
766 | .failed1: |
||
3534 | clevermous | 767 | call unlock_application_table |
2288 | clevermous | 768 | dec eax ;-1 |
769 | ret |
||
770 | endp |
||
771 | |||
6333 | serge | 772 | proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword |
773 | |||
774 | mov edx, [img_size] |
||
775 | mov esi, [file_base] |
||
776 | mov ecx, [file_size] |
||
777 | add edx, 4095 |
||
778 | add ecx, 4095 |
||
779 | shr edx, 12 ; total pages |
||
780 | shr ecx, 12 ; image pages |
||
781 | |||
782 | mov edi, page_tabs |
||
783 | shr esi, 10 |
||
784 | add esi, edi |
||
785 | |||
786 | .map_image: |
||
787 | lodsd |
||
788 | and eax, -4096 |
||
789 | or eax, PG_UWR |
||
790 | stosd |
||
791 | dec edx |
||
792 | loop .map_image |
||
793 | |||
794 | test edx, edx |
||
795 | jz .done |
||
796 | .map_bss: |
||
797 | call alloc_page |
||
798 | test eax, eax |
||
799 | jz .fail |
||
800 | |||
801 | or eax, PG_UWR |
||
802 | stosd |
||
803 | dec edx |
||
804 | jnz .map_bss |
||
805 | |||
806 | mov edi, [file_size] |
||
807 | mov ecx, [img_size] |
||
808 | add edi, 4095 |
||
809 | and edi, -4096 |
||
810 | add ecx, 4095 |
||
811 | and ecx, -4096 |
||
812 | sub ecx, edi |
||
813 | shr ecx, 2 |
||
814 | xor eax, eax |
||
815 | rep stosd |
||
816 | .done: |
||
817 | .fail: |
||
818 | ret |
||
819 | endp |
||
820 | |||
2288 | clevermous | 821 | align 4 |
6333 | serge | 822 | common_app_entry: |
823 | mov ebp, [current_slot] |
||
824 | mov ebp, [ebp+APPDATA.exec_params] |
||
825 | test ebp, ebp |
||
826 | jz .exit |
||
827 | stdcall map_process_image, [ebp+APP_HDR._emem],\ |
||
828 | [ebp+APP_HDR.img_base], [ebp+APP_HDR.img_size] |
||
6502 | pathoswith | 829 | mov esi, [ebp+APP_HDR.path_string] |
6333 | serge | 830 | mov edi, [ebp+APP_HDR.path] |
6758 | pathoswith | 831 | mov ecx, [ebp+APP_HDR.filename_size] |
832 | cmp ecx, 1023 |
||
833 | jc @f |
||
834 | mov ecx, 1022 |
||
835 | @@: |
||
6502 | pathoswith | 836 | push esi |
837 | test edi, edi |
||
838 | jz @f |
||
6758 | pathoswith | 839 | mov al, '/' |
840 | stosb |
||
6502 | pathoswith | 841 | rep movsb |
842 | mov byte [edi], 0 |
||
6338 | serge | 843 | @@: |
6502 | pathoswith | 844 | call kernel_free |
6333 | serge | 845 | mov edi, [ebp+APP_HDR.cmdline] |
846 | test edi, edi |
||
847 | jz .check_tls_header |
||
6502 | pathoswith | 848 | lea esi, [ebp+sizeof.APP_HDR] |
849 | mov ecx, [ebp+APP_HDR.cmdline_size] |
||
6333 | serge | 850 | cmp ecx, 256 |
851 | jb .copy_cmdline |
||
852 | mov edi, [ebp+APP_HDR._emem] |
||
853 | add edi, 4095 |
||
854 | and edi, -4096 |
||
855 | sub edi, ecx |
||
856 | dec edi |
||
857 | cmp word [6], '00' |
||
6502 | pathoswith | 858 | jne @f |
6333 | serge | 859 | mov [APP_HEADER_00_.i_param], edi |
860 | jmp .copy_cmdline |
||
861 | @@: |
||
862 | mov [APP_HEADER_01_.i_param], edi |
||
863 | .copy_cmdline: |
||
864 | rep movsb |
||
6502 | pathoswith | 865 | mov byte [edi], 0 |
6333 | serge | 866 | .check_tls_header: |
867 | cmp word [6], '02' |
||
868 | jne .cleanup |
||
2288 | clevermous | 869 | call init_heap |
870 | stdcall user_alloc, 4096 |
||
871 | mov edx, [current_slot] |
||
872 | mov [edx+APPDATA.tls_base], eax |
||
873 | mov [tls_data_l+2], ax |
||
874 | shr eax, 16 |
||
875 | mov [tls_data_l+4], al |
||
876 | mov [tls_data_l+7], ah |
||
877 | mov dx, app_tls |
||
878 | mov fs, dx |
||
6333 | serge | 879 | .cleanup: |
880 | stdcall free_kernel_space, [ebp+APP_HDR.img_base] |
||
881 | stdcall kernel_free, ebp |
||
6345 | serge | 882 | mov ebx, [current_slot] |
883 | cmp [ebx+APPDATA.debugger_slot], 0 |
||
884 | je .exit |
||
885 | mov eax, [TASK_BASE] |
||
886 | mov [eax+TASKDATA.state], 1 |
||
887 | call change_task |
||
6333 | serge | 888 | .exit: |
2288 | clevermous | 889 | popad |
890 | iretd |
||
891 | |||
892 | EFL_IF equ 0x0200 |
||
893 | EFL_IOPL1 equ 0x1000 |
||
894 | EFL_IOPL2 equ 0x2000 |
||
895 | EFL_IOPL3 equ 0x3000 |
||
896 | |||
897 | align 4 |
||
6333 | serge | 898 | proc set_app_params stdcall,slot:dword, params:dword, flags:dword |
2288 | clevermous | 899 | |
900 | locals |
||
901 | pl0_stack dd ? |
||
902 | endl |
||
903 | |||
904 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
||
905 | mov [pl0_stack], eax |
||
906 | |||
907 | lea edi, [eax+RING0_STACK_SIZE] |
||
908 | |||
909 | mov eax, [slot] |
||
910 | mov ebx, eax |
||
911 | |||
912 | shl eax, 8 |
||
913 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
||
914 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
||
915 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
||
3296 | clevermous | 916 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
2288 | clevermous | 917 | |
918 | ;set default io permission map |
||
919 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
||
920 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
||
921 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
||
922 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
||
923 | |||
924 | mov esi, fpu_data |
||
925 | mov ecx, 512/4 |
||
926 | rep movsd |
||
927 | |||
928 | cmp ebx, [TASK_COUNT] |
||
929 | jle .noinc |
||
930 | inc dword [TASK_COUNT] ;update number of processes |
||
931 | .noinc: |
||
932 | shl ebx, 8 |
||
933 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
||
934 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
||
935 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
||
936 | |||
937 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
||
938 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
||
939 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
||
940 | |||
941 | mov ecx, [def_cursor] |
||
942 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
||
943 | mov eax, [pl0_stack] |
||
944 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
||
945 | add eax, RING0_STACK_SIZE |
||
946 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
||
947 | |||
948 | push ebx |
||
6502 | pathoswith | 949 | stdcall kernel_alloc, maxPathLength |
2288 | clevermous | 950 | pop ebx |
951 | mov esi, [current_slot] |
||
952 | mov esi, [esi+APPDATA.cur_dir] |
||
6502 | pathoswith | 953 | mov ecx, maxPathLength/4 |
2288 | clevermous | 954 | mov edi, eax |
955 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
||
956 | rep movsd |
||
957 | |||
958 | shr ebx, 3 |
||
6333 | serge | 959 | mov dword [CURRENT_TASK+ebx+0x10], 0 |
2288 | clevermous | 960 | |
961 | mov ebx, [slot] |
||
962 | mov eax, ebx |
||
963 | shl ebx, 5 |
||
964 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
||
965 | |||
966 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
||
967 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
||
968 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
||
969 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
||
970 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
||
971 | |||
972 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
||
973 | |||
974 | inc dword [process_number] |
||
975 | mov eax, [process_number] |
||
976 | mov [ebx+4], eax ;set PID |
||
977 | |||
978 | ;set draw data to full screen |
||
979 | xor eax, eax |
||
980 | mov [ecx+0], dword eax |
||
981 | mov [ecx+4], dword eax |
||
5350 | serge | 982 | mov eax, [screen_workarea.right] |
2288 | clevermous | 983 | mov [ecx+8], eax |
5350 | serge | 984 | mov eax, [screen_workarea.bottom] |
2288 | clevermous | 985 | mov [ecx+12], eax |
986 | |||
987 | mov ebx, [pl0_stack] |
||
988 | mov esi, [params] |
||
989 | lea ecx, [ebx+REG_EIP] |
||
990 | xor eax, eax |
||
991 | |||
6333 | serge | 992 | mov [ebx+REG_RET], dword common_app_entry |
2288 | clevermous | 993 | mov [ebx+REG_EDI], eax |
994 | mov [ebx+REG_ESI], eax |
||
995 | mov [ebx+REG_EBP], eax |
||
996 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
||
997 | mov [ebx+REG_EBX], eax |
||
998 | mov [ebx+REG_EDX], eax |
||
999 | mov [ebx+REG_ECX], eax |
||
1000 | mov [ebx+REG_EAX], eax |
||
1001 | |||
6333 | serge | 1002 | mov eax, [esi+APP_HDR.eip] |
1003 | mov [ebx+REG_EIP], eax |
||
2288 | clevermous | 1004 | mov [ebx+REG_CS], dword app_code |
3534 | clevermous | 1005 | mov ecx, USER_PRIORITY |
4105 | Serge | 1006 | |
1007 | test byte [flags], 2 |
||
1008 | jz @F |
||
1009 | |||
3325 | clevermous | 1010 | mov [ebx+REG_CS], dword os_code ; kernel thread |
3534 | clevermous | 1011 | mov ecx, MAX_PRIORITY |
3325 | clevermous | 1012 | @@: |
2288 | clevermous | 1013 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1014 | |||
6333 | serge | 1015 | mov eax, [esi+APP_HDR.esp] |
1016 | mov [ebx+REG_APP_ESP], eax |
||
2288 | clevermous | 1017 | mov [ebx+REG_SS], dword app_data |
1018 | |||
3534 | clevermous | 1019 | lea edx, [ebx+REG_RET] |
2288 | clevermous | 1020 | mov ebx, [slot] |
1021 | shl ebx, 5 |
||
3534 | clevermous | 1022 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
2288 | clevermous | 1023 | |
3534 | clevermous | 1024 | xor edx, edx; process state - running |
2288 | clevermous | 1025 | ; set if debuggee |
1026 | test byte [flags], 1 |
||
1027 | jz .no_debug |
||
1028 | mov eax, [CURRENT_TASK] |
||
1029 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
||
1030 | .no_debug: |
||
3534 | clevermous | 1031 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1032 | lea edx, [SLOT_BASE+ebx*8] |
||
1033 | call scheduler_add_thread |
||
2288 | clevermous | 1034 | ret |
1035 | endp |
||
1036 | |||
1037 | align 4 |
||
1038 | get_stack_base: |
||
1039 | mov eax, [current_slot] |
||
1040 | mov eax, [eax+APPDATA.pl0_stack] |
||
1041 | ret |
||
1042 | |||
1043 | |||
1044 | include "debug.inc"> |