[smart] Updated the API for kernel access to user address issues and for calculating string length (#8058)
This commit is contained in:
parent
b826afe8f9
commit
dc84765823
|
@ -167,7 +167,6 @@ void lwp_tid_put(int tid);
|
||||||
rt_thread_t lwp_tid_get_thread(int tid);
|
rt_thread_t lwp_tid_get_thread(int tid);
|
||||||
void lwp_tid_set_thread(int tid, rt_thread_t thread);
|
void lwp_tid_set_thread(int tid, rt_thread_t thread);
|
||||||
|
|
||||||
size_t lwp_user_strlen(const char *s, int *err);
|
|
||||||
int lwp_execve(char *filename, int debug, int argc, char **argv, char **envp);
|
int lwp_execve(char *filename, int debug, int argc, char **argv, char **envp);
|
||||||
|
|
||||||
/*create by lwp_setsid.c*/
|
/*create by lwp_setsid.c*/
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -832,4 +832,66 @@ size_t lwp_data_put(struct rt_lwp *lwp, void *dst, void *src, size_t size)
|
||||||
return copy_len;
|
return copy_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t lwp_user_strlen_ext(struct rt_lwp *lwp, const char *s)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
char *new_buf = RT_NULL;
|
||||||
|
void *addr_start = RT_NULL;
|
||||||
|
int size = 0;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (s == RT_NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
addr_start = (void *)s;
|
||||||
|
new_buf = rt_malloc(ARCH_PAGE_SIZE);
|
||||||
|
|
||||||
|
if (lwp == RT_NULL)
|
||||||
|
{
|
||||||
|
LOG_W("%s: lwp is NULL", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = lwp_data_get(lwp, new_buf, addr_start, ARCH_PAGE_SIZE);
|
||||||
|
if (err == 0)
|
||||||
|
{
|
||||||
|
rt_free(new_buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (new_buf[size] != '\0')
|
||||||
|
{
|
||||||
|
len ++;
|
||||||
|
if (size == (ARCH_PAGE_SIZE -1))
|
||||||
|
{
|
||||||
|
err = lwp_data_get(lwp, new_buf, addr_start + len, ARCH_PAGE_SIZE);
|
||||||
|
if (err == 0)
|
||||||
|
{
|
||||||
|
rt_free(new_buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_free(new_buf);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t lwp_user_strlen(const char *s)
|
||||||
|
{
|
||||||
|
struct rt_lwp *lwp = RT_NULL;
|
||||||
|
|
||||||
|
lwp = lwp_self();
|
||||||
|
RT_ASSERT(lwp != RT_NULL);
|
||||||
|
|
||||||
|
return lwp_user_strlen_ext(lwp, s);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -145,6 +145,9 @@ void lwp_unmap_user_space(struct rt_lwp *lwp);
|
||||||
int lwp_unmap_user(struct rt_lwp *lwp, void *va);
|
int lwp_unmap_user(struct rt_lwp *lwp, void *va);
|
||||||
void *lwp_map_user(struct rt_lwp *lwp, void *map_va, size_t map_size, rt_bool_t text);
|
void *lwp_map_user(struct rt_lwp *lwp, void *map_va, size_t map_size, rt_bool_t text);
|
||||||
|
|
||||||
|
size_t lwp_user_strlen(const char *s);
|
||||||
|
size_t lwp_user_strlen_ext(struct rt_lwp *lwp, const char *s);
|
||||||
|
|
||||||
rt_varea_t lwp_map_user_varea(struct rt_lwp *lwp, void *map_va, size_t map_size);
|
rt_varea_t lwp_map_user_varea(struct rt_lwp *lwp, void *map_va, size_t map_size);
|
||||||
|
|
||||||
/* check LWP_MAP_FLAG_* */
|
/* check LWP_MAP_FLAG_* */
|
||||||
|
|
Loading…
Reference in New Issue