Introduce api to track fd ownership in libc.

Add two functions to allow objects that own a file descriptor to
enforce that only they can close their file descriptor.

Use them in FILE* and DIR*.

Bug: http://b/110100358
Test: bionic_unit_tests
Test: aosp/master boots without errors
Test: treehugger
Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index a874152..43f12d3 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -585,6 +585,12 @@
   // couldn't make system calls on x86 at that point, but we can now...
   if (!linker_so.protect_relro()) __linker_cannot_link(args.argv[0]);
 
+  // Initialize the linker/libc.so shared global inside the linker.
+  static libc_shared_globals shared_globals;
+  __libc_shared_globals = &shared_globals;
+  __libc_init_shared_globals(&shared_globals);
+  args.shared_globals = __libc_shared_globals;
+
   // Initialize the linker's static libc's globals
   __libc_init_globals(args);