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

Function lwp_argscopy

components/lwp/lwp_args.c:310–388  ·  view source on GitHub ↗

* @brief Copy a light-weight process arguments info structure to user space * * @param[in] lwp Pointer to the light-weight process structure * @param[in] ai Pointer to the arguments info structure to copy * * @return struct process_aux* Pointer to the process auxiliary structure in user space */

Source from the content-addressed store, hash-verified

308 * @return struct process_aux* Pointer to the process auxiliary structure in user space
309 */
310struct process_aux *lwp_argscopy(struct rt_lwp *lwp, struct lwp_args_info *ai)
311{
312 int size = sizeof(rt_base_t) * 4; /* store argc, argv_NULL, envp_NULL, aux_NULL */
313 char *str_ua;
314 const char **args_ua;
315 const char **iter;
316 rt_base_t off;
317 struct process_aux_item pa_item;
318 struct process_aux *aux_ua;
319 size_t prot = PROT_READ | PROT_WRITE;
320 size_t flags = MAP_FIXED | MAP_PRIVATE;
321 rt_base_t argc = ai->argv.string_count;
322 rt_base_t envc = ai->envp.string_count;
323
324 /**
325 * counts the bytes to storage the args
326 */
327 size += argc * sizeof(char *) + envc * sizeof(char *)
328 + ai->strings_length + sizeof(struct process_aux);
329
330 args_ua = lwp_mmap2(lwp, (void *)(USER_STACK_VEND), size, prot, flags, -1, 0);
331 if (args_ua == RT_NULL)
332 {
333 return RT_NULL;
334 }
335
336 /**
337 * @brief Put data from args info to user space
338 * argc, argv[], NULL, envp[], NULL, aux[], NULL, strings
339 */
340 iter = args_ua;
341
342 /* argc */
343 lwp_data_put(lwp, iter++, &argc, sizeof(char *));
344
345 /* strings */
346 str_ua = (char *)((rt_ubase_t)args_ua +
347 (1 + argc + 1 + envc + 1 + AUX_ARRAY_ITEMS_NR * 2 + 1) * sizeof(rt_base_t));
348 lwp_data_put(lwp, str_ua, ai->str_buf, ai->strings_length);
349
350 /* argv */
351 off = str_ua - ai->str_buf;
352 for (size_t i = 0; i < argc; i++)
353 {
354 /* str_ua + ai->argv.strvec[i] - ai->str_buf */
355 ai->argv.strvec[i] += off;
356 }
357 lwp_data_put(lwp, iter, ai->argv.strvec, sizeof(char *) * ai->argv.string_count);
358 iter += ai->argv.string_count;
359
360 /* NULL */
361 lwp_data_set(lwp, iter++, 0, sizeof(char *));
362
363 /* envp */
364 for (size_t i = 0; i < envc; i++)
365 {
366 /* str_ua + ai->envp.strvec[i] - ai->str_buf */
367 ai->envp.strvec[i] += off;

Callers 2

argscopyFunction · 0.85
sys_execveFunction · 0.85

Calls 6

lwp_mmap2Function · 0.85
lwp_data_putFunction · 0.85
lwp_data_setFunction · 0.85
rt_strlenFunction · 0.85
rt_mallocFunction · 0.85
lwp_memcpyFunction · 0.85

Tested by

no test coverage detected