From aa4154894c216f31665b691836efe85fdad387ae Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Tue, 31 May 2022 07:27:00 +0000 Subject: [PATCH] [kernel] Add is_string_userspace func, like is_region_userspace git-svn-id: svn://kolibrios.org@9823 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/dll.inc | 16 ++++++++-------- kernel/trunk/core/memory.inc | 4 ++-- kernel/trunk/kernel.asm | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/kernel/trunk/core/dll.inc b/kernel/trunk/core/dll.inc index e303aa5fce..7dfd66d6bc 100644 --- a/kernel/trunk/core/dll.inc +++ b/kernel/trunk/core/dll.inc @@ -287,17 +287,17 @@ align 4 proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword @@: - stdcall strncmp, [pSym], [sz_sym], 8 + stdcall strncmp, [pSym], [sz_sym], sizeof.COFF_SYM.Name test eax, eax jz .ok - add [pSym], 18 + add [pSym], sizeof.COFF_SYM dec [count] jnz @b xor eax, eax ret .ok: mov eax, [pSym] - mov eax, [eax+8] + mov eax, [eax+COFF_SYM.Value] ret endp @@ -964,7 +964,7 @@ proc load_library stdcall, file_name:dword, encoding:dword movzx ecx, [edx + COFF_HEADER.nSections] xor ebx, ebx - add edx, 20 + add edx, sizeof.COFF_HEADER @@: call coff_get_align add ebx, eax @@ -1045,7 +1045,7 @@ proc load_library stdcall, file_name:dword, encoding:dword movzx ecx, [edx + COFF_HEADER.nSections] lea ecx, [ecx*5] lea edi, [edi + ecx*8+20] - add edx, 20 + add edx, sizeof.COFF_HEADER @@: movzx eax, [edx + COFF_SECTION.NumReloc] lea eax, [eax*5] @@ -1097,7 +1097,7 @@ proc load_library stdcall, file_name:dword, encoding:dword ; fixup symbols mov edx, ebx mov eax, [ebx + COFF_HEADER.nSymbols] - add edx, 20 + add edx, sizeof.COFF_HEADER mov ecx, [esi + DLLDESCR.symbols_num] lea ecx, [ecx*9] add ecx, ecx @@ -1184,7 +1184,7 @@ proc load_library stdcall, file_name:dword, encoding:dword shr ecx, 12 .map_pages_loop: mov eax, [page_tabs + ecx*4] - and eax, not 0xFFF + and eax, -PAGE_SIZE or al, PG_UR xchg eax, [page_tabs + edx*4] test al, 1 @@ -1194,7 +1194,7 @@ proc load_library stdcall, file_name:dword, encoding:dword invlpg [ebx+edi] inc ecx inc edx - add edi, 0x1000 + add edi, PAGE_SIZE cmp edi, [esi + DLLDESCR.size] jb .map_pages_loop diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 344227f3a8..63b3819be2 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -1141,8 +1141,8 @@ f68: .18: mov eax, edx .19: - cmp ecx, OS_BASE - jae .fail + stdcall is_string_userspace, ecx + jnz .fail stdcall load_library, ecx, eax mov [esp + SYSCALL_STACK._eax], eax ret diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index bce6dbbe7a..1efb31b1c5 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -4820,6 +4820,30 @@ proc is_region_userspace stdcall, base:dword, len:dword ret endp +align 4 +; @brief Check whether given string lays in userspace memory, i.e. below OS_BASE +; @param base Base address of string +; @return ZF = 1 if string in userspace memory, +; zf = 0 otherwise +proc is_string_userspace stdcall, base:dword + push eax ecx edi + xor eax, eax + mov edi, [base] + + mov ecx, OS_BASE-1 + sub ecx, edi + jb .done ; zf + inc ecx + cmp ecx, 0x10000 ; don't allow strings larger than 64k? + jbe @f + mov ecx, 0x10000 +@@: + repnz scasb +.done: + pop edi ecx eax + ret +endp + if ~ lang eq sp diff16 "end of .text segment",0,$ end if