当我在程序集 x86 (linux) 中将 int 更改为 syscall/sysenter 时出现分段错误

Segmentation fault when I change int to syscall/sysenter in assembly x86 (linux)

当我在以下代码中将系统调用从 int [=13=]x80 更改为 syscallsysenter 时:

mov , %rax
mov , %rbx
mov $String1, %rcx
mov , %rdx
int [=12=]x80

#where String1 is defined sooner as String1: .asciz "String numero 1\n"

它给我一个分段错误。在 GDB 中,我收到消息

Program received signal SIGSEGV, Segmentation fault. 0x00000000f7ffdbe9 in ?? ()

因为我根本不是汇编方面的专家,所以我不知道发生了什么

编辑:程序正在使用 asld 构建,没有特殊参数

Edit2: 我正在使用 x86_64 系统,根据 lshw | grep syscall 的输出,它返回:

capacidades: x86-64 fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt lahf_lm tpr_shadow vnmi flexpriority ept vpid dtherm arat cpufreq

但是 sysenter...

没有返回

在评论中,@Jester 说这种不同的系统调用意味着在为参数加载不同的寄存器中。那是哪些寄存器呢? 提前致谢

感谢评论,问题已解决。

首先,我的架构不支持 sysenter。为了进行系统调用,我必须将代码替换为:

mov , %rax
mov , %rdi
mov $String1, %rsi
mov , %rdx
syscall

而且效果很好