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

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

问题描述

在汇编程序中,.text被加载到0x08048000.之后是.data.bss部分.

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

如果我没有在.text部分中放置exit syscall,会发生什么?是否会导致.data.bss被解释为导致不可预测"结果的代码?程序什么时候终止-大概在每条指令"执行完之后?

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

我可以很容易地编写一个没有exit syscall的程序,但是测试.data.bss是否会执行是我仍然不知道的事情,因为我想我必须知道真正的机器代码,是在引擎盖下生成的以模拟这一点.

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

我认为这个问题更多的是关于CPU和操作系统如何处理这种情况,而不是汇编语言.

I think this question is more about how would CPU and operating system handle such a scenario than assembly language.

推荐答案

处理器不知道您的代码在哪里结束.它忠实地执行一条指令,直到另一条指令被重定向到其他地方为止(例如通过跳转,调用,中断,系统调用等).如果代码结束而没有跳到其他地方,则处理器将在代码执行后继续执行内存中的所有内容.确切的结果是无法预料的,​​但是最终,您的代码通常会崩溃,因为它试图执行无效的指令或试图访问不允许访问的内存.如果两者均未发生且没有跳转发生,则处理器最终将尝试执行未映射的内存或标记为不可执行"的代码的内存,从而导致分段冲突.在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天全站免登陆