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

Function lwp_data_put

components/lwp/lwp_user_mm.c:901–957  ·  view source on GitHub ↗

dst is in lwp address space, src is in current thread space */

Source from the content-addressed store, hash-verified

899
900/* dst is in lwp address space, src is in current thread space */
901size_t lwp_data_put(struct rt_lwp *lwp, void *dst, void *src, size_t size)
902{
903 size_t copy_len = 0;
904 char *temp_page = 0;
905 char *dst_iter, *dst_iter_aligned, *dst_next_page;
906 char *src_put_end, *src_iter;
907
908 if (!size || !dst)
909 {
910 return 0;
911 }
912
913 src_iter = src;
914 dst_iter = dst;
915 src_put_end = dst + size;
916 dst_next_page =
917 (char *)(((size_t)dst_iter + ARCH_PAGE_SIZE) & ~(ARCH_PAGE_SIZE - 1));
918 do
919 {
920 size_t bytes_to_put = (char *)dst_next_page - (char *)dst_iter;
921 if (bytes_to_put > size)
922 {
923 bytes_to_put = size;
924 }
925
926 if (ALIGNED(dst_iter) && bytes_to_put == ARCH_PAGE_SIZE)
927 {
928 /* write to page in kernel */
929 if (rt_aspace_page_put(lwp->aspace, dst_iter, src_iter))
930 break;
931 }
932 else
933 {
934 if (!temp_page)
935 temp_page = rt_pages_alloc_ext(0, PAGE_ANY_AVAILABLE);
936 if (!temp_page)
937 break;
938
939 dst_iter_aligned = (void *)((long)dst_iter & ~ARCH_PAGE_MASK);
940 if (rt_aspace_page_get(lwp->aspace, dst_iter_aligned, temp_page))
941 break;
942 memcpy(temp_page + (dst_iter - dst_iter_aligned), src_iter, bytes_to_put);
943 if (rt_aspace_page_put(lwp->aspace, dst_iter_aligned, temp_page))
944 break;
945 }
946
947 src_iter = src_iter + bytes_to_put;
948 dst_iter = dst_iter + bytes_to_put;
949 size -= bytes_to_put;
950 dst_next_page = dst_next_page + ARCH_PAGE_SIZE;
951 copy_len += bytes_to_put;
952 } while (dst_iter < src_put_end);
953
954 if (temp_page)
955 rt_pages_free(temp_page, 0);
956 return copy_len;
957}
958

Callers 6

_update_ruFunction · 0.85
_stats_and_reap_childFunction · 0.85
lwp_argscopyFunction · 0.85
elf_aux_fillFunction · 0.85
lwp_put_to_userFunction · 0.85
test_map_fixedFunction · 0.85

Calls 4

rt_aspace_page_putFunction · 0.85
rt_pages_alloc_extFunction · 0.85
rt_aspace_page_getFunction · 0.85
rt_pages_freeFunction · 0.85

Tested by 1

test_map_fixedFunction · 0.68