1 /*
2 * Copyright 2021-2022 The OSHI Project Contributors
3 * SPDX-License-Identifier: MIT
4 */
5 package oshi.jna.platform.unix;
6
7 import com.sun.jna.Native;
8 import com.sun.jna.Pointer;
9 import com.sun.jna.Structure;
10 import com.sun.jna.Structure.FieldOrder;
11
12 /**
13 * C library. This class should be considered non-API as it may be removed if/when its code is incorporated into the JNA
14 * project.
15 */
16 public interface OpenBsdLibc extends CLibrary {
17 OpenBsdLibc INSTANCE = Native.load(null, OpenBsdLibc.class);
18
19 int CTL_KERN = 1; // "high kernel": proc, limits
20 int CTL_VM = 1; // "high kernel": proc, limits
21 int CTL_HW = 6; // generic cpu/io
22 int CTL_MACHDEP = 7; // machine dependent
23 int CTL_VFS = 10; // VFS sysctl's
24
25 int KERN_OSTYPE = 1; // string: system version
26 int KERN_OSRELEASE = 2; // string: system release
27 int KERN_OSREV = 3; // int: system revision
28 int KERN_VERSION = 4; // string: compile time info
29 int KERN_MAXVNODES = 5; // int: max vnodes
30 int KERN_MAXPROC = 6; // int: max processes
31 int KERN_ARGMAX = 8; // int: max arguments to exec
32 int KERN_CPTIME = 40; // array: cp_time
33 int KERN_CPTIME2 = 71; // array: cp_time2
34
35 int VM_UVMEXP = 4; // struct uvmexp
36
37 int HW_MACHINE = 1; // string: machine class
38 int HW_MODEL = 2; // string: specific machine model
39 int HW_PAGESIZE = 7; // int: software page size
40 int HW_CPUSPEED = 12; // get CPU frequency
41 int HW_NCPUFOUND = 21; // CPU found (includes offline)
42 int HW_SMT = 24; // enable SMT/HT/CMT
43 int HW_NCPUONLINE = 25; // number of cpus being used
44
45 int VFS_GENERIC = 0; // generic filesystem information
46 int VFS_BCACHESTAT = 3; // struct: buffer cache statistics given as next argument
47
48 /*
49 * CPU state indices
50 */
51 int CPUSTATES = 5;
52 int CP_USER = 0;
53 int CP_NICE = 1;
54 int CP_SYS = 2;
55 int CP_INTR = 3; // 4 on 6.4 and later
56 int CP_IDLE = 4; // 5 on 6.4 and later
57
58 int UINT64_SIZE = Native.getNativeSize(long.class);
59 int INT_SIZE = Native.getNativeSize(int.class);
60
61 /**
62 * OpenBSD Cache stats for memory
63 */
64 @FieldOrder({ "numbufs", "numbufpages", "numdirtypages", "numcleanpages", "pendingwrites", "pendingreads",
65 "numwrites", "numreads", "cachehits", "busymapped", "dmapages", "highpages", "delwribufs", "kvaslots",
66 "kvaslots_avail", "highflips", "highflops", "dmaflips" })
67 class Bcachestats extends Structure {
68 public long numbufs; // number of buffers allocated
69 public long numbufpages; // number of pages in buffer cache
70 public long numdirtypages; // number of dirty free pages
71 public long numcleanpages; // number of clean free pages
72 public long pendingwrites; // number of pending writes
73 public long pendingreads; // number of pending reads
74 public long numwrites; // total writes started
75 public long numreads; // total reads started
76 public long cachehits; // total reads found in cache
77 public long busymapped; // number of busy and mapped buffers
78 public long dmapages; // dma reachable pages in buffer cache
79 public long highpages; // pages above dma region
80 public long delwribufs; // delayed write buffers
81 public long kvaslots; // kva slots total
82 public long kvaslots_avail; // available kva slots
83 public long highflips; // total flips to above DMA
84 public long highflops; // total failed flips to above DMA
85 public long dmaflips; // total flips from high to DMA
86
87 public Bcachestats(Pointer p) {
88 super(p);
89 read();
90 }
91 }
92
93 /**
94 * Return type for BSD sysctl kern.boottime
95 */
96 @FieldOrder({ "tv_sec", "tv_usec" })
97 class Timeval extends Structure {
98 public long tv_sec; // seconds
99 public long tv_usec; // microseconds
100 }
101
102 /**
103 * Returns the thread ID of the calling thread. This is used in the implementation of the thread library (-lpthread)
104 * and can appear in the output of system utilities such as ps and kdump.
105 *
106 * @return the thread ID of the calling thread.
107 */
108 int getthrid();
109 }