* @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 *
| 486 | * 7. Creates and starts the main thread |
| 487 | */ |
| 488 | pid_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, '/'); |
no test coverage detected