MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / lwp_execve

Function lwp_execve

components/lwp/lwp.c:488–635  ·  view source on GitHub ↗

* @brief Creates and starts a new LWP by loading and executing the specified executable file. * * @param[in] filename Path to the executable file * @param[in] debug Debug flag (non-zero to enable debugging) * @param[in] argc Argument count * @param[in] argv Argument vector * @param[in] envp Environment variables * * @return Process ID (PID) of the new LWP on success *

Source from the content-addressed store, hash-verified

486 * 7. Creates and starts the main thread
487 */
488pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
489{
490 int result;
491 struct rt_lwp *lwp;
492 char *thread_name;
493 struct process_aux *aux;
494 int tid = 0;
495
496 if (filename == RT_NULL)
497 {
498 return -EINVAL;
499 }
500
501 if (access(filename, X_OK) != 0)
502 {
503 return -EACCES;
504 }
505
506 lwp = lwp_create(LWP_CREATE_FLAG_ALLOC_PID | LWP_CREATE_FLAG_NOTRACE_EXEC);
507
508 if (lwp == RT_NULL)
509 {
510 LOG_E("lwp struct out of memory!\n");
511 return -ENOMEM;
512 }
513 LOG_D("lwp malloc : %p, size: %d!", lwp, sizeof(struct rt_lwp));
514
515 if ((tid = lwp_tid_get()) == 0)
516 {
517 lwp_ref_dec(lwp);
518 return -ENOMEM;
519 }
520#ifdef ARCH_MM_MMU
521 if (lwp_user_space_init(lwp, 0) != 0)
522 {
523 lwp_tid_put(tid);
524 lwp_ref_dec(lwp);
525 return -ENOMEM;
526 }
527#endif
528
529 if ((aux = argscopy(lwp, argc, argv, envp)) == RT_NULL)
530 {
531 lwp_tid_put(tid);
532 lwp_ref_dec(lwp);
533 return -ENOMEM;
534 }
535
536 result = lwp_load(filename, lwp, RT_NULL, 0, aux);
537 if (result == RT_EOK)
538 {
539 rt_thread_t thread = RT_NULL;
540 rt_uint32_t priority = 25, tick = 200;
541
542 lwp_execve_setup_stdio(lwp);
543
544 /* obtain the base name */
545 thread_name = strrchr(filename, '/');

Callers 3

execFunction · 0.85
lwp_startupFunction · 0.85
sys_execFunction · 0.85

Calls 15

lwp_createFunction · 0.85
lwp_tid_getFunction · 0.85
lwp_ref_decFunction · 0.85
lwp_user_space_initFunction · 0.85
lwp_tid_putFunction · 0.85
argscopyFunction · 0.85
lwp_loadFunction · 0.85
lwp_execve_setup_stdioFunction · 0.85
rt_thread_createFunction · 0.85
lwp_tid_set_threadFunction · 0.85
lwp_selfFunction · 0.85
lwp_to_pidFunction · 0.85

Tested by

no test coverage detected