mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-20 01:43:33 +08:00
e5cf86267b
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>
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
/*
|
|
* Copyright (c) 2006-2024, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2024-01-12 Shell separate argv, envp, aux processing from execve(2).
|
|
* Bugs fix for script arguments processing.
|
|
*/
|
|
#ifndef __LWP_ARGV_H__
|
|
#define __LWP_ARGV_H__
|
|
|
|
#include <rtthread.h>
|
|
|
|
struct rt_lwp;
|
|
|
|
enum lwp_args_type {
|
|
LWP_ARGS_TYPE_ARG,
|
|
LWP_ARGS_TYPE_KARG,
|
|
LWP_ARGS_TYPE_ENVP,
|
|
LWP_ARGS_TYPE_KENVP,
|
|
LWP_ARGS_TYPE_NULLPTR
|
|
};
|
|
|
|
struct lwp_string_vector
|
|
{
|
|
const char **strvec;
|
|
rt_uint32_t strvec_buflen;
|
|
rt_uint32_t string_count;
|
|
};
|
|
|
|
struct lwp_args_info
|
|
{
|
|
int argv0_strlen;
|
|
int strings_length;
|
|
int str_buf_size;
|
|
|
|
char *str_buf;
|
|
struct lwp_string_vector argv;
|
|
struct lwp_string_vector envp;
|
|
};
|
|
|
|
rt_err_t lwp_args_init(struct lwp_args_info *ai);
|
|
void lwp_args_detach(struct lwp_args_info *ai);
|
|
struct process_aux *lwp_argscopy(struct rt_lwp *lwp, struct lwp_args_info *args_info);;
|
|
rt_err_t lwp_args_put(struct lwp_args_info *args, const char **strv_addr, enum lwp_args_type atype);
|
|
rt_err_t lwp_args_put_argv(struct lwp_args_info *args, const char **argv_uaddr);
|
|
rt_err_t lwp_args_put_envp(struct lwp_args_info *args, const char **envp_uaddr);
|
|
rt_err_t lwp_args_load_script(struct lwp_args_info *args, const char *filename);
|
|
const char *lwp_args_get_argv_0(struct lwp_args_info *ai);
|
|
char** lwp_get_envp(struct rt_lwp *lwp, rt_size_t *penvp_counts);
|
|
void lwp_print_envp(struct rt_lwp *lwp);
|
|
|
|
char** lwp_get_command_line_args(struct rt_lwp *lwp);
|
|
void lwp_free_command_line_args(char** argv);
|
|
|
|
#endif /* __LWP_ARGV_H__ */
|