Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nacl: support sel_ldr_x86_64 -h/-r/-w etc fd passing #7930

Open
gopherbot opened this issue May 3, 2014 · 3 comments

Comments

@gopherbot
Copy link

commented May 3, 2014

It seems the nacl syscall package's "var files" trickery does not let it
access nacl fds other than 0,1,2. Being able to access open files passed in by the
parent would be nice for things like safely running a query over file contents.

Running go tip f613443b.

How to reproduce:

cat read.go && GOOS=nacl GOARCH=amd64p32 go build -o read read.go &&
sel_ldr_x86_64 -r10:10 ./read 10<read.go
package main

import (
    "fmt"
    "log"
    "syscall"
)

func main() {
    buf := make([]byte, 8192)
    n, err := syscall.Read(10, buf)
    if err != nil {
        log.Printf("read error: %s", err)
    } else {
        fmt.Printf("read %d %q\n", n, buf[:n])
    }
}
[30054,1836660608:14:11:08.380778] Native Client module will be loaded at base address
0x00004fc600000000
runtime: nacl_exception_stack: error 38
runtime: nacl_exception_handler: error 38
runtime: nacl_exception_stack: error 38
runtime: nacl_exception_handler: error 38
runtime: nacl_exception_stack: error 38
runtime: nacl_exception_handler: error 38
runtime: nacl_exception_stack: error 38
runtime: nacl_exception_handler: error 38
2014/05/03 21:11:08 read error: Bad file number
[30054,1836447488:14:11:08.398073]
NaClRuntimeHostInterfaceReportExitStatus(0x7fa56df36040, 0x0)

The only creation of type naclFile seem to be in fd_nacl.go init(), for fds 0, 1, 2.


As a proof of concept, these two work:

diff --git i/src/pkg/syscall/fd_nacl.go w/src/pkg/syscall/fd_nacl.go
index cbc8315..d157085 100644
--- i/src/pkg/syscall/fd_nacl.go
+++ w/src/pkg/syscall/fd_nacl.go
@@ -318,3 +318,7 @@ func Pipe(fd []int) error {
        fd[1] = newFD(&pipeFile{wr: q})
        return nil
 }
+
+func OpenNacl(naclFD int) (fd uintptr) {
+       return uintptr(newFD(&naclFile{naclFD: naclFD}))
+}


package main

import (
    "io"
    "log"
    "os"
    "syscall"
)

func main() {
    fd := syscall.OpenNacl(10)
    f := os.NewFile(fd, "/dev/fd/10")
    n, err := io.Copy(os.Stdout, f)
    log.Println(n, err)
}
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 5, 2014

Comment 1:

Labels changed: added repo-main, os-nativeclient, release-go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented May 11, 2014

Comment 2:

Labels changed: added release-none, removed release-go1.3maybe.

Status changed to Accepted.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Jun 19, 2014

Comment 3:

Passing an FD for a listening TCP/unix domain socket would be really nice too.

@rsc rsc removed the os-nativeclient label Apr 10, 2015

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc added OS-NaCl and removed release-none labels Apr 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.