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.
6  *
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.
10  */
11 
12 /*
13  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
14  * Copyright 2017 RackTop Systems.
15  */
16 
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>
22 
23 #include <sys/poll.h>
24 
25 #include <time.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <errno.h>
29 
30 #include <fakekernel.h>
31 
32 pri_t minclsyspri = 60;
33 
34 /* Some kernel code takes the address of this. */
35 proc_t p0;
36 
37 proc_t *
38 _curproc(void)
39 {
40 	return (&p0);
41 }
42 
43 zone_t zone0 = {
44 	.zone_name = "global",
45 	.zone_zsched = &p0, 0
46 };
47 
48 zone_t *
49 _curzone(void)
50 {
51 	return (&zone0);
52 }
53 
54 pid_t
55 ddi_get_pid(void)
56 {
57 	return ((pid_t)getpid());
58 }
59 
60 /*
61  * Find highest one bit set.
62  *	Returns bit number + 1 of highest bit that is set, otherwise returns 0.
63  */
64 int
65 highbit64(uint64_t i)
66 {
67 	int h = 1;
68 
69 	if (i == 0)
70 		return (0);
71 	if (i & 0xffffffff00000000ULL) {
72 		h += 32; i >>= 32;
73 	}
74 	if (i & 0xffff0000) {
75 		h += 16; i >>= 16;
76 	}
77 	if (i & 0xff00) {
78 		h += 8; i >>= 8;
79 	}
80 	if (i & 0xf0) {
81 		h += 4; i >>= 4;
82 	}
83 	if (i & 0xc) {
84 		h += 2; i >>= 2;
85 	}
86 	if (i & 0x2) {
87 		h += 1;
88 	}
89 	return (h);
90 }
91 
92 int
93 ddi_strtoul(const char *str, char **endp, int base, unsigned long *res)
94 {
95 	*res = strtoul(str, endp, base);
96 	if (*res == 0)
97 		return (errno);
98 	return (0);
99 }
100 
101 int
102 ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *res)
103 {
104 	char *end;
105 
106 	*res = strtoull(str, &end, base);
107 	if (*res == 0)
108 		return (errno);
109 	return (0);
110 }
111 
112 void
113 delay(clock_t ticks)
114 {
115 	int msec = ticks;  /* NB: hz==1000 */
116 	(void) poll(0, 0, msec);
117 }
118 
119 int
120 issig(int why)
121 {
122 	return (0);
123 }
124 
125 /*
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.
130  */
131 void
132 fakekernel_init(void)
133 {
134 }
135