MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / lwp_user_strlen_ext

Function lwp_user_strlen_ext

components/lwp/lwp_user_mm.c:1008–1071  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006}
1007
1008size_t lwp_user_strlen_ext(struct rt_lwp *lwp, const char *s)
1009{
1010 int len = 0;
1011 char *temp_buf = RT_NULL;
1012 void *addr_start = RT_NULL;
1013 int get_bytes = 0;
1014 int index = 0;
1015
1016 if (s == RT_NULL)
1017 return 0;
1018
1019 if (lwp == RT_NULL)
1020 {
1021 LOG_W("%s: lwp is NULL", __func__);
1022 return -1;
1023 }
1024
1025 addr_start = (void *)s;
1026 temp_buf = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
1027 if (!temp_buf)
1028 {
1029 LOG_W("%s: No memory", __func__);
1030 return -1;
1031 }
1032
1033 get_bytes = lwp_data_get(lwp, temp_buf, addr_start, ARCH_PAGE_SIZE);
1034 if (get_bytes == 0)
1035 {
1036 LOG_I("lwp_data_get(lwp=%p,dst=0x%lx,src=0x%lx,size=0x1000) failed", lwp, temp_buf, addr_start);
1037 rt_pages_free(temp_buf, 0);
1038 return -1;
1039 }
1040
1041 while (temp_buf[index] != '\0')
1042 {
1043 len++;
1044 index++;
1045 if (index == get_bytes)
1046 {
1047 if (get_bytes == ARCH_PAGE_SIZE)
1048 {
1049 get_bytes = lwp_data_get(lwp, temp_buf, addr_start + len, ARCH_PAGE_SIZE);
1050 if (get_bytes == 0)
1051 {
1052 LOG_I("lwp_data_get(lwp=%p,dst=0x%lx,src=0x%lx,size=0x1000): user data unaccessible",
1053 lwp, temp_buf, addr_start);
1054 len = -1;
1055 break;
1056 }
1057 index = 0;
1058 }
1059 else
1060 {
1061 LOG_I("lwp_data_get(lwp=%p,dst=0x%lx,src=0x%lx,size=0x1000): user data unaccessible",
1062 lwp, temp_buf, addr_start);
1063 len = -1;
1064 break;
1065 }

Callers 4

lwp_get_envpFunction · 0.85
lwp_user_strlenFunction · 0.85
lwp_strlenFunction · 0.85

Calls 3

rt_pages_alloc_extFunction · 0.85
lwp_data_getFunction · 0.85
rt_pages_freeFunction · 0.85

Tested by

no test coverage detected