summaryrefslogtreecommitdiff
path: root/libc/misc/internals/shared_flat_initfini.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-12-08 22:53:40 +0000
committerMike Frysinger <vapier@gentoo.org>2006-12-08 22:53:40 +0000
commit808694e8a330e32741b7781467610d8cec99ae6e (patch)
treea2114e7c67f1f88f5df4687d6ab7122892e68283 /libc/misc/internals/shared_flat_initfini.c
parentcba2c53724a6ed35f32775ec38906268c1bbd340 (diff)
Richard Sandiford writes: add support for init/fini arrays in shared flat libraries
Diffstat (limited to 'libc/misc/internals/shared_flat_initfini.c')
-rw-r--r--libc/misc/internals/shared_flat_initfini.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/libc/misc/internals/shared_flat_initfini.c b/libc/misc/internals/shared_flat_initfini.c
new file mode 100644
index 000000000..81e53834e
--- /dev/null
+++ b/libc/misc/internals/shared_flat_initfini.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2006 CodeSourcery Inc
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * This file defines the main initialisation and finalisation code for
+ * shared flat libraries. It in turn calls the initialisation and
+ * finalisation code for each registered library.
+ */
+#include "shared_flat_lib.h"
+
+/* A doubly-linked list of shared libraries. Those nearer the head
+ * of the list should be initialised first and finalised last. */
+struct shared_flat_lib *__first_shared_lib;
+struct shared_flat_lib *__last_shared_lib;
+
+void __shared_flat_init(void)
+{
+ struct shared_flat_lib *lib;
+ void (**start)(void);
+ void (**end)(void);
+
+ for (lib = __first_shared_lib; lib; lib = lib->next) {
+ end = lib->preinit_array_end;
+ for (start = lib->preinit_array_start; start < end; start++)
+ (*start)();
+ }
+
+ for (lib = __first_shared_lib; lib; lib = lib->next) {
+ if (lib->init)
+ lib->init();
+
+ end = lib->init_array_end;
+ for (start = lib->init_array_start; start < end; start++)
+ (*start)();
+ }
+}
+
+void __shared_flat_fini(void)
+{
+ struct shared_flat_lib *lib;
+ void (**start)(void);
+ void (**end)(void);
+
+ for (lib = __last_shared_lib; lib; lib = lib->prev) {
+ start = lib->fini_array_start;
+ for (end = lib->fini_array_end; end > start;)
+ (*--end)();
+
+ if (lib->fini)
+ lib->fini();
+ }
+}