• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <string>
17 
18 static int volatile g_initialization_order_code;
19 
20 void (*g_fini_callback)(const char*) = nullptr;
21 
22 // These two function are called by local group's constructors and destructors
record_init(int digit)23 extern "C" void record_init(int digit) {
24   g_initialization_order_code = g_initialization_order_code*10 + digit;
25 }
26 
record_fini(const char * s)27 extern "C" void record_fini(const char* s) {
28   g_fini_callback(s);
29 }
30 
31 // these 2 functions are used by the test
get_init_order_number()32 extern "C" int get_init_order_number() {
33   return g_initialization_order_code;
34 }
35 
set_fini_callback(void (* f)(const char *))36 extern "C" void set_fini_callback(void (*f)(const char*)) {
37   g_fini_callback = f;
38 }
39 
init()40 static void __attribute__((constructor)) init() {
41   record_init(1);
42 }
43 
fini()44 static void __attribute__((destructor)) fini() {
45   record_fini("(root)");
46 }
47