如果汇编程序中没有退出系统调用会发生什么? [英] What happens if there is no exit system call in an assembly program?

查看:28
本文介绍了如果汇编程序中没有退出系统调用会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在汇编程序中,.text 部分在0x08048000 处加载;.data.bss 部分紧随其后.

In an assembly program, the .text section is loaded at 0x08048000; the .data and the .bss section comes after that.

如果我exit 系统调用放在 .text 部分会发生什么?是否会导致 .data.bss 部分被解释为导致不可预测"的代码?行为?程序何时终止——可能在每个指令"之后?执行了吗?

What would happen if I don't put an exit syscall in the .text section? Would it lead to the .data and the .bss section being interpreted as code causing "unpredictable" behavior? When will the program terminate -- probably after every "instruction" is executed?

我可以在没有 exit 系统调用的情况下轻松编写程序,但我不会测试 .data.bss 是否被执行'不知道,因为我想我必须知道在后台生成的真实机器代码才能理解这一点.

I can easily write a program without the exit syscall, but testing if .data and .bss gets executed is something I don't know because I guess I would have to know the real machine code that is generated under-the-hoods to understand that.

我认为这个问题更多地是关于操作系统和 CPU 将如何处理这种情况?";与汇编语言相比,但对于汇编程序员等来说还是很有趣的.

I think this question is more about "How would OS and CPU handle such a scenario?" than assembly language, but it is still interesting to know for assembly programmers etc.

推荐答案

处理器不知道您的代码在哪里结束.它忠实地执行一条又一条指令,直到执行被重定向到别处(例如,通过跳转、调用、中断、系统调用或类似方式).如果你的代码没有跳转到其他地方就结束了,处理器会在你的代码之后继续执行内存中的任何内容.究竟发生了什么是相当不可预测的,但最终,您的代码通常会崩溃,因为它尝试执行无效指令或尝试访问不允许访问的内存.如果两者都没有发生并且没有发生跳转,最终处理器会尝试将未映射的内存或标记为不可执行"的内存作为代码执行,从而导致分段违规.在 Linux 上,这会引发 SIGSEGVSIGBUS.如果未处理,这些将终止您的进程并可选择生成核心转储.

The processor does not know where your code ends. It faithfully executes one instruction after another until execution is redirected elsewhere (e.g. by a jump, call, interrupt, system call, or similar). If your code ends without jumping elsewhere, the processor continues executing whatever is in memory after your code. It is fairly unpredictable what exactly happens, but eventually, your code typically crashes because it tries to execute an invalid instruction or tries to access memory that it is not allowed to access. If neither happens and no jump occurs, eventually the processor tries to execute unmapped memory or memory that is marked as "not executable" as code, causing a segmentation violation. On Linux, this raises a SIGSEGV or SIGBUS. When unhandled, these terminate your process and optionally produce core dumps.

这篇关于如果汇编程序中没有退出系统调用会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆