Hi all,

I'm looking for a safe way to make a unix syscall where the syscall takes a 
pointer to a struct and, in turn, the struct needs to contain a pointer to 
a buffer (for the kernel to read or write to).

According to the rules in the unsafe package, I don't think this is safe:

buf := [128]byte{}
wrapper := someStruct{buf: &buf}
... := unix.Syscall(trap, uintptr(unsafe.Pointer(&wrapper)), ...)

The point to "wrapper" is protect from being moved by unsafe.Pointer's 
"Conversion of a Pointer to a uintptr when calling syscall.Syscall" rule 
but I think the pointer to buf within that struct is not safe from being 
rewritten.

Lots of ioctls use this pattern as does the BPF syscall.  At the moment, 
we're resorting to CGo to make those calls but it'd be nice to get rid of 
that.

One way I could see to solve this would be to do some manual memory 
management with MMap or BRK to allocate the buffer but I wondered if there 
was an easier way?

Cheers,
-Shaun

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1c41cd4e-6d54-43bd-98eb-b53cd9ca5598n%40googlegroups.com.

Reply via email to