What happens if there is no exit system call in an assembly program?

偶尔善良 提交于 2019-12-06 02:10:31

问题


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

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?

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/49674026/what-happens-if-there-is-no-exit-system-call-in-an-assembly-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!