以下链接解释了UNIX(BSD风格)和Linux的x86-32系统调用约定:
但是UNIX和Linux上的x86-64系统调用约定是什么?
我从同事那里了解到,无需编写函数即可编写和执行C程序main().它可以在下面完成
withoutMain.c
/* Compile this with gcc -nostartfiles */
#include <stdlib.h>
void _start() {
  int ret = my_main();
  exit(ret); 
}
int my_main() {
  puts("This is a program without a main() function!");
  return 0; 
}
Run Code Online (Sandbox Code Playgroud)
将其编译为:
my_main.c
运行方式为: 
main()
我的问题是,何时需要做这种事情?一些现实世界的场景?
我有这个简短的你好世界计划:
#include <stdio.h>
static const char* msg = "Hello world";
int main(){
    printf("%s\n", msg);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用gcc将它编译成以下汇编代码:
    .file   "hello_world.c"
    .section    .rodata
.LC0:
    .string "Hello world"
    .data
    .align 4
    .type   msg, @object
    .size   msg, 4
msg:
    .long   .LC0
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    andl    $-16, %esp
    subl    $16, %esp
    movl    msg, %eax
    movl    %eax, (%esp)
    call    puts
    movl    $0, %eax
    leave
    .cfi_restore 5
    .cfi_def_cfa …Run Code Online (Sandbox Code Playgroud) 我想了解我们为什么使用int 80h以及在汇编代码中调用它后会发生什么。像这儿:
int 80h
mov eax,1
int 80h
Run Code Online (Sandbox Code Playgroud)
它怎么知道我要调用系统退出,而不只是在eax中保存十进制数?
message db "Enter a digit ", 0xA,0xD
Length equ $- message
Run Code Online (Sandbox Code Playgroud)
它用于获取字符串的长度吗?
它在内部如何运作?
我试图在 32 位测试 Linux 系统(Lubuntu)上用 python3 编写一个简单的调试器,它应该能够捕获任意程序的所有系统调用(在本例中为:/bin/ls)。为此,我使用 ptrace 系统调用来单步执行该过程。每一步之后,我都会读取寄存器以找到指令指针eip,以从下一条指令读取 2 个字节。如果这 2 个字节是0xcd和0x80,则表示int 80是系统调用。我知道还有用于此目的的 PTRACE_SYSCALL,但我想在不使用它的情况下执行此操作。
下面我向您展示代码,它似乎有效,但 有一些奇怪的行为:
为了弄清楚这是否有效,我使用strace将其输出与我自己的系统调用进行比较。看来我的程序只显示系统调用的第一部分,第二部分就丢失了。为了向您展示我在下面发布了我的程序和 strace 的输出。有人知道这里可能出什么问题吗?
import os               # os interaction
from struct import pack # dealing with bytes (ptrace)
import ctypes           # support c data structures
""" ========================================================== """
# 32 bit reg process structrue
class UserRegsStruct(ctypes.Structure):
    _fields_ = [
        ("ebx", ctypes.c_ulong),
        ("ecx", ctypes.c_ulong),
        ("edx", ctypes.c_ulong),
        ("esi", ctypes.c_ulong),
        ("edi", ctypes.c_ulong),
        ("ebp", ctypes.c_ulong), …Run Code Online (Sandbox Code Playgroud) 我知道这int 0x80会在 linux 中造成中断。但是,我不明白这段代码是如何工作的。它会返回一些东西吗?
代表什么$ - msg?
global _start
section .data
    msg db "Hello, world!", 0x0a
    len equ $ - msg
section .text
_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80 ;What is this?
    mov eax, 1
    mov ebx, 0
    int 0x80 ;and what is this?
Run Code Online (Sandbox Code Playgroud)