当前位置:网站首页>Processus d'exécution du programme exécutable
Processus d'exécution du programme exécutable
2022-04-23 05:26:00 【La vie a besoin de profondeur】
./hello_worldCette commande estlinuxComment fonctionne le système du noyau.Utilisation du système de fichiersbusybox,CorrespondantlinuxProcédure d'appel du noyau.
busyboxMoyenneshellRésoudre la ligne de commande
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 */
}
Deux appels système sont appelés pendant l'exécution de la commande forkshellEtshellexec,Adoptionshellexec Par exemple, un appel système
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
}
execveLa fonction estgcc Mise en oeuvre des fichiers de la Bibliothèque fournis par l'outil de compilation glibc-2.3.6/sysdeps/unix/sysv/linux/execve.cDéfinition moyenne
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)
Appel final àINLINE_SYSCALL Macro dans le fichier d'en - tête glibc-2.3.6/sysdeps/unix/sysv/linux/arm/sysdep.hRéalisation intermédiaire
/* 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; })
Enfin appelé àarmDeswitch La commande entre dans l'interruption douce et est transférée dans le traitement de l'interruption du système d'exploitation pour traitement .
版权声明
本文为[La vie a besoin de profondeur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230525501380.html
边栏推荐
- Quick app bottom navigation bar
- Output string in reverse order
- When is it appropriate for automated testing? (bottom)
- Graphics.FromImage报错“Graphics object cannot be created from an image that has an indexed pixel ...”
- Double click The jar package cannot run the solution
- egg中的多进程模型--egg文档搬运工
- Study notes: unity customsrp-10-point and spot shadows
- Publish your own wheel - pypi packaging upload practice
- Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time
- Solve the problem of JS calculation accuracy
猜你喜欢

Laravel database

Project manager's thinking mode worth trying: project success equation

Camera imaging + homography transformation + camera calibration + stereo correction

Getting started with varnish
Redis的基本知识

To understand Devops, you must read these ten books!

selenium預先加載cookie的必要性

Cloud computing and cloud native architecture design of openshift

mariadb数据库的主从复制

4 most common automated test challenges and Countermeasures
随机推荐
(11) Vscode code formatting configuration
Basic knowledge of redis
Low code and no code considerations
Vscode settings JSON configuration
Publish your own wheel - pypi packaging upload practice
es6数组的使用
Use pagoda + Xdebug + vscode to debug code remotely
Modèle axé sur le domaine DDD (III) - gestion des transactions à l'aide de Saga
Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
Pandas to_ SQL function pit avoidance guide "with correct code to run"
MySQL series - install MySQL 5.6.27 on Linux and solve common problems
When is it appropriate for automated testing? (bottom)
我这位老程序员对时代危险和机遇的一点感悟?
egg中的cors和proxy(づ ̄3 ̄)づ╭~踩坑填坑的过程~ToT~
Getting started with varnish
App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
Use of ES6 array
学习笔记:Unity CustomSRP-11-Post Processing---Bloom
Laravel routing job
Click the Add button - a box appears (similar to adding learning experience - undergraduate - Graduate)