Linux Read syscall signature and event/signal/timerfd

165 views
Skip to first unread message

Albert Strasheim

unread,
Jun 4, 2010, 12:55:26 PM6/4/10
to golang-dev
Hello all

I'm working on adding support for Linux's eventfd, signalfd and
timerfd to the syscall package.

The current signature for Read looks like this:

func Read(fd int, p []byte) (n int, errno int)

For these special fds, you need to read things that aren't []byte from
the fds, so I was wondering what the best way would be to do this. For
eventfd and timerfd you need to read an 8-byte value. For signalfd,
you need to read a struct signalfd_siginfo.

I looked at doing something like:

//sys Read_(fd int, p uintptr) (n int, errno int) = SYS_READ

so that you can write:

var info syscall.SignalfdSiginfo
syscall.Read_(int(sigfd), uintptr(unsafe.Pointer(&info)))

but it seems a bit ugly. Any ideas on a better way to organise this
would be appreciated.

Cheers

Albert

Ian Lance Taylor

unread,
Jun 4, 2010, 1:44:08 PM6/4/10
to Albert Strasheim, golang-dev
Albert Strasheim <ful...@gmail.com> writes:

One option would be to add a new ByteOrder to the encoding/binary
package: HostByteOrder (or perhaps NativeByteOrder). Then you could
pass that to binary.Read.

Ian

Russ Cox

unread,
Jun 4, 2010, 2:49:42 PM6/4/10
to Albert Strasheim, golang-dev
> The current signature for Read looks like this:
>
> func Read(fd int, p []byte) (n int, errno int)

There is also a func read, which takes fd int, p *byte, n int.

syscall.read(sigfd, (*byte)(unsafe.Pointer(&info)), unsafe.Sizeof(info))

Russ

Albert Strasheim

unread,
Jun 8, 2010, 11:01:58 AM6/8/10
to golang-dev
Hello
I might be missing something obvious, but how can this unexported read
function be accessed outside the syscall package?

Regards

Albert

Russ Cox

unread,
Jun 8, 2010, 3:42:36 PM6/8/10
to Albert Strasheim, golang-dev
> I might be missing something obvious, but how can this unexported read
> function be accessed outside the syscall package?

It can't. But I assumed that you would be putting
implementations of new system calls in the syscall package.

Russ

Albert Strasheim

unread,
Jun 9, 2010, 2:13:50 AM6/9/10
to golang-dev
Hello
Right.

So perhaps we want add something like the following to syscall:

func ReadEventfd(fd int, counter *uint64) (n int, errno int)
func ReadTimerfd(fd int, expirations *uint64) (n int, errno int)
func ReadSignalfd(fd int, info *SignalfdSiginfo) (n int, errno int)

and have these functions call syscall.read in their implementation?

Regards

Albert

Russ Cox

unread,
Jun 9, 2010, 3:20:51 AM6/9/10
to Albert Strasheim, golang-dev
> So perhaps we want add something like the following to syscall:
>
> func ReadEventfd(fd int, counter *uint64) (n int, errno int)
> func ReadTimerfd(fd int, expirations *uint64) (n int, errno int)
> func ReadSignalfd(fd int, info *SignalfdSiginfo) (n int, errno int)
>
> and have these functions call syscall.read in their implementation?

Sure.

Russ

Reply all
Reply to author
Forward
0 new messages