Basic Queries on pNacl and Chrome

245 views
Skip to first unread message

Anoop Singh

unread,
Feb 3, 2016, 12:08:58 PM2/3/16
to Native-Client-Discuss
Hi Members,

I need the answer for some basic queries on pNaCl and chrome browser communication.
Here are my queries:

1. Do we always need

    pp::Instance class HandleMessage(), PostMessage())

    pp::Module class

    pp::Var class

to be implemented in our code to make communication possible between browser and pNaCl library.

 

2. Can we have any document stored in hard disk of the system and it can be accessible from chrome browser through pNaCl library? How ?

 

3. Does communication between chrome browser and pNaCl library only a possibility or is it possible between chrome extension and pNaCl and also between chrome app and pNaCl?


4. Does chrome browser has capability of storage while processing or communicating with pNaCl library and how?


Thanks in advance for the guidance.


With best regards,

Anoop.


Sam Clegg

unread,
Feb 4, 2016, 12:46:21 PM2/4/16
to native-cli...@googlegroups.com
On Wed, Feb 3, 2016 at 9:08 AM, Anoop Singh <aks....@gmail.com> wrote:
> Hi Members,
>
> I need the answer for some basic queries on pNaCl and chrome browser
> communication.
> Here are my queries:
>
> 1. Do we always need
>
> pp::Instance class HandleMessage(), PostMessage())
>
> pp::Module class
>
> pp::Var class
>
> to be implemented in our code to make communication possible between browser
> and pNaCl library.

Basically yes, although if you use the ppapi_simple library it hides a
lot of those details.

>
> 2. Can we have any document stored in hard disk of the system and it can be
> accessible from chrome browser through pNaCl library? How ?

In general, you can only do the same things that you could already do
from JavaScript. So for file access to the users hard disk you are
basically limited to the "Save As", "Open File" type interactions.
You would need to trigger these actions from JavaScript and pass the
data to and from the NaCl module with the PostMessage API.

>
> 3. Does communication between chrome browser and pNaCl library only a
> possibility or is it possible between chrome extension and pNaCl and also
> between chrome app and pNaCl?

NaCl modules can live within an extension or and app or a normal tab,
just like any other DOM element.

>
>
> 4. Does chrome browser has capability of storage while processing or
> communicating with pNaCl library and how?

You can use the PPAPI filesystem API if you want to save and load
files specific to you application (more precisely, your origin). See:
https://developer.chrome.com/native-client/devguide/coding/file-io

>
>
> Thanks in advance for the guidance.
>
>
> With best regards,
>
> Anoop.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at https://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

Anoop Singh

unread,
Feb 5, 2016, 12:22:06 PM2/5/16
to Native-Client-Discuss

Hi Sam,

You really rock. Thanks a lot for answering my queries. Here is some more queries.

1. Can a chrome browser support multiple .pexe at a time? As i understand it can not as from manifest.nmf file we can refer on .pexe at a time. If possible, is there any example?

2. Let us say, if i have a static library "LIB.a" which does some conversion operation on a simple document. If i build it with pnacl i get static library created "LIB.a" which is pNaCl compatible. Now if i want to send a document from the browser (javascript) to pNacl library to do the conversion operation, how can i do it? How to pass this document as parameter to  pNaCl from javascript? Can i write a C or CPP file which will have functionality of getting the document from javascript and i will build this file to get .pexe using the static library "LIB.a" ? I am creating .pexe as chrome browser ultimately need .pexe to communicate.
Can you please put some light on it as to how to achieve it? Can you let me know the simple steps to do it and test it?

3. Can we deploy this created .pexe directly on browser using manifest.nmf file?

4. I see ppapi_sample examples in nacl_sdk and when i run "make" i got background.js, .pexe, _nmf etc, files getting created. How does "make" command create background.js file and _nmf file? I hope  i need to get all these for my above implementation too?

Thanks a lot in advance.

With best regards,
Anoop.

Sam Clegg

unread,
Feb 5, 2016, 12:37:51 PM2/5/16
to native-cli...@googlegroups.com
On Fri, Feb 5, 2016 at 9:22 AM, Anoop Singh <aks....@gmail.com> wrote:
>
> Hi Sam,
>
> You really rock. Thanks a lot for answering my queries. Here is some more
> queries.
>
> 1. Can a chrome browser support multiple .pexe at a time? As i understand it
> can not as from manifest.nmf file we can refer on .pexe at a time. If
> possible, is there any example?

Yes, an new nacl module is created for each embed tag you create.
You can use the same nmf or different nmfs for each embed tag.

>
> 2. Let us say, if i have a static library "LIB.a" which does some conversion
> operation on a simple document. If i build it with pnacl i get static
> library created "LIB.a" which is pNaCl compatible. Now if i want to send a
> document from the browser (javascript) to pNacl library to do the conversion
> operation, how can i do it? How to pass this document as parameter to pNaCl
> from javascript? Can i write a C or CPP file which will have functionality
> of getting the document from javascript and i will build this file to get
> .pexe using the static library "LIB.a" ? I am creating .pexe as chrome
> browser ultimately need .pexe to communicate.
> Can you please put some light on it as to how to achieve it? Can you let me
> know the simple steps to do it and test it?

Yes, you need to create an executable (.pexe) that uses your library.
The executable will want to receive documents from JavaScript using
the PostMessage API. You can use the ppapi or ppapi_cpp libraries
directly, or you can use ppapi_simple, which might make your code
simpler.

>
> 3. Can we deploy this created .pexe directly on browser using manifest.nmf
> file?

Yes. Just create an embed tag with 'src' pointing your nmf.

>
> 4. I see ppapi_sample examples in nacl_sdk and when i run "make" i got
> background.js, .pexe, _nmf etc, files getting created. How does "make"
> command create background.js file and _nmf file? I hope i need to get all
> these for my above implementation too?

That example code has a lot of JavaScript boilerplate that you can
crib from, but a lot of complexity in there won't be needed if you
only targeting PNaCl.

Anoop Singh

unread,
Feb 8, 2016, 12:05:18 PM2/8/16
to Native-Client-Discuss

Hi Sam,

Thanks for great response. I understood how can i create multiple .pexe and use them in browser through embed tag.

A question regarding building .pexe. I built static library using pnacl toolchain separately  "LIB.a", and then I want to get .pexe out of it by compiling hello_tutorial.cc file and including "LIB.a", i tried this command, but it threw error:

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lLIB.a


hello_tutorial.cc:65:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

    auto message = var_message.AsString();

    ^

1 warning generated.

pnacl-ld: Cannot find '-lLIB.a'


I have copied "LIB.a" at specified place. What could be wrong here?

2. Could you please point me a Sample code to how to use ppapi lib directly or ppapi_simple in view of getting a document from javascript into .pexe and send it to a specific API present in static library which was built with .pexe as above?

3. Is there a way that chrome saves a document into a file system and pnacl can read the document from that file system? What type of file system is it? What are the API’s? Is there any example?


I appreciate your help in advance.


Thanks & regards,

Anoop.

Anoop Singh

unread,
Feb 8, 2016, 12:17:29 PM2/8/16
to Native-Client-Discuss
Hi Sam,

Thanks for great response. I understood how can i create multiple .pexe and use them in browser through embed tag.

A question regarding building .pexe. I built static library using pnacl toolchain separately  "LIB.a", and then I want to get .pexe out of it by compiling hello_tutorial.cc file and including "LIB.a", i tried this command, but it threw error:

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lLIB.a


hello_tutorial.cc:65:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

    auto message = var_message.AsString();

    ^

1 warning generated.

pnacl-ld: Cannot find '-lLIB.a'


I have copied "LIB.a" at specified place. What could be wrong here?

2. Could you please point me a Sample code to how to use ppapi lib directly or ppapi_simple in view of getting a document from javascript into .pexe and send it to a specific API present in static library which was included to with .pexe as above case?

3. Is there a way that chrome extension saves a document into a file system and pnacl can read the document from that file system? What type of file system is it? What are the API’s? Is there any example?


I appreciate your help in advance.


Thanks & regards,

Anoop.

On Monday, February 8, 2016 at 10:35:18 PM UTC+5:30, Anoop Singh wrote:

Hi Sam,

Thanks for great response. I understood how can i create multiple .pexe and use them in browser through embed tag.

A question regarding building .pexe. I built static library using pnacl toolchain separately  "LIB.a", and then I want to get .pexe out of it by compiling hello_tutorial.cc file and including "LIB.a", i tried this command, but it threw error:

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lLIB.a


hello_tutorial.cc:65:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

    auto message = var_message.AsString();

    ^

1 warning generated.

pnacl-ld: Cannot find '-lLIB.a'


I have copied "LIB.a" at specified place. What could be wrong here?

2. Could you please point me a Sample code to how to use ppapi lib directly or ppapi_simple in view of getting a document from javascript into .pexe and send it to a specific API present in static library which was built with .pexe as above?

3. Is there a way that chrome saves a document into a file system and pnacl can read the document from that file system? What type of file system is it? What are the API’s? Is there any example?


I appreciate your help in advance.


Thanks & regards,

Anoop.

<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="t

Victor Khimenko

unread,
Feb 8, 2016, 3:45:55 PM2/8/16
to Native Client Discuss
On Mon, Feb 8, 2016 at 6:05 PM, Anoop Singh <aks....@gmail.com> wrote:

Hi Sam,

Thanks for great response. I understood how can i create multiple .pexe and use them in browser through embed tag.

A question regarding building .pexe. I built static library using pnacl toolchain separately  "LIB.a", and then I want to get .pexe out of it by compiling hello_tutorial.cc file and including "LIB.a", i tried this command, but it threw error:

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lLIB.a


hello_tutorial.cc:65:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

    auto message = var_message.AsString();

    ^

1 warning generated.

pnacl-ld: Cannot find '-lLIB.a'


I have copied "LIB.a" at specified place. What could be wrong here?

The name of library. LIB.a couldn't be used. Usually you strip prefix "lib" and suffix ".a" then specify the "stem" in the -l option (-lstdc++ uses file "libstdc++.a", e.g.), but with name "LIB.a" said "steam" is empty thus you couldn't use it. Also don't forget that order of libraries matter:
 

Anoop Singh

unread,
Feb 8, 2016, 9:59:10 PM2/8/16
to Native-Client-Discuss
Hi Khim,

Thanks. It works for me now.

With best regards,
Anoop.

Anoop Singh

unread,
Feb 8, 2016, 10:03:12 PM2/8/16
to Native-Client-Discuss

Hi Sam,

Thanks for the valuable guidance. 

1. Is there a way that chrome extension saves a document into a file system and pnacl can read the document from that file system? What type of file system is it? What are the API’s to support it? Is there any example? Please also point a link where I can read about it.

2. Could you please point me a Sample code to how to use ppapi lib directly or ppapi_simple in view of getting a document from javascript(chrome extension or browser) into .pexe and send it to a specific function present in static library which was built with .pexe ?


I appreciate your help in advance.


Thanks & regards,

Anoop.

Ben Smith

unread,
Feb 9, 2016, 1:07:12 PM2/9/16
to Native-Client-Discuss


On Monday, February 8, 2016 at 7:03:12 PM UTC-8, Anoop Singh wrote:

Hi Sam,

Thanks for the valuable guidance. 

1. Is there a way that chrome extension saves a document into a file system and pnacl can read the document from that file system? What type of file system is it? What are the API’s to support it? Is there any example? Please also point a link where I can read about it.

Yes, you can use the Filesystem API, which is also a web API. It seems unlikely that it will be supported by other browsers, but it is used in many places in Chrome. Take a look at the file_io example (in examples/api/file_io in the SDK). It doesn't use the JavaScript Filesystem API, but it shows you how to request permanent storage so you can use the Pepper API.

Take a look at the thttpd port in webports for an example of sharing the filesystem between JavaScript and Native Client. 
 

2. Could you please point me a Sample code to how to use ppapi lib directly or ppapi_simple in view of getting a document from javascript(chrome extension or browser) into .pexe and send it to a specific function present in static library which was built with .pexe ?

I don't think there's an example of this.

Anoop Singh

unread,
Feb 15, 2016, 10:17:28 AM2/15/16
to Native-Client-Discuss
Hi Ben,

Thanks a lot for the info. I was able to learn through file_io examples as you pointed it.

I have one query, I have a static library (e.g., libwork.a ) which i built using pnacl toolchain. I included this library while building my CPP code to create pexe using pnacl toolchain.

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lwork



Could you please tell me how can i test that library (libwork.a) is included in pexe? Like in linux we have commands ldd which tells what all libraries included with executable?
Is there any such command? Let me know if there is any other way of testing it.

Thanks & regards,
Anoop.

Ben Smith

unread,
Feb 15, 2016, 1:18:23 PM2/15/16
to Native-Client-Discuss


On Monday, February 15, 2016 at 7:17:28 AM UTC-8, Anoop Singh wrote:
Hi Ben,

Thanks a lot for the info. I was able to learn through file_io examples as you pointed it.

I have one query, I have a static library (e.g., libwork.a ) which i built using pnacl toolchain. I included this library while building my CPP code to create pexe using pnacl toolchain.

./pnacl-clang++   hello.pexe   hello_tutorial.cc   -Inacl_sdk/pepper_47/include/   -L/home/anoop/testProgram   -lwork

This line looks wrong. It should be "-o hello.bc" instead of "hello.pexe". The output from Clang is an LLVM bitcode file which must be finalized by pnacl-finalize before it can be run:

pnacl-finalize -o hello.pexe hello.bc
 



Could you please tell me how can i test that library (libwork.a) is included in pexe? Like in linux we have commands ldd which tells what all libraries included with executable?
Is there any such command? Let me know if there is any other way of testing it.

Well, if your executable needs a symbol that is only provided by the library then it won't link unless the library is being used. You can use llvm-nm to see the list of symbols. Here I'm running it on the graphics3d example, piping it through c++filt to demangle the C++ symbols:

$ llvm-nm graphics_3d_unstripped.bc | c++filt
     ...
     d (anonymous namespace)::kCubeIndexes
     d (anonymous namespace)::kFragShaderSource
     d (anonymous namespace)::kVertexShaderSource
     t Graphics3DModule::CreateInstance(int)
     t Graphics3DModule::~Graphics3DModule()
     t Graphics3DInstance::DidChangeView(pp::View const&)
     t Graphics3DInstance::HandleMessage(pp::Var const&)
     t Graphics3DInstance::Init(unsigned int, char const**, char const**)
     t Graphics3DInstance::Render()
     t Graphics3DInstance::Animate()
     t Graphics3DInstance::MainLoop(int)
     t Graphics3DInstance::~Graphics3DInstance()
     t Graphics3DInstance::~Graphics3DInstance()
     t pp::Graphics3D::SwapBuffers(pp::CompletionCallback const&)
     t pp::Graphics3D::~Graphics3D()
     t pp::Graphics3D::~Graphics3D()
     ...

Anoop Singh

unread,
Feb 16, 2016, 12:34:34 PM2/16/16
to Native-Client-Discuss
Hi Ben,

Thanks a lot for the info and corrections.
I want to let you know that all build and operations i am doing on linux(ubuntu) machine.

Actually, I followed these commands to create pexe.
first i ran below command to get hello.o
 ./pnacl-clang++  -c  hello_tutorial.cc  -o  hello.o  -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release/ -lwor

then i created .pexe out of it using command
./pnacl-clang++  hello.pexe  -o  hello.o

and finalized it hello.pexe using this command to generate again hello.pexe only
./pnacl-finalize hello.pexe hello.pexe

I checked this pexe in chrome browser and it works fine.

Do i need to create .bc first mandatorily and not object file? What is the difference b/w two commands ..one uses –c and one –o and create object file.

I created hello.bc file also to follow your instruction

./pnacl-clang++  -c  hello_tutorial.cc  -o  hello.bc  -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release/  -lwork

but when i ran pnacl-finalize command like below I got the error
./pnacl-finalize -o hello.pexe hello.bc
LLVM ERROR: Struct types are not supported in PNaCl bitcode
Why is this error? How to fix this?

In your example you have run llvm-nm command on unstripped.bc file so i ran command like below and got the error
llvm-nm hello.bc
llvm-nm: hello.bc: Invalid value.

When i do llvm-nm for hello.pexe it says
llvm-nm: hello.pexe: unrecognizable file type
 Some times it says invalid record. What could be the issue?

While building one c file using pnacl-clang i got this error
fatal error: 'net/if.h' file not found
This seems to be that net/if.h is not supported. But this program compiles using gcc on linux but pnacl-clang build on linux shows the above said error. How to fix it?

Thanks in advance for all help and guidance.

With regards,
Anoop.

Ben Smith

unread,
Feb 16, 2016, 5:54:17 PM2/16/16
to Native-Client-Discuss
On Tuesday, February 16, 2016 at 9:34:34 AM UTC-8, Anoop Singh wrote:
Hi Ben,

Thanks a lot for the info and corrections.
I want to let you know that all build and operations i am doing on linux(ubuntu) machine.

Actually, I followed these commands to create pexe.
first i ran below command to get hello.o
 ./pnacl-clang++  -c  hello_tutorial.cc  -o  hello.o  -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release/ -lwor

then i created .pexe out of it using command
./pnacl-clang++  hello.pexe  -o  hello.o

and finalized it hello.pexe using this command to generate again hello.pexe only
./pnacl-finalize hello.pexe hello.pexe

I checked this pexe in chrome browser and it works fine.

Do i need to create .bc first mandatorily and not object file? What is the difference b/w two commands ..one uses –c and one –o and create object file.

I created hello.bc file also to follow your instruction

./pnacl-clang++  -c  hello_tutorial.cc  -o  hello.bc  -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release/  -lwork

This isn't working because -c is making it compile without linking. You can either do this:

# compile hello_tutorial.cc into the object file hello_tutorial.o
pnacl-clang++ -c hello_tutorial.cc -o hello_tutorial.o -I/home/anoop/nacl_sdk/pepper_47/include/

# link hello_tutorial.o into a LLVM bitcode file
pnacl-clang++ -o hello.bc hello_tutorial.o -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork

# finalize the LLVM bitcode file into a PNaCl pexe
pnacl-finalize -o hello.pexe hello.bc
 
or this:

# compile and link in one step
pnacl-clang++ -o hello.bc hello_tutorial.c -I/home/anoop/nacl_sdk/pepper_47/include/ -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork

# finalize the LLVM bitcode file into a PNaCl pexe
pnacl-finalize -o hello.pexe hello.bc

The confusing part here is the LLVM bitcode file. In a normal toolchain, this would be the executable. PNaCl uses a binary format that is based on LLVM bitcode format, but it has been stabilized (i.e. the format will not change, whereas the LLVM bitcode format can and does change). That is the purpose of the finalization step: to turn the unstable LLVM binary format into the stable PNaCl executable binary format.


but when i ran pnacl-finalize command like below I got the error
./pnacl-finalize -o hello.pexe hello.bc
LLVM ERROR: Struct types are not supported in PNaCl bitcode
Why is this error? How to fix this?

In your example you have run llvm-nm command on unstripped.bc file so i ran command like below and got the error
llvm-nm hello.bc
llvm-nm: hello.bc: Invalid value.

I'm not sure why this isn't working for you. What does it say if you run "file hello.bc". In any case, if you follow the steps I gave above, it should work.
 

When i do llvm-nm for hello.pexe it says
llvm-nm: hello.pexe: unrecognizable file type
 Some times it says invalid record. What could be the issue?

llvm-nm expects to be given LLVM bitcode files, not a pexe.
 

While building one c file using pnacl-clang i got this error
fatal error: 'net/if.h' file not found
This seems to be that net/if.h is not supported. But this program compiles using gcc on linux but pnacl-clang build on linux shows the above said error. How to fix it?

This is not provided by newlib (the C library used by PNaCl). You can find a copy of the header in glibc-compat in webports, but AFAIK it won't provide any functionality. Your best bet is to remove it from whatever source is using it.

Anoop Singh

unread,
Feb 17, 2016, 12:05:02 PM2/17/16
to Native-Client-Discuss
Hi Ben,

Thanks for elaborated info. It solved almost all issues which i was facing. I am able to link the library successfully and create .pexe.
One more small help i need,
I want my chrome browser to read a file from any supported file system (file which is saved by chrome extension) through pexe and send it as a parameter to my library(lwork) function(e.g., performThis()), something like shown below

hello.cpp
status = performThis("D:/abc.txt", "XX.XX.XX.XX");   //I need to know what to replace at file ("D:/abc.txt") place.

Here i am reading from D drive directlt just to show what i need to do and understand it is not possible perhaps from chrome browser using pnacl library.
How could i achieve this in my cpp file and build it to create pexe?
I will build using the command
pnacl-clang++ -o hello.bc hello.cpp -I/home/anoop/nacl_sdk/pepper_47/include/ -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork

I think the file_io as you said earlier should be able to do this but I am not sure how? Your guidance will be highly appreciated.

Many thanks in advance.

Thanks & regards,
Anoop.

Ben Smith

unread,
Feb 18, 2016, 1:47:37 PM2/18/16
to Native-Client-Discuss


On Wednesday, February 17, 2016 at 9:05:02 AM UTC-8, Anoop Singh wrote:
Hi Ben,

Thanks for elaborated info. It solved almost all issues which i was facing. I am able to link the library successfully and create .pexe.
One more small help i need,
I want my chrome browser to read a file from any supported file system (file which is saved by chrome extension) through pexe and send it as a parameter to my library(lwork) function(e.g., performThis()), something like shown below

hello.cpp
status = performThis("D:/abc.txt", "XX.XX.XX.XX");   //I need to know what to replace at file ("D:/abc.txt") place.

Take a look at the nacl_io_demo, it shows you how to mount a filesystem. This recent thread is asking a similar question too.
 

Here i am reading from D drive directlt just to show what i need to do and understand it is not possible perhaps from chrome browser using pnacl library.
How could i achieve this in my cpp file and build it to create pexe?
I will build using the command
pnacl-clang++ -o hello.bc hello.cpp -I/home/anoop/nacl_sdk/pepper_47/include/ -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork

I think the file_io as you said earlier should be able to do this but I am not sure how? Your guidance will be highly appreciated.

This ultimately will use the FileIO interface, but it's easier to use nacl_io because it wraps the PPAPI interface in the normal C way, so you can use fopen/fread, etc.

Anoop Singh

unread,
Feb 19, 2016, 12:00:33 PM2/19/16
to Native-Client-Discuss

Hi Ben,

Thanks for the help and guidance.

I checked the nacl_io_demo and the other discussion thread which you pointed out. It gave me some idea.
While implementing i took the same code of the thread but i faced one issue, I have mounted the filesystem like this

class HelloTutorialInstance : public pp::Instance {

public:

  explicit HelloTutorialInstance(PP_Instance instance)

      : pp::Instance(instance) {

            // initialize nacl file system

      nacl_io_init_ppapi(instance, pp::Module::Get()->get_browser_interface());

           // mounting html5fs filesystem

           int result = mount("",  /* source. Use relative URL */

        "/fileSystemMount",  /* target */

                "html5fs", /* filesystemtype */

                0,        /* mountflags */

                "");      /* data */


This gives me that file is successfully mounted. Now when i pass message obtained from the extension which is a directory path of a file created by the extension and try to pass the same path to the library function which i build through pnacl toolchain, I am getting the path correctly in post message but function looks like not understanding the path.

virtual void HandleMessage(const pp::Var& var_message) {

    std::string message = var_message.AsString();

      int status = 0;

      char mount_path[100] = "/fileSystemMount/";

      char *messageptr = new char[message.length() + 1];

      strcpy(messageptr, message.c_str());

      std::strcat(mount_path, messageptr);

      status = performAction(mount_path, "XX.XX.XX.XX");  //this function is in the library -lwork

       PostMessage(status);

      delete [] messageptr;


If you see in the code in HandleMessage, performAction() function accepts a path, which is some directory path but now here i need to send the mount path as given by chrome. performAction() function is in library which is built with pnacl toolchain.

Here my function returns always 1 value which means it has not gotten the mount_path correctly. What could be the wrong in this? Is this not the correct way of doing? Does pnacl not understand this path?
nacl_io_demo shows that handle message needs to be called from the thread. But is this necessary?
I want to let you know that the above code file(hello.cc) I am compiling along with library to create pexe and this pexe is being used by extension to communicate.
./pnacl-clang++ -o hello.bc hello.cc -L/home/anoop/path/to/lib -lwork
./pnacl-finalize -o hello.pexe hello.bc

Many thanks in advance.

Thanks & regards,
Anoop.

Anoop Singh

unread,
Feb 22, 2016, 5:48:18 AM2/22/16
to Native-Client-Discuss
Hi Ben and Sam,

I tried to get the directory "mount_path" and list the files under it at but it is not able to open the directory which means "mount_path" directory is not available or accessible. 
DIR *dir;
      struct dirent *ent;
      if ((dir = opendir (mount_path)) != NULL) {
      /* print all the files and directories within directory */
      while ((ent = readdir (dir)) != NULL) {
        printf ("%s\n", ent->d_name);
        PostMessage(ent->d_name);
      }
      closedir (dir);
      } else {
        PostMessage("No such Directory");
     }
 
nacl_io_demo shows that handle message needs to be called from the thread. But is this necessary?
I want to let you know that the above code file(hello.cc) I am compiling along with library to create pexe and this pexe is being used by extension to communicate.
./pnacl-clang++ -o hello.bc hello.cc -L/home/anoop/path/to/lib -lwork
./pnacl-finalize -o hello.pexe hello.bc

Many thanks in advance. 

Thanks & regards,
Anoop.

...

Sam Clegg

unread,
Feb 22, 2016, 10:42:50 PM2/22/16
to native-cli...@googlegroups.com
I'm not sure exactly what you mean here, but if you are asked if the
POSIX file I/O functions need to be run on a background thread (not
the main thread), then the answer is yes. The main thread can't make
blocking calls and the POSIX file I/O functions mostly involve
blocking.

Anoop Singh

unread,
Feb 23, 2016, 8:44:46 PM2/23/16
to Native-Client-Discuss
Hi Sam and Ben,

Thanks for the guidance. Now I am able to mount the file system correctly from nacl module and able to access the directory and files created under it by the extension. 
 mount("",  /* source. Use relative URL */
          "/temporary/",  /* target */
          "html5fs", /* filesystemtype */
          0,        /* mountflags */
          "type=TEMPORARY,expected_size=1048576");

I understand that this file and directory can be understood by any function as per the pNaCl documentation.

As i said earlier, I have a library which is written in C and C++ code which performs read, open, popen etc operations on a file. here is the example function

status = performAction(filePath, "", "")    // first argument is the filePath. 

This code works fine with gcc build. 

I have built the above full code along with pNaCl toolchain to get a static library libwork.a. This library I link with my C++ code (hello.cc) where I have written pnacl file system mount code to get pexe out of it. Till here everything is fine.

./pnacl-clang++ -o hello.bc hello.cc -L/home/anoop/path/to/lib -lwork
./pnacl-finalize -o hello.pexe hello.bc

filePath passed to the above library function in Nacl module is "/temporary/job_1234/abc.txt". I am able to open this file from Nacl module using simple C++ code. 

But when I pass the filePath to my above mentioned library function in the hello.cc, it seems the path is not properly recognized by the function and it is not able to perform the action it needs to do on the file path.  What could be the reason? 

As i understand this filepath should be recognized correctly by the library function as both are now part of pnacl toolchain and pexe is running in chrome browser. 

Please let me know if there is any misconception from my side.

Thanks & regards,
Anoop.

Sam Clegg

unread,
Feb 23, 2016, 9:10:16 PM2/23/16
to native-cli...@googlegroups.com
On Tue, Feb 23, 2016 at 5:44 PM, Anoop Singh <aks....@gmail.com> wrote:
> Hi Sam and Ben,
>
> Thanks for the guidance. Now I am able to mount the file system correctly
> from nacl module and able to access the directory and files created under it
> by the extension.
> mount("", /* source. Use relative URL */
> "/temporary/", /* target */
> "html5fs", /* filesystemtype */
> 0, /* mountflags */
> "type=TEMPORARY,expected_size=1048576");
>
> I understand that this file and directory can be understood by any function
> as per the pNaCl documentation.
>
> As i said earlier, I have a library which is written in C and C++ code which
> performs read, open, popen etc operations on a file. here is the example
> function
>
> status = performAction(filePath, "", "") // first argument is the
> filePath.
>
> This code works fine with gcc build.
>
> I have built the above full code along with pNaCl toolchain to get a static
> library libwork.a. This library I link with my C++ code (hello.cc) where I
> have written pnacl file system mount code to get pexe out of it. Till here
> everything is fine.
>
> ./pnacl-clang++ -o hello.bc hello.cc -L/home/anoop/path/to/lib -lwork

Is this your full link line? I would expect to see at least -lppapi
when building a PNaCl module. You also want -lnacl_io in this case.

Anoop Singh

unread,
Feb 23, 2016, 9:15:08 PM2/23/16
to Native-Client-Discuss
Hi Sam,

I have added -lppapi and -lnacl_io. I forgot to mention that. Issue is the same.

Thanks & regards,
Anoop.

Anoop Singh

unread,
Feb 23, 2016, 9:19:26 PM2/23/16
to Native-Client-Discuss
Hi Sam,

Here is the full command used by me. 

 ./pnacl-clang++ -o hello.bc hello.cc -I/home/anoop/nacl_sdk/pepper_47/include/ -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lpdlconverter -lppapi_simple_cpp -lnacl_io -lppapi_cpp -lppapi

I didn't mention the full command in my example. Issue is the same.
Logically, library function must be able to access the nacl mounted path as the library does on linux system. 
Let me know what could be the issue?

Thanks & regards,
Anoop.

Anoop Singh

unread,
Feb 23, 2016, 9:20:47 PM2/23/16
to Native-Client-Discuss
Hi Sam,

Here is the full command used by me. 

 ./pnacl-clang++ -o hello.bc hello.cc -I/home/anoop/nacl_sdk/pepper_47/include/ -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork -lppapi_simple_cpp -lnacl_io -lppapi_cpp -lppapi


I didn't mention the full command in my example. Issue is the same.
Logically, library function must be able to access the nacl mounted path as the library does on linux system. 
Let me know what could be the issue?

Thanks & regards,
Anoop.

...

Sam Clegg

unread,
Feb 23, 2016, 10:48:13 PM2/23/16
to native-cli...@googlegroups.com
Are you calling the library function from a background thread?

What function is failing in the library and what error code is it giving?

Anoop Singh

unread,
Feb 23, 2016, 11:05:14 PM2/23/16
to Native-Client-Discuss
Hi Sam,

Here is my code

#include <stdio.h>
#include "sys/mount.h"
#include <dirent.h>
#include "nacl_io/nacl_io.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"

#include <ppapi/cpp/var.h>
#include "ppapi_simple/ps_main.h"
#include "ppapi_simple/ps_event.h"
#include "ppapi_simple/ps_interface.h"
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <fstream>

int file_test_main(int argc, char* argv[]) {

    PSEventSetFilter(PSE_ALL);
    // char str_buff[50];
   
    char mount_path[100];

    strcpy(mount_path,"/temporary/");

    // mount the http root at /http
    mount("",  /* source. Use relative URL */
          "/temporary/",  /* target */
          "html5fs", /* filesystemtype */
          0,        /* mountflags */
          "type=TEMPORARY,expected_size=1048576");      /* data */

    while (true) {
        PSEvent* ps_event;
        // Consume all available events
        while ((ps_event = PSEventWaitAcquire()) != NULL) {
        //while ((ps_event = PSEventTryAcquire()) != NULL) {
            // handle messages from javascript
            if (ps_event->type == PSE_INSTANCE_HANDLEMESSAGE) {
                // Convert Pepper Simple message to PPAPI C++ vars
                pp::Var var_message(ps_event->as_var);
                                //PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message.pp_var());
                // process the message if it is a string
                if (var_message.is_string()) {
                    // get the string message
                    std::string message = var_message.AsString();

                     char *messageptr = new char[message.length() + 1];
                     std::strcpy(messageptr, message.c_str());
                     pp::Var var_message2(mount_path);
                     PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message2.pp_var());

     int status = 0;
     std::strcat(mount_path, "/page");
    
     status = performAction(mount_path, 0, 0, 1, 1);
     pp::Var var_message3(status);
     PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message3.pp_var());

     delete [] messageptr;
     }
     }
     PSEventRelease(ps_event);
        }
    }
    return 0;
}

/*
 * Register the function to call once the Instance Object is initialized.
 * see: pappi_simple/ps_main.h
 */
PPAPI_SIMPLE_REGISTER_MAIN(file_test_main)

I built it using
/pnacl-clang++ -o hello.bc hello.cc -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release -lwork -lppapi_simple_cpp -lnacl_io -lppapi_cpp -lppap

This is the way I am doing, see the function performAction which is part of library -lwork which linked with hello.cc code to build pexe. libwork.a is static library converted using pnacl toolchain.

Thanks & regards,
Anoop.

Anoop Singh

unread,
Feb 24, 2016, 10:27:38 AM2/24/16
to Native-Client-Discuss
Hi Sam,

I am able to fix the issue which i was facing with the file system. The problem was in my static library. Please check code which i have given in my post once to check if still you see any issue.

Actually my library (libwork.a) also uses image image magick to perform some action. It uses binary "identify.exe" to run "identify format " command in the shell. But as of now Image magic I have not associated with the library. So it was failing.

Here, Could you please let me know that how can I execute shell command from chrome browser? Is it possible?
I have built image magick to get "identify.pexe". How can i execute shell command from the chrome browser using this pexe?

How can i include this identify.pexe along with my static library as earlier I was building my hello.cc file by and linking with my library (libwork.a) to get pexe, and now i have one more pexe to include or link with this?
So i was running this command earlier,
/pnacl-clang++ -o  hello.bc  hello.cc  -I/home/anoop/nacl_sdk/pepper_47/include/  -L/home/anoop/nacl_sdk/pepper_47/lib/pnacl/Release  -lwork -lppapi_simple_cpp -lnacl_io -lppapi_cpp -lppap

As my library uses image magick so built binary or library of image magick needs to be accessible by my library (libwork.a).
How Can i include identify.pexe into it to get one pexe? Ultimately i want to use one pexe which serves my work.

Is there any other approach to achieve this?

Thanks a lot in advance for the help.

Thanks & regards,
Anop.

Sam Clegg

unread,
Feb 24, 2016, 6:15:23 PM2/24/16
to native-cli...@googlegroups.com
Spawning/forking of external executable can only really be done via
JavaScript (since each executable it represented as its own DOM
elements and the DOM is controlled by JavaScript). We have a
framework for doing this in webports (see ports/nacl-spawn), but I
would imagine it more complicated than you need in this case. I would
advise you to modify your code to remove the call to the external
binary (perhaps you know the type of the file already and can pass
this information in? , or perhaps you could switch to using the
libImageMagick rather than relying on the external binary?).

cheers,
sam

Anoop Singh

unread,
Feb 26, 2016, 9:36:29 AM2/26/16
to Native-Client-Discuss
Hi Sam,

Thanks for the guidance. I am able to resolve the issue by changing the code which calls the binary.
Everything is working fine. Thanks again.

With best regards,
Anoop.

Anoop Singh

unread,
Feb 29, 2016, 9:56:06 AM2/29/16
to Native-Client-Discuss
Hi Sam and Ben,

I am able to call my pexe from the extension. My pexe is able to call  the function performAction() from the built library.
I was facing issue as my library uses socket connect and it was failing as there was no permission granted from the extension's manifest file for TCP. This issue is fixed now.

But in my Browser console i am seeing "NaCl module crashed". Is there any action needed from the extension to handle once the function is called from the library. here is the code which i used for your understanding of the issue.


int file_test_main(int argc, char* argv[]) {
     PSEventSetFilter(PSE_ALL);  
 
    char mount_path[100];
    char mount_pathNew[100];
    char logFile[] = "/temporary/log/pdl_converter.log";

    strcpy(mount_path,"/temporary/");
    strcpy(mount_pathNew,"/temporary/");  

    mount("",  /* source. Use relative URL */
          "/temporary/",  /* target */
          "html5fs", /* filesystemtype */
          0,        /* mountflags */
          "type=TEMPORARY,expected_size=1048576");      /* data */  

#if 1

    while (true) {
        PSEvent* ps_event;
        // Consume all available events
        while ((ps_event = PSEventWaitAcquire()) != NULL) {
             // handle messages from javascript
            if (ps_event->type == PSE_INSTANCE_HANDLEMESSAGE) {
                // Convert Pepper Simple message to PPAPI C++ vars
                pp::Var var_message(ps_event->as_var);

                //PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message.pp_var());
                // process the message if it is a string
                if (var_message.is_string()) {
                         // get the string message
                        std::string message = var_message.AsString();
                        char *messageptr = new char[message.length() + 1];
                        std::strcpy(messageptr, message.c_str());
                        std::strcat(mount_path, messageptr);
                        std::strcat(mount_pathNew, messageptr);

                        // Post Message mount_path to JavaScript

                        pp::Var var_message2(mount_path);
                        PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message2.pp_var());

                       int status = 0;                       
                        std::strcat(mount_pathNew, "/page");
                        status = performAction(logFile, mount_pathNew, "XX.XX.XX.XX", "Letter");
                        pp::Var var_message3(status);

                        PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var_message3.pp_var());
                        delete [] messageptr;
                        } /* End of if var_message is string */
                } /* End of if ps_event type */
                PSEventRelease(ps_event);
         } /* PSEventWaitAcquire Loop */
    } /* End of while (true) */
#endif

   return 0;
}
/*
* Register the function to call once the Instance Object is initialized.
* see: pappi_simple/ps_main.h
*/
PPAPI_SIMPLE_REGISTER_MAIN(file_test_main)

If you see the code performAction is called in the While loop of above code. I am not seeing the status value(which is returned by the function implemented in the library) on browser console. I feel here only the "Nacl module crash" has happened.  But all message which come before this called function are seen.
What could be the issue? Is there any  problem in handling the performAction output or is there any issue in  file_test_main() function itself? I am returning "0" from this function.
Does it mean that file_test_main() function still expecting message from extension and its not coming to it so the issue?

But as performAction return value is not printed means, issue can be there in the performAction function only. Am i right? How to identify and fix this issue?

Thanks & regards,
Anoop.

Ben Smith

unread,
Feb 29, 2016, 4:17:32 PM2/29/16
to Native-Client-Discuss
It's hard to tell where your crash is, it would probably be easiest to connect nacl-gdb and see where it crashed. If you don't want to bother with that, you may want to try printf debugging.

That said, I'd suggest that your use of strcpy/strcat makes me suspicious. It might be working, but just to be safe, you may want to use std::string for more of that, and convert to a C string as late as possible.

Sam Clegg

unread,
Mar 1, 2016, 2:59:03 PM3/1/16
to native-cli...@googlegroups.com
On Mon, Feb 29, 2016 at 6:56 AM, Anoop Singh <aks....@gmail.com> wrote:
> Hi Sam and Ben,
>
> I am able to call my pexe from the extension. My pexe is able to call the
> function performAction() from the built library.
> I was facing issue as my library uses socket connect and it was failing as
> there was no permission granted from the extension's manifest file for TCP.
> This issue is fixed now.

My understanding was that only apps and not extensions could use the
socket (TCP) APIs. I'm not sure if this is related to your crash on
startup though.

As ben says, try printf() and gdb debugging.

Anoop Singh

unread,
Mar 2, 2016, 12:14:10 AM3/2/16
to Native-Client-Discuss
Hi Sam and Ben,

Thanks for the kind reply. Using printf() statements i could identify the issue. There was handling issue of return value from an api which was causing this crash.

Sam, I am able to use socket API's which are there in my library through the pexe. This pexe is called by extensions only by using nmf file. It works without any issue.
This gives me solid opinion that extensions and apps both can use TCP socket api's though i have never tried calling socket api's from apps.

Thanks & regards,
Anoop.

Anoop Singh

unread,
Mar 2, 2016, 4:17:55 AM3/2/16
to Native-Client-Discuss
Hi Sam,

I am sorry for the confusion over my previous post. Its an app only. I am using tcp socket api from app only.

Thanks & regards,
Anoop.


On Wednesday, March 2, 2016 at 10:44:10 AM UTC+5:30, Anoop Singh wrote:
Hi Sam and Ben,

Anoop Singh

unread,
Mar 3, 2016, 10:12:40 AM3/3/16
to Native-Client-Discuss
Hi Sam and Ben,

I have some more queries regarding pNaCl.
1. How do we implement a wait condition in pNacCl? I mean to say If i want pNaCl module to perform some action once it has received all messages from javascript how can we achieve it? Here is the code where I need to wait

        while ((ps_event = PSEventWaitAcquire()) != NULL) {
               // handle messages from javascript
            if (ps_event->type == PSE_INSTANCE_HANDLEMESSAGE) {
                // Convert Pepper Simple message to PPAPI C++ vars
                pp::Var var_message(ps_event->as_var);                                
                // process the message if it is a string
                if (var_message.is_string()) {
                    // get the string message
                    std::string dirpath = var_message.AsString();
                     
//Here dirpath is a directory path (which is html5 file system path) sent by javascript and when all files are saved into this directory path then only i want to send this path to my performAction function. how to do this?
    like if there are three files in the directory i want to keep waiting until all three files are copied into the dirpath from javascript and then send only dirpath (dirpath without  any change) to below function. Otherwise the below function will be called thrice which is not required. 

     int status = performAction(dirpath, 0, 0, 1, 1);

     
2. How can we send and receive data of different types as key value pairs together from pNacl to javascript and from Javascript to pNaCl?

Thanks a lot in advance for the help.

With best regards,
Anoop.
Reply all
Reply to author
Forward
0 new messages