From 23bdfe5dc431c03d7896c313565cec0ad96c96e3 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Thu, 24 May 2007 07:36:48 +0000 Subject: [PATCH] infinity: remove direct access to kernel data git-svn-id: svn://kolibrios.org@520 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/exports.inc | 4 +++ kernel/trunk/core/memory.inc | 52 +++++++++++++++++++++++++++++++ kernel/trunk/core/taskman.inc | 6 ++++ kernel/trunk/drivers/imports.inc | 6 ++++ kernel/trunk/drivers/infinity.asm | 21 +++++++------ kernel/trunk/fs/fs_lfn.inc | 50 ++++++++++++++--------------- 6 files changed, 104 insertions(+), 35 deletions(-) diff --git a/kernel/trunk/core/exports.inc b/kernel/trunk/core/exports.inc index 8eca40ad22..3cafc0850b 100644 --- a/kernel/trunk/core/exports.inc +++ b/kernel/trunk/core/exports.inc @@ -39,7 +39,9 @@ iglobal szUserFree db 'UserFree',0 szKmalloc db 'Kmalloc',0 szKfree db 'Kfree',0 + szCreateRingBuffer db 'CreateRingBuffer',0 + szGetPid db 'GetPid',0 szCreateObject db 'CreateObject',0 szDestroyObject db 'DestroyObject',0 szCreateEvent db 'CreateEvent',0 @@ -101,7 +103,9 @@ kernel_export: dd szUserFree , user_free dd szKmalloc , malloc dd szKfree , free + dd szCreateRingBuffer, create_ring_buffer + dd szGetPid , get_pid dd szCreateObject , create_kernel_object dd szDestroyObject , destroy_kernel_object dd szCreateEvent , create_event diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 0271ed58a3..e4e2b0dbe1 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -1085,6 +1085,58 @@ proc stall stdcall, delay:dword ret endp +align 4 +proc create_ring_buffer stdcall, size:dword, flags:dword + locals + buf_ptr dd ? + endl + + mov eax, [size] + test eax, eax + jz .fail + + add eax, eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail + + mov [buf_ptr], eax + + mov ebx, [size] + shr ebx, 12 + push ebx + + stdcall alloc_pages, ebx + pop ecx + + test eax, eax + jz .mm_fail + + or eax, [flags] + mov edi, [buf_ptr] + mov ebx, [buf_ptr] + mov edx, ecx + shl edx, 2 + shr edi, 10 +@@: + mov [page_tabs+edi], eax + mov [page_tabs+edi+edx], eax + invlpg [ebx] + invlpg [ebx+esi] + add eax, 0x1000 + add ebx, 0x1000 + add edi, 4 + dec ecx + jnz @B + + mov eax, [buf_ptr] + ret +.mm_fail: + stdcall free_kernel_space, [buf_ptr] + xor eax, eax +.fail: + ret +endp if 0 push eax diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 0da2ca7653..be25cb0962 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -544,6 +544,12 @@ proc destroy_app_space stdcall, pg_dir:dword ret endp +align 4 +get_pid: + mov eax, [TASK_DATA] + mov eax, [eax+4] + ret + pid_to_slot: ;Input: ; eax - pid of process diff --git a/kernel/trunk/drivers/imports.inc b/kernel/trunk/drivers/imports.inc index e579414ee2..ef07fb7a04 100644 --- a/kernel/trunk/drivers/imports.inc +++ b/kernel/trunk/drivers/imports.inc @@ -88,7 +88,13 @@ end if if used Kfree extrn Kfree end if +if used CreateRingBuffer + extrn CreateRingBuffer +end if +if used GetPid + extrn GetPid +end if if used CreateObject extrn CreateObject end if diff --git a/kernel/trunk/drivers/infinity.asm b/kernel/trunk/drivers/infinity.asm index 57be5d2ceb..407ba4de70 100644 --- a/kernel/trunk/drivers/infinity.asm +++ b/kernel/trunk/drivers/infinity.asm @@ -15,7 +15,10 @@ SOUND_VERSION equ API_VERSION include 'proc32.inc' + +;include 'system.inc' include 'main.inc' + include 'imports.inc' FORCE_MMX equ 0 ;set to 1 to force use mmx or @@ -27,9 +30,6 @@ DEBUG equ 1 OS_BASE equ 0x80000000 -SLOT_BASE equ (OS_BASE+0x0080000) -TASK_COUNT equ (OS_BASE+0x0003004) -CURRENT_TASK equ (OS_BASE+0x0003000) CAPS_SSE2 equ 26 PG_SW equ 0x003 @@ -334,9 +334,9 @@ proc CreateBuffer stdcall, format:dword, size:dword test eax, PCM_OUT+PCM_STATIC jnz .fail .test_ok: - mov ebx, [CURRENT_TASK] ;hack: direct accsess - shl ebx, 5 ;to kernel data - mov ebx, [CURRENT_TASK+ebx+4] + + call GetPid + mov ebx, eax mov eax, STREAM_SIZE call CreateObject @@ -390,9 +390,11 @@ proc CreateBuffer stdcall, format:dword, size:dword shr ebx, 12 mov [ring_pages], ebx - add eax, eax ;double ring size - stdcall AllocKernelSpace, eax + stdcall CreateRingBuffer, eax, PG_SW +if 0 + stdcall AllocKernelSpace, eax +end if mov edi, [str] mov ecx, [ring_size] mov [edi+STREAM.in_base], eax @@ -407,6 +409,7 @@ proc CreateBuffer stdcall, format:dword, size:dword add eax, ecx mov [edi+STREAM.in_top], eax +if 0 mov ebx, [ring_pages] stdcall AllocPages, ebx mov edi, [str] @@ -421,7 +424,7 @@ proc CreateBuffer stdcall, format:dword, size:dword pop eax add ebx, [ring_size] call CommitPages ;double mapped - +end if jmp .out_buff .static: mov ecx, [size] diff --git a/kernel/trunk/fs/fs_lfn.inc b/kernel/trunk/fs/fs_lfn.inc index f8eace7e8a..93f5634542 100644 --- a/kernel/trunk/fs/fs_lfn.inc +++ b/kernel/trunk/fs/fs_lfn.inc @@ -84,7 +84,7 @@ endg end_of_file_system_lfn: pop edx - stdcall kernel_free, edx + stdcall kernel_free, edx ret @@ -103,38 +103,39 @@ file_system_lfn: ; 9 : create directory ; замена адреса возврата - push eax + push eax stdcall kernel_alloc, 200 - mov edx,eax - pop eax + mov edx,eax + pop eax + push edx push end_of_file_system_lfn - mov ebx,edx - - mov ecx, [eax] - mov [ebx],ecx + mov ebx,edx - add ebx,4 - mov ecx, [eax+4] - mov [ebx],ecx + mov ecx, [eax] + mov [ebx],ecx - add ebx,4 - mov ecx, [eax+8] - mov [ebx],ecx + add ebx,4 + mov ecx, [eax+4] + mov [ebx],ecx - add ebx,4 - mov ecx, [eax+12] - mov [ebx],ecx + add ebx,4 + mov ecx, [eax+8] + mov [ebx],ecx - add ebx,4 - mov ecx, [eax+16] - mov [ebx],ecx + add ebx,4 + mov ecx, [eax+12] + mov [ebx],ecx - add ebx,4 + add ebx,4 + mov ecx, [eax+16] + mov [ebx],ecx + + add ebx,4 push edx ; !!!!!!!!!!!!!!!!!!! ; eax - yначало старого пакета ; edx - начало нового пакета - ; ebx - куда ложить строку + ; ebx - куда ложить строку add eax,20 mov cl, [eax] test cl,cl @@ -143,10 +144,7 @@ file_system_lfn: @@: stdcall full_file_name,eax,ebx pop eax - - - - + ; add eax, std_application_base_address