SharedMemory between different processes in Android

914 views
Skip to first unread message

Iker Jamardo

unread,
May 30, 2016, 9:31:59 AM5/30/16
to Chromium-discuss
Hello everyone,

I am new to Chromium and I am looking for some basic guidance on how to get SharedMemory to work on Android. I need to have a SharedMemory block shared between a webkit/blink IDL class and my implementation in the Android webview of a library. My biggest doubt is on how to effectively share the SharedMemory. I have been digging into the shared_memory_unittest.cc file and although I see a MultiProcess example, it seems it is using the CreateNamedDeprecated approach that AFAIK is not supported on Android. I am guessing I am missing the passing of the SharedMemory object through IPC but I definitively do not have a clue on how to do so.

Could you point me on any tutorial, document or source code file that effectively shows how to share memory between different processes on Android? I would also love to learn how the GL command buffer works (as I am guessing it is using this same mechanism I am looking for). I have read https://www.chromium.org/developers/design-documents/gpu-command-buffer but it only provides a high level overview.

Thank you very much in advance. Any help would be much appreciated!

Regards,
Iker

Primiano Tucci

unread,
May 30, 2016, 3:20:45 PM5/30/16
to ik...@ludei.com, Chromium-discuss
Android WebView is single process (everything is hosted in the same process).
Why do you need any SharedMemory at all? If your use case if WebView you don't need any IPC at all.

In the more general case, instead, you want to take a look to usages of SharedMemory::ShareToProcess.


--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

Anand

unread,
May 30, 2016, 5:57:14 PM5/30/16
to Chromium-discuss, ik...@ludei.com
On Tuesday, May 31, 2016 at 5:20:45 AM UTC+10, Primiano wrote:
Android WebView is single process (everything is hosted in the same process).
Why do you need any SharedMemory at all? If your use case if WebView you don't need any IPC at all.

In the more general case, instead, you want to take a look to usages of SharedMemory::ShareToProcess.

Please don't use SharedMemory::ShareToProcess (and friends) in any new code. Those are effectively deprecated. Instead, use the SharedMemoryHandle as an IPC argument and the IPC system will do the right thing.

Iker Jamardo

unread,
Jun 1, 2016, 11:32:20 AM6/1/16
to Anand, Chromium-discuss
Hello,

I have some code in the WebView side and some code in the Chromium WebIDL side. I would like an object to be shared between the two libraries (.so-s) and AFAIK each library has it's own memory/process (correct me if I am wrong).

If to solve this problem I would need shared memory as I suspect, please, provide some insight on how to pass the SharedMemoryHandle through IPC so I can create it in one of the libraries but share it with the other.

Sorry if this sounds as something I should know but I am new to Chromium.

Thank you very much in advance! Any help would be much appreciated!
--
Iker Jamardo
CTO @ Ludei
http://ludei.com
156 2nd Street
San Francisco
CA, 94105

Torne (Richard Coles)

unread,
Jun 1, 2016, 12:53:42 PM6/1/16
to ik...@ludei.com, Anand, Chromium-discuss
No, there is only one process in WebView. The rendering engine runs in the same process as the Java app using the WebView. There's no need to share memory across processes here.

Torne (Richard Coles)

unread,
Jun 3, 2016, 6:51:42 AM6/3/16
to Iker Jamardo, Anand, Chromium-discuss
On Fri, 3 Jun 2016 at 01:33 Iker Jamardo <ik...@ludei.com> wrote:
Ok, so you mean that if I define a singleton class in one library (compiled and linked in a SO shared library) and reference it on a different one (another SO shared library that links against the first one), I should be able to use this "global" variable?

I have tested it and it seems to work but confirmation that I am not doing anything wrong that might arise in the future while the app is executing would be ideal.

Yes, in single-process WebView you can just use globals if that's easiest. We're working on a multiprocess mode for WebView, but this won't be supported on existing OS versions and isn't shipping yet.
 
Also, would this schema work on other systems such as Windows or Linux?

No. It won't even work on the regular Android version of Chromium - it *only* works in WebView, which currently always runs in single-process mode.
 
Thank you very much for taking the time to respond.

Regards,
Iker

Iker Jamardo

unread,
Jun 3, 2016, 3:01:25 PM6/3/16
to Torne (Richard Coles), Anand, Chromium-discuss
Ok, so you mean that if I define a singleton class in one library (compiled and linked in a SO shared library) and reference it on a different one (another SO shared library that links against the first one), I should be able to use this "global" variable?

I have tested it and it seems to work but confirmation that I am not doing anything wrong that might arise in the future while the app is executing would be ideal.

Also, would this schema work on other systems such as Windows or Linux?

Thank you very much for taking the time to respond.

Regards,
Iker
On Wed, Jun 1, 2016 at 9:53 AM, Torne (Richard Coles) <to...@chromium.org> wrote:

Iker Jamardo

unread,
Jun 6, 2016, 9:27:56 AM6/6/16
to Torne (Richard Coles), Anand, Chromium-discuss
Thank you for the explanation! I managed to create a prototype and it works.

For Chrome Android and other systems I would need to use SharedMemory right? How does the IPC work for sharing the SharedMemoryHandle? Is there any good/easy code samples I could look at?

Thanks once again!
Reply all
Reply to author
Forward
0 new messages