MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / strlenSafe

Function strlenSafe

Kernel/src/arch/x86_64/stringsafe.cpp:5–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <paging.h>
4
5long strlenSafe(const char* str, size_t& size, address_space_t* aSpace)
6{
7 size_t pageBoundary = PAGE_SIZE_4K - (reinterpret_cast<uintptr_t>(str) & (PAGE_SIZE_4K - 1)); // Get amount of bytes to page boundary
8 if(!Memory::CheckUsermodePointer(reinterpret_cast<uintptr_t>(str), pageBoundary, aSpace)){
9 return 1;
10 }
11
12 size_t& i = size;
13 i = 0;
14
15 while(i < pageBoundary){
16 if(str[i] == '\0'){
17 return 0;
18 }
19
20 i++;
21 }
22
23
24 for(;;){
25 if(!Memory::CheckUsermodePointer(reinterpret_cast<uintptr_t>(str) + i, PAGE_SIZE_4K, aSpace)){
26 return 1;
27 }
28
29 size_t pageBoundary = i + PAGE_SIZE_4K;
30 while(i < pageBoundary){
31 if(str[i] == '\0'){
32 return 0;
33 }
34
35 i++;
36 }
37 }
38}

Callers 4

SysExecFunction · 0.85
SysCreateServiceFunction · 0.85
SysCreateInterfaceFunction · 0.85
SysInterfaceConnectFunction · 0.85

Calls 1

CheckUsermodePointerFunction · 0.85

Tested by

no test coverage detected