mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-10-21 15:41:41 +08:00
[smart] fixup of script execution (#9009)
This patch fixup the script execution capabilities on argv passing and adds support for arguments larger than 4k. According to POSIX, the script parameter is quiet different from the current implementation. Especially on the way it inserts the path of executables. At the end, when you execute a script from `$PATH`, it always fails. For the script, interpreter will be invoked with the following arguments: `{interpreter [optional-arg] pathname arg...}` where pathname is the pathname of the file specified as the first argument of execve(), and arg... is the series of words pointed to by the argv argument of execve(), starting at argv[1]. Note that there is no way to get the argv[0] that was passed to the execve() call. The changes include: - Separating argument, environment variable, and auxiliary vector processing into a new lwp_args.c file. - Fixing bugs in script argument processing and supporting arguments larger than 4k. - Updating lwp_execve to use the new argscopy function and removing the old lwp_argscopy function. - Making various modifications to lwp_load and elf_aux_fill to work with the new argument processing. - Removing unnecessary code related to dynamic loading and interpreter scripts. Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
@@ -47,11 +47,13 @@
|
||||
#define ELF_EXEC_LOAD_ADDR USER_VADDR_START
|
||||
#define ELF_INTERP_LOAD_ADDR LDSO_LOAD_VADDR
|
||||
|
||||
#define ELF_AUX_ENT(aux, id, val) \
|
||||
do \
|
||||
{ \
|
||||
*aux++ = id; \
|
||||
*aux++ = val; \
|
||||
#define ELF_AUX_ENT(aux, id, val) \
|
||||
do \
|
||||
{ \
|
||||
rt_base_t a = id; \
|
||||
lwp_data_put(lwp, aux++, &a, sizeof(rt_ubase_t)); \
|
||||
a = val; \
|
||||
lwp_data_put(lwp, aux++, &a, sizeof(rt_ubase_t)); \
|
||||
} while (0)
|
||||
|
||||
typedef struct
|
||||
@@ -571,6 +573,7 @@ static int elf_aux_fill(elf_load_info_t *load_info)
|
||||
uint32_t random_value = rt_tick_get();
|
||||
size_t prot = PROT_READ | PROT_WRITE;
|
||||
size_t flags = MAP_PRIVATE;
|
||||
rt_lwp_t lwp = load_info->lwp;
|
||||
void *va;
|
||||
|
||||
if (!aux)
|
||||
@@ -581,7 +584,7 @@ static int elf_aux_fill(elf_load_info_t *load_info)
|
||||
aux_info = (elf_addr_t *)aux->item;
|
||||
ELF_AUX_ENT(aux_info, AT_PAGESZ, ARCH_PAGE_SIZE);
|
||||
|
||||
va = lwp_mmap2(load_info->lwp, (void *)(USER_VADDR_TOP - ARCH_PAGE_SIZE * 2), ARCH_PAGE_SIZE, prot, flags, -1, 0);
|
||||
va = lwp_mmap2(lwp, (void *)(USER_VADDR_TOP - ARCH_PAGE_SIZE * 2), ARCH_PAGE_SIZE, prot, flags, -1, 0);
|
||||
if (!va)
|
||||
{
|
||||
LOG_E("lwp map user failed!");
|
||||
@@ -604,10 +607,6 @@ static int elf_aux_fill(elf_load_info_t *load_info)
|
||||
ELF_AUX_ENT(aux_info, AT_CLKTCK, 0);
|
||||
ELF_AUX_ENT(aux_info, AT_SECURE, 0);
|
||||
|
||||
#ifdef ARCH_MM_MMU
|
||||
rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, aux, sizeof(*aux));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -757,7 +756,7 @@ OUT:
|
||||
}
|
||||
|
||||
int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_t addr_size,
|
||||
struct process_aux *aux)
|
||||
struct process_aux *aux_ua)
|
||||
{
|
||||
elf_load_info_t load_info = { 0 };
|
||||
int len;
|
||||
@@ -789,7 +788,7 @@ int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_
|
||||
}
|
||||
|
||||
load_info.lwp = lwp;
|
||||
load_info.aux = aux;
|
||||
load_info.aux = aux_ua;
|
||||
|
||||
load_info.exec_info.fd = ELF_INVALID_FD;
|
||||
load_info.interp_info.fd = ELF_INVALID_FD;
|
||||
|
Reference in New Issue
Block a user