2

I have two different Android Apps which both contain the same .so file. Could the global variables inside those .so files be shared across the two Apps or are they guaranteed to be isolated from each other.

I know that Android builds the isolation between Apps on top of Linux processes and Unix permissions among other things and from this answer I would deduce that on Linux those variable would be shared if two processes load the same .so file. However I guess it might depend on form where the .so file gets loaded and how the runtime maps the .so file to memory.

How does all of this fit together in Android? More specifically how can I guarantee isolation if I build an AAR which contians an .so file and the AAR might be used in different Apps that could run at the same time?

mschwaig
  • 551
  • 6
  • 19
  • Shared .so variables between different processes? Hard to believe! Remember: "Each process has its own address space, meaning that there is never any memory being shared between processes (unless you use some inter-process communication library or extensions)." Otherwise, global variables in .so-s would be the simplest form of interprocess-communication. This would be especially fine for any software with criminal intent - just link the same .so and read the complete users secrets out of global variables... I believe, even on Android it's not that simple. – Scheff's Cat Oct 27 '17 at 10:26
  • Actually, I really hope I'm right - as owner of a smart phone running Android... – Scheff's Cat Oct 27 '17 at 10:27
  • I read the answer about Linux as several .so files **in the same process** can share an exported variable. Not that different processes share any data. – Bo Persson Oct 27 '17 at 11:29
  • @Scheff Each process does have its own virtual address space. However technically that memory can very well be backed by the same physical memory. It comes down to how it gets mapped into the address space of the process. If the globals are mapped onto a page that is unique per process or not. – mschwaig Oct 27 '17 at 13:17
  • "Not unique per process" sounds like shared memory. Memory for global variables which is not allocated explicitly as shared memory shouldn't be shared. (I remember with horror Windows 3.1 where one amok-running process corrupted the memory of the system and the other applications.) But may be, I'm thinking too simple, and I must admit that my experience about Android has at best end-user level. – Scheff's Cat Oct 27 '17 at 13:23

0 Answers0