Skip to content

Commit e5cf862

Browse files
authored
[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 <[email protected]>
1 parent 85b428d commit e5cf862

File tree

9 files changed

+934
-1425
lines changed

9 files changed

+934
-1425
lines changed

components/lwp/lwp.c

Lines changed: 29 additions & 898 deletions
Large diffs are not rendered by default.

components/lwp/lwp.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "lwp_signal.h"
3333
#include "lwp_syscall.h"
3434
#include "lwp_avl.h"
35+
#include "lwp_args.h"
3536
#include "mm_aspace.h"
3637

3738
#ifdef RT_USING_MUSLLIBC
@@ -237,6 +238,8 @@ void lwp_tid_dec_ref(rt_thread_t thread);
237238
void lwp_tid_set_thread(int tid, rt_thread_t thread);
238239

239240
int lwp_execve(char *filename, int debug, int argc, char **argv, char **envp);
241+
int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_t addr_size, struct process_aux *aux);
242+
void lwp_user_obj_free(struct rt_lwp *lwp);
240243

241244
/*create by lwp_setsid.c*/
242245
int setsid(void);
@@ -382,15 +385,6 @@ struct process_aux
382385
struct process_aux_item item[AUX_ARRAY_ITEMS_NR];
383386
};
384387

385-
struct lwp_args_info
386-
{
387-
char **argv;
388-
char **envp;
389-
int argc;
390-
int envc;
391-
int size;
392-
};
393-
394388
struct dbg_ops_t
395389
{
396390
int (*dbg)(int argc, char **argv);

0 commit comments

Comments
 (0)