1eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes/*
2eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * Copyright (C) 2017 The Android Open Source Project
3eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes *
4eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * you may not use this file except in compliance with the License.
6eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * You may obtain a copy of the License at
7eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes *
8eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes *
10eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * See the License for the specific language governing permissions and
14eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes * limitations under the License.
15eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes */
16eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
17eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes#include <errno.h>
18eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes#include <stdio.h>
19eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes#include <unistd.h>
20eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes#include <sys/auxv.h>
21eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
22eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes#include "libs_utils.h"
23eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
24eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughesstatic unsigned long g_AT_RANDOM;
25eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughesstatic unsigned long g_AT_PAGESZ;
26eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
27eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughesstatic void preinit_ctor() {
28eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  g_AT_RANDOM = getauxval(AT_RANDOM);
29eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  g_AT_PAGESZ = getauxval(AT_PAGESZ);
30eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes}
31eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
32eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes__attribute__((section(".preinit_array"), used)) void (*preinit_ctor_p)(void) = preinit_ctor;
33eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes
34eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughesint main() {
35eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  // Did getauxval during preinit get the same results as getauxval now?
36eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  CHECK(getauxval(AT_RANDOM) == g_AT_RANDOM);
37eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  CHECK(getauxval(AT_PAGESZ) == g_AT_PAGESZ);
38eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes  return 0;
39eb04ed506fbb0561b677d9518c9bae33f0262b03Elliott Hughes}
40