Compile a program with syscall

Hi guys, I am actually trying syscalls. Is it normal when I create a simple crystal code with a syscall I can’t compile it ?

I wrote this code to try:

module Init
  Syscall.def_syscall reboot, Int64, magic : Int64, magic2 : Int64, op : Int64
end

Init.reboot(magic:  0xfee1dead,
            magic2: 0x28121969,
            op:     0x1234567)

And I am getting this error:

[fulgurance@alienware-m17-r3 Downloads]$ crystal build test.cr -o test
Showing last frame. Use --error-trace for full trace.

In test.cr:10:5

 10 | Syscall.def_syscall reboot, Int64, magic : Int64, magic2 : Int64, op : Int64
      ^------
Error: undefined constant Syscall

The thing strange is this code can be compiled with an old version of crystal ! ( It can be compiled with 1.11.2 xD)

Did your program include

require Syscall

?

Ah okay the documentation don’t specify this.

I have another question about syscalls.

The syscall REBOOT in C is like this:

int syscall(SYS_reboot, int magic, int magic2, int op, void *arg);

What is the equivalent of *arg in crystal ? Because it is a pointer.

The list of constants mentioned in crystal/src/syscall/x86_64-linux.cr at master · crystal-lang/crystal · GitHub

the Reboot would be Syscall::Code::REBOOT.

I am reading the macros ( crystal/src/syscall/x86_64-linux.cr at master · crystal-lang/crystal · GitHub ) and it should work: def_syscall "reboot", …