All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oshi.driver.linux.proc.Auxv Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2022 The OSHI Project Contributors
 * SPDX-License-Identifier: MIT
 */
package oshi.driver.linux.proc;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

import oshi.annotation.concurrent.ThreadSafe;
import oshi.util.FileUtil;
import oshi.util.platform.linux.ProcPath;

/**
 * Utility to read auxiliary vector from {@code /proc/self/auxv}
 */
@ThreadSafe
public final class Auxv {

    private Auxv() {
    }

    public static final int AT_PAGESZ = 6; // system page size
    public static final int AT_HWCAP = 16; // arch dependent hints at CPU capabilities
    public static final int AT_CLKTCK = 17; // frequency at which times() increments

    /**
     * Retrieve the auxiliary vector for the current process
     *
     * @return A map of auxiliary vector keys to their respective values
     * @see auxvec.h
     */
    public static Map queryAuxv() {
        ByteBuffer buff = FileUtil.readAllBytesAsBuffer(ProcPath.AUXV);
        Map auxvMap = new HashMap<>();
        int key;
        do {
            key = FileUtil.readNativeLongFromBuffer(buff).intValue();
            if (key > 0) {
                auxvMap.put(key, FileUtil.readNativeLongFromBuffer(buff).longValue());
            }
        } while (key > 0);
        return auxvMap;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy