Golang, calling a new system call in Linux

huangapple go评论85阅读模式
英文:

Golang, calling a new system call in Linux

问题

我有一个带有自定义系统调用的Linux内核。在C语言中,我可以使用标准C库的syscall()函数通过系统调用号来调用系统调用。那么在Go语言中,我该如何调用这个新的系统调用呢?

在Linux上的C语言中,还有一些宏可以生成所需的内联汇编代码来直接进行系统调用。

我不想修改syscall_linux.go文件。

我看到在Go语言中,syscall_linux.go文件是通过一个Perl脚本(mysyscall.pl)进行处理,以生成汇编代码。这也相当复杂,而且修改它以生成新的存根似乎也是不必要的混乱。

英文:

I have a Linux kernel with a custom system call. In C, I can use the standard C library syscall() to call a system call by its number. How can I call this new system call in Go?

In C, on Linux, there are also macros that can emit the needed inline assembly to make a system call directly.

I would hate to have to hack syscall_linux.go.

I see that in Go, syscall_linux.go is processed by a perl script (mysyscall.pl) to generate assembly. That is also pretty complicated and hacking it to generate a new stub also seems needlessly messy.

答案1

得分: 6

syscall 包提供了 syscall.Syscallsyscall.Syscall6 函数,可以直接进行系统调用。

英文:

The syscall package has syscall.Syscall and syscall.Syscall6 to make syscalls directly.

huangapple
  • 本文由 发表于 2014年11月27日 02:52:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/27156817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定