Segmentation fault when I change int to syscall/sysenter in assembly x86 (linux)
When I change the system call from int $0x80
to syscall
or sysenter
in the following code:
mov $4, %rax
mov $1, %rbx
mov $String1, %rcx
mov $16, %rdx
int $0x80
#where String1 is defined sooner as String1: .asciz "String numero 1n"
It gives me a segmentation fault. In GDB I got the message
Program received signal SIGSEGV, Segmentation fault. 0x00000000f7ffdbe9 in ?? ()
Since I'm not expert at all in assembly I don't know what is happening
Edit : the program is being built using as
and ld
with no special param
Edit2 : I'm using x86_64 system, according to the output of lshw | grep syscall
lshw | grep syscall
it returned:
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
But it didn't returned for sysenter
...
On the comments, @Jester said that this different system calls implies in different registers being loaded for the parameters. Which registers are those then? Thanks in advance
Solved the problem thanks to the comments.
First off, my architecture doesn't support sysenter. And to make the syscall I had to replace the code with:
mov $1, %rax
mov $1, %rdi
mov $String1, %rsi
mov $16, %rdx
syscall
and it worked just fine
链接地址: http://www.djcxy.com/p/72572.html上一篇: C ++