The following application generates a Segmentation Fault when executed:
.set __NR_reboot, 169
.set LINUX_REBOOT_CMD_POWER_OFF, 0x4321FEDC
.section .text
.globl _start
_start:
movl $LINUX_REBOOT_CMD_POWER_OFF, %ebx
movl $__NR_reboot, %eax
int $0x80
It's a quite simple application and I must be missing something really obvious. Can someone help me?
It was compiled with:
as shutdown.s -o shutdown.o
ld shutdown.o -o shutdown
EDIT:
Even a simple application that just calls syscall sync() generates a Segmentation Fault:
.set __NR_sync, 36
.section .text
.globl _start
_start:
movl $__NR_sync, %eax
int $0x80
movl $1, %eax #syscall exit
movl $0, %eax
int $0x80
WARNING: remember to sync(2)
before calling reboot(2)
.
The reboot(2)
system call takes 4 parameters.You are confusing it with the libc
wrapper.
WARNING: remember to sync(2)
before calling reboot(2)
.
(It actually takes the magic* parameters so that people have to reread the documentation and don't forget calling sync(2)
.)
WARNING: Did I say that you have to sync(2)
before calling reboot(2)
?