8809 libzpool should leverage work done in libfakekernel
[unleashed.git] / usr / src / lib / libfakekernel / common / kmisc.c
blob2849552a66c5f464f7456b94b766eb1a08368246
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
14 * Copyright 2017 RackTop Systems.
17 #include <sys/types.h>
18 #include <sys/time.h>
19 #include <sys/thread.h>
20 #include <sys/proc.h>
21 #include <sys/zone.h>
23 #include <sys/poll.h>
25 #include <time.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <errno.h>
30 #include <fakekernel.h>
32 pri_t minclsyspri = 60;
34 /* Some kernel code takes the address of this. */
35 proc_t p0;
37 proc_t *
38 _curproc(void)
40 return (&p0);
43 zone_t zone0 = {
44 .zone_name = "global",
45 .zone_zsched = &p0, 0
48 zone_t *
49 _curzone(void)
51 return (&zone0);
54 pid_t
55 ddi_get_pid(void)
57 return ((pid_t)getpid());
61 * Find highest one bit set.
62 * Returns bit number + 1 of highest bit that is set, otherwise returns 0.
64 int
65 highbit64(uint64_t i)
67 int h = 1;
69 if (i == 0)
70 return (0);
71 if (i & 0xffffffff00000000ULL) {
72 h += 32; i >>= 32;
74 if (i & 0xffff0000) {
75 h += 16; i >>= 16;
77 if (i & 0xff00) {
78 h += 8; i >>= 8;
80 if (i & 0xf0) {
81 h += 4; i >>= 4;
83 if (i & 0xc) {
84 h += 2; i >>= 2;
86 if (i & 0x2) {
87 h += 1;
89 return (h);
92 int
93 ddi_strtoul(const char *str, char **endp, int base, unsigned long *res)
95 *res = strtoul(str, endp, base);
96 if (*res == 0)
97 return (errno);
98 return (0);
102 ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *res)
104 char *end;
106 *res = strtoull(str, &end, base);
107 if (*res == 0)
108 return (errno);
109 return (0);
112 void
113 delay(clock_t ticks)
115 int msec = ticks; /* NB: hz==1000 */
116 (void) poll(0, 0, msec);
120 issig(int why)
122 return (0);
126 * This library does not really need an "init" function, but
127 * providing one the main program can call is an easy way to
128 * make sure this library is loaded into the debugger, and
129 * gives us a way to avoid elfcheck complaints in the build.
131 void
132 fakekernel_init(void)