xref: /freebsd/sys/contrib/openzfs/lib/libspl/libspl.c (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
14  * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
15  * Copyright (c) 2016 Actifio, Inc. All rights reserved.
16  * Copyright (c) 2025, Klara, Inc.
17  * Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
18  */
19 
20 #include <libspl.h>
21 #include <assert.h>
22 #include <unistd.h>
23 #include <sys/misc.h>
24 #include <sys/systm.h>
25 #include <sys/utsname.h>
26 #include "libspl_impl.h"
27 
28 static uint64_t hw_physmem = 0;
29 static struct utsname hw_utsname = {};
30 
31 uint64_t
libspl_physmem(void)32 libspl_physmem(void)
33 {
34 	return (hw_physmem);
35 }
36 
37 utsname_t *
utsname(void)38 utsname(void)
39 {
40 	return (&hw_utsname);
41 }
42 
43 void
libspl_init(void)44 libspl_init(void)
45 {
46 	hw_physmem = sysconf(_SC_PHYS_PAGES);
47 
48 	VERIFY0(uname(&hw_utsname));
49 
50 	random_init();
51 }
52 
53 void
libspl_fini(void)54 libspl_fini(void)
55 {
56 	random_fini();
57 }
58