BSD socket() EACCES and libnacl_spawn?

26 views
Skip to first unread message

Gert Vierman

unread,
Feb 11, 2016, 2:21:28 AM2/11/16
to Native-Client-Discuss

Hello,

I've been running into some issues with a  PNaCL application using BSD sockets which I can reduce to a simple minimal application. The program has a normal main() entry point, and creates a AF_INET/SOCK_STREAM socket. The socket() call returns EACCESS (Permission denied), even though the manifest states the proper permissions.

After some digging around in a live sample using Curl, I found that my appication is working as expected when I link it with libnacl_spawn. I'm not able to find any proper documentation of this library, so I'm not sure what it's exact function is, and when I am supposed to link to it.

Can anyone explain what is happening, and why linking to nacl_spawn is required to get BSD sockets to work in my app?

Thank you,

Victor Khimenko

unread,
Feb 11, 2016, 4:29:19 AM2/11/16
to Native Client Discuss
It's most definitely not required since there are tons of apps which don't use nacl_spawn and use sockets. Are you sure you are not trying to access sockets from main thread? That wouldn't work and would explain why nacl_spawn saves your beacon: it creates "fake" main thread and runs your main there. Then all the code started from main is no longer on main thread...

Gert Vierman

unread,
Feb 12, 2016, 8:46:27 AM2/12/16
to Native-Client-Discuss

On Thursday, February 11, 2016 at 10:29:19 AM UTC+1, khim wrote:

It's most definitely not required since there are tons of apps which don't use nacl_spawn and use sockets.

That's what I thought. Thus my surprise when I found that linking to this lib solved my problem.
 
Are you sure you are not trying to access sockets from main thread? That wouldn't work and would explain why nacl_spawn saves your beacon: it creates "fake" main thread and runs your main there. Then all the code started from main is no longer on main thread...

I tried creating a 'fake main thread' myself by simply running all code in a separate pthread while the main thread is sleeping, but this gave me the same results. I'll try to reduce to a minimal example and post here later.

What then is the main purpose of nacl spawn? Is linking to it the preferred way of getting code to run on PNaCL without having to port specifically to this environment?

Victor Khimenko

unread,
Feb 12, 2016, 9:31:32 AM2/12/16
to Native Client Discuss, Sam Clegg
On Fri, Feb 12, 2016 at 2:46 PM, Gert Vierman <gert.v...@gmail.com> wrote:

On Thursday, February 11, 2016 at 10:29:19 AM UTC+1, khim wrote:

It's most definitely not required since there are tons of apps which don't use nacl_spawn and use sockets.

That's what I thought. Thus my surprise when I found that linking to this lib solved my problem.
 
Are you sure you are not trying to access sockets from main thread? That wouldn't work and would explain why nacl_spawn saves your beacon: it creates "fake" main thread and runs your main there. Then all the code started from main is no longer on main thread...

I tried creating a 'fake main thread' myself by simply running all code in a separate pthread while the main thread is sleeping, but this gave me the same results. I'll try to reduce to a minimal example and post here later.

This is kind of pointless. Sleeping main thread means "dead app" when you deal with PPAPI.

It's called "main thread" for historical reasons, but in reality it's "browser interface thread". ALL functions in PPAPI work asynchronously via messages sent to main thread. Any thread could send message to browser (few years ago this, too, was only allowed on main thread; that limitation was lifted couple of years back), but browser could only return something back to main thread.
 
What then is the main purpose of nacl spawn?

It's used to emulate posix_spawn function:

But as side-effect it pushed your main to a separate thread while the main thread remained free to interact with browser.
 
Is linking to it the preferred way of getting code to run on PNaCL without having to port specifically to this environment?

Yes and no. There are few libraries like this (nacl_io, ppapi_simple, etc) - they emulate POSIX api do larger or smaller degree. If you just use nothing then, of course, POSIX sockets wouldn't work, but which one is better to use in your particular case? This depends on the app. Sorry, I couldn't be more specific: the last time I've reviewed set of available POSIX-emulating libraries was a few years ago, I'm just not sure what's available now and what is better in which case.

Sam should know current situation with emulation libraries better than me, hopefully he'll help you to pick the right emulation library.

Reply all
Reply to author
Forward
0 new messages