xref: /freebsd/sys/contrib/openzfs/module/os/freebsd/spl/spl_misc.c (revision aca928a50a42f00f344df934005b09dbcb4e2f77)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3eda14cbcSMatt Macy  * All rights reserved.
4eda14cbcSMatt Macy  *
5eda14cbcSMatt Macy  * Redistribution and use in source and binary forms, with or without
6eda14cbcSMatt Macy  * modification, are permitted provided that the following conditions
7eda14cbcSMatt Macy  * are met:
8eda14cbcSMatt Macy  * 1. Redistributions of source code must retain the above copyright
9eda14cbcSMatt Macy  *    notice, this list of conditions and the following disclaimer.
10eda14cbcSMatt Macy  * 2. Redistributions in binary form must reproduce the above copyright
11eda14cbcSMatt Macy  *    notice, this list of conditions and the following disclaimer in the
12eda14cbcSMatt Macy  *    documentation and/or other materials provided with the distribution.
13eda14cbcSMatt Macy  *
14eda14cbcSMatt Macy  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15eda14cbcSMatt Macy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16eda14cbcSMatt Macy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17eda14cbcSMatt Macy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18eda14cbcSMatt Macy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19eda14cbcSMatt Macy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20eda14cbcSMatt Macy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21eda14cbcSMatt Macy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22eda14cbcSMatt Macy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23eda14cbcSMatt Macy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24eda14cbcSMatt Macy  * SUCH DAMAGE.
25eda14cbcSMatt Macy  */
26eda14cbcSMatt Macy 
27eda14cbcSMatt Macy #include <sys/types.h>
28eda14cbcSMatt Macy #include <sys/param.h>
29eda14cbcSMatt Macy #include <sys/jail.h>
30eda14cbcSMatt Macy #include <sys/kernel.h>
31eda14cbcSMatt Macy #include <sys/libkern.h>
32eda14cbcSMatt Macy #include <sys/limits.h>
33eda14cbcSMatt Macy #include <sys/misc.h>
34eda14cbcSMatt Macy #include <sys/sysctl.h>
35eda14cbcSMatt Macy #include <sys/vnode.h>
36eda14cbcSMatt Macy 
37eda14cbcSMatt Macy #include <sys/zfs_context.h>
38eda14cbcSMatt Macy 
39eda14cbcSMatt Macy static struct opensolaris_utsname hw_utsname = {
40*aca928a5SMartin Matuska 	.sysname = ostype,
41*aca928a5SMartin Matuska 	.nodename = prison0.pr_hostname,
42*aca928a5SMartin Matuska 	.release = osrelease,
43eda14cbcSMatt Macy 	.machine = MACHINE
44eda14cbcSMatt Macy };
45eda14cbcSMatt Macy 
46eda14cbcSMatt Macy utsname_t *
utsname(void)47eda14cbcSMatt Macy utsname(void)
48eda14cbcSMatt Macy {
49eda14cbcSMatt Macy 	return (&hw_utsname);
50eda14cbcSMatt Macy }
51eda14cbcSMatt Macy 
52eda14cbcSMatt Macy static void
opensolaris_utsname_init(void * arg)53eda14cbcSMatt Macy opensolaris_utsname_init(void *arg)
54eda14cbcSMatt Macy {
55eda14cbcSMatt Macy 	snprintf(hw_utsname.version, sizeof (hw_utsname.version),
56eda14cbcSMatt Macy 	    "%d", osreldate);
57eda14cbcSMatt Macy }
58eda14cbcSMatt Macy 
59eda14cbcSMatt Macy char *
kmem_strdup(const char * s)60eda14cbcSMatt Macy kmem_strdup(const char *s)
61eda14cbcSMatt Macy {
62eda14cbcSMatt Macy 	char *buf;
63eda14cbcSMatt Macy 
64eda14cbcSMatt Macy 	buf = kmem_alloc(strlen(s) + 1, KM_SLEEP);
65eda14cbcSMatt Macy 	strcpy(buf, s);
66eda14cbcSMatt Macy 	return (buf);
67eda14cbcSMatt Macy }
68eda14cbcSMatt Macy 
69eda14cbcSMatt Macy int
ddi_copyin(const void * from,void * to,size_t len,int flags)70eda14cbcSMatt Macy ddi_copyin(const void *from, void *to, size_t len, int flags)
71eda14cbcSMatt Macy {
72eda14cbcSMatt Macy 	/* Fake ioctl() issued by kernel, 'from' is a kernel address */
73eda14cbcSMatt Macy 	if (flags & FKIOCTL) {
74eda14cbcSMatt Macy 		memcpy(to, from, len);
75eda14cbcSMatt Macy 		return (0);
76eda14cbcSMatt Macy 	}
77eda14cbcSMatt Macy 
78eda14cbcSMatt Macy 	return (copyin(from, to, len));
79eda14cbcSMatt Macy }
80eda14cbcSMatt Macy 
81eda14cbcSMatt Macy int
ddi_copyout(const void * from,void * to,size_t len,int flags)82eda14cbcSMatt Macy ddi_copyout(const void *from, void *to, size_t len, int flags)
83eda14cbcSMatt Macy {
84eda14cbcSMatt Macy 	/* Fake ioctl() issued by kernel, 'from' is a kernel address */
85eda14cbcSMatt Macy 	if (flags & FKIOCTL) {
86eda14cbcSMatt Macy 		memcpy(to, from, len);
87eda14cbcSMatt Macy 		return (0);
88eda14cbcSMatt Macy 	}
89eda14cbcSMatt Macy 
90eda14cbcSMatt Macy 	return (copyout(from, to, len));
91eda14cbcSMatt Macy }
92eda14cbcSMatt Macy 
93be181ee2SMartin Matuska void
spl_panic(const char * file,const char * func,int line,const char * fmt,...)94eda14cbcSMatt Macy spl_panic(const char *file, const char *func, int line, const char *fmt, ...)
95eda14cbcSMatt Macy {
96eda14cbcSMatt Macy 	va_list ap;
97eda14cbcSMatt Macy 
98eda14cbcSMatt Macy 	va_start(ap, fmt);
99eda14cbcSMatt Macy 	vpanic(fmt, ap);
100eda14cbcSMatt Macy 	va_end(ap);
101eda14cbcSMatt Macy }
102eda14cbcSMatt Macy 
103eda14cbcSMatt Macy 
104eda14cbcSMatt Macy SYSINIT(opensolaris_utsname_init, SI_SUB_TUNABLES, SI_ORDER_ANY,
105eda14cbcSMatt Macy     opensolaris_utsname_init, NULL);
106