blob: 45394ec46a93f10062a8eb114a213f6053fec6c1 [file] [log] [blame]
Dimitry Ivanovea8f3962017-02-09 13:31:57 -08001/*
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
18static int volatile g_initialization_order_code;
19
20void (*g_fini_callback)(const char*) = nullptr;
21
22// These two function are called by local group's constructors and destructors
23extern "C" void record_init(int digit) {
24 g_initialization_order_code = g_initialization_order_code*10 + digit;
25}
26
27extern "C" void record_fini(const char* s) {
28 g_fini_callback(s);
29}
30
31// these 2 functions are used by the test
32extern "C" int get_init_order_number() {
33 return g_initialization_order_code;
34}
35
36extern "C" void set_fini_callback(void (*f)(const char*)) {
37 g_fini_callback = f;
38}
39
40static void __attribute__((constructor)) init() {
41 record_init(1);
42}
43
44static void __attribute__((destructor)) fini() {
45 record_fini("(root)");
46}