当前位置:网站首页>Executable program execution process
Executable program execution process
2022-04-23 05:26:00 【Life needs depth】
./hello_world This order is in linux How to execute in the kernel system . File system usage busybox, Corresponding linux Kernel call procedure .
busybox in shell Parse command line
int ash_main(int argc, char **argv)
{
state4: /* XXX ??? - why isn't this before the "if" statement */
cmdloop(1);
}
static int
cmdloop(int top)
{
union node *n;
struct stackmark smark;
int inter;
int numeof = 0;
printf("1. cmdloop\n");
TRACE(("cmdloop(%d) called\n", top));
for (;;) {
} else if (nflag == 0) {
/* job_warning can only be 2,1,0. Here 2->1, 1/0->0 */
printf("3. cmdloop\n");
job_warning >>= 1;
numeof = 0;
evaltree(n, 0);
printf("4. cmdloop\n");
}
}
static void
evaltree(union node *n, int flags)
{
int checkexit = 0;
void (*evalfn)(union node *, int);
unsigned isor;
int status;
if (n == NULL) {
TRACE(("evaltree(NULL) called\n"));
goto out;
}
case NCMD:
evalfn = evalcommand;
printf("2. evaltree ncmd switch\n");
checkexit:
if (eflag && !(flags & EV_TESTED))
checkexit = ~0;
goto calleval;
calleval:
evalfn(n, flags);
break;
}
}
static void
evalcommand(union node *cmd, int flags)
{
static const struct builtincmd bltin = {
"\0\0", bltincmd
};
struct stackmark smark;
/* Execute the command. */
switch (cmdentry.cmdtype) {
default:
printf("2. cmdentry.cmdtype default.\n");
/* Fork off a child process if necessary. */
if (!(flags & EV_EXIT) || trap[0]) {
INT_OFF;
jp = makejob(cmd, 1);
if (forkshell(jp, cmd, FORK_FG) != 0) {
exitstatus = waitforjob(jp);
INT_ON;
break;
}
printf("3. cmdentry.cmdtype forkshell.\n");
FORCE_INT_ON;
}
listsetvar(varlist.list, VEXPORT|VSTACK);
shellexec(argv, path, cmdentry.u.index);
/* NOTREACHED */
}
Two system calls will be called during command execution forkshell and shellexec, adopt shellexec Take system calls for example
static void
shellexec(char **argv, const char *path, int idx)
{
char *cmdname;
int e;
char **envp;
int exerrno;
clearredir(1);
envp = environment();
if (strchr(argv[0], '/')
#if ENABLE_FEATURE_SH_STANDALONE
|| find_applet_by_name(argv[0])
#endif
) {
tryexec(argv[0], argv, envp);
e = errno;
} else {
e = ENOENT;
while ((cmdname = padvance(&path, argv[0])) != NULL) {
if (--idx < 0 && pathopt == NULL) {
tryexec(cmdname, argv, envp);
if (errno != ENOENT && errno != ENOTDIR)
e = errno;
}
stunalloc(cmdname);
}
}
}
static void
tryexec(char *cmd, char **argv, char **envp)
{
int repeated = 0;
repeat:
#ifdef SYSV
do {
execve(cmd, argv, envp);
} while (errno == EINTR);
#else
execve(cmd, argv, envp);
#endif
}
execve The function is gcc The library file provided by the compilation tool realizes glibc-2.3.6/sysdeps/unix/sysv/linux/execve.c In the definition of
int
__execve (file, argv, envp)
const char *file;
char *const argv[];
char *const envp[];
{
#if __BOUNDED_POINTERS__
{
char *const *v;
int i;
char *__unbounded *__unbounded ubp_argv;
char *__unbounded *__unbounded ubp_envp;
char *__unbounded *__unbounded ubp_v;
for (v = argv; *v; v++)
;
i = v - argv + 1;
ubp_argv = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_argv) * i);
for (v = argv, ubp_v = ubp_argv; --i; v++, ubp_v++)
*ubp_v = CHECK_STRING (*v);
*ubp_v = 0;
for (v = envp; *v; v++)
;
i = v - envp + 1;
ubp_envp = (char *__unbounded *__unbounded) alloca (sizeof (*ubp_envp) * i);
for (v = envp, ubp_v = ubp_envp; --i; v++, ubp_v++)
*ubp_v = CHECK_STRING (*v);
*ubp_v = 0;
return INLINE_SYSCALL (execve, 3, CHECK_STRING (file), ubp_argv, ubp_envp);
}
#else
return INLINE_SYSCALL (execve, 3, file, argv, envp);
#endif
}
weak_alias (__execve, execve)
Finally call to INLINE_SYSCALL Macro in header file glibc-2.3.6/sysdeps/unix/sysv/linux/arm/sysdep.h To realize
/* Define a macro which expands into the inline wrapper code for a system
call. */
#undef INLINE_SYSCALL
#define INLINE_SYSCALL(name, nr, args...) \
({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
{ \
__set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
_sys_result = (unsigned int) -1; \
} \
(int) _sys_result; })
#undef INTERNAL_SYSCALL_DECL
#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
#undef INTERNAL_SYSCALL
#define INTERNAL_SYSCALL(name, err, nr, args...) \
({ unsigned int _sys_result; \
{ \
register int _a1 asm ("a1"); \
LOAD_ARGS_##nr (args) \
asm volatile ("swi %1 @ syscall " #name \
: "=r" (_a1) \
: "i" (SYS_ify(name)) ASM_ARGS_##nr \
: "memory"); \
_sys_result = _a1; \
} \
(int) _sys_result; })
Will eventually be called to arm Of switch The instruction enters the soft interrupt and is transferred to the operating system interrupt processing for processing .
版权声明
本文为[Life needs depth]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230525501380.html
边栏推荐
- Wbpack configuring production development environment
- What are the most popular recruitment technical skills in 2022? You can't think of it
- Study notes: unity customsrp-10-point and spot shadows
- what is wifi6?
- es6数组的使用
- Data bus realizes the communication between brother components
- 学习笔记:Unity CustomSRP-12-HDR
- Vscode settings JSON configuration
- Call the interface to get the time
- Double click The jar package cannot run the solution
猜你喜欢
Basic use of sqlyog
If I am PM's performance, movie VR ticket purchase display
Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
Getting started with varnish
Top 25 Devops tools in 2021 (Part 2)
Graphics. Fromimage reports an error "graphics object cannot be created from an image that has an indexed pixel..."
我这位老程序员对时代危险和机遇的一点感悟?
无线网怎么用手机验证码登录解决方案
Using PHP post temporary file mechanism to upload arbitrary files
Laravel database
随机推荐
SQL Server检索SQL和用户信息的需求
egg测试的知识大全--mock、superTest、coffee
Cloud computing and cloud native architecture design of openshift
2021-10-25
工具在数字化转型中扮演了什么样的角色?
日志简介和构建web应用
Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行
Mairadb数据库基本操作之数据管理
4 个最常见的自动化测试挑战及应对措施
MySQL series - install MySQL 5.6.27 on Linux and solve common problems
Knowledge of egg testing -- mock, Supertest, coffee
varnish入门
The 2021 IT industry project management survey report was released!
Cross domain CORS relationship~
双击.jar包无法运行解决方法
領域驅動模型DDD(三)——使用Saga管理事務
The source of anxiety of graduating college students looking for technology development jobs
Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
2021-10-08
CPT 104_TTL 09