summaryrefslogtreecommitdiff
path: root/usr/src/lib/libfakekernel
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libfakekernel')
-rw-r--r--usr/src/lib/libfakekernel/Makefile.com7
-rw-r--r--usr/src/lib/libfakekernel/common/copy.c30
-rw-r--r--usr/src/lib/libfakekernel/common/cred.c60
-rw-r--r--usr/src/lib/libfakekernel/common/kmisc.c13
-rw-r--r--usr/src/lib/libfakekernel/common/mapfile-vers12
-rw-r--r--usr/src/lib/libfakekernel/common/printf.c29
-rw-r--r--usr/src/lib/libfakekernel/common/rwlock.c1
-rw-r--r--usr/src/lib/libfakekernel/common/sys/cmn_err.h8
-rw-r--r--usr/src/lib/libfakekernel/common/sys/cred.h5
-rw-r--r--usr/src/lib/libfakekernel/common/sys/cyclic.h87
-rw-r--r--usr/src/lib/libfakekernel/common/uio.c4
11 files changed, 238 insertions, 18 deletions
diff --git a/usr/src/lib/libfakekernel/Makefile.com b/usr/src/lib/libfakekernel/Makefile.com
index ef1abe4072..f9135717e6 100644
--- a/usr/src/lib/libfakekernel/Makefile.com
+++ b/usr/src/lib/libfakekernel/Makefile.com
@@ -56,10 +56,15 @@ $(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC)
CSTD = $(CSTD_GNU99)
C99LMODE = -Xc99=%all
+CFLAGS += $(CCVERBOSE)
+
# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+# Also Note: intentionally override CPPFLAGS, not +=
CPPFLAGS.first += -I../common
+CPPFLAGS= $(CPPFLAGS.first)
+
+INCS += -I$(SRC)/uts/common
-CFLAGS += $(CCVERBOSE)
CPPFLAGS += $(INCS) -D_REENTRANT -D_FAKE_KERNEL
CPPFLAGS += -D_FILE_OFFSET_BITS=64
diff --git a/usr/src/lib/libfakekernel/common/copy.c b/usr/src/lib/libfakekernel/common/copy.c
index b1eb215b5c..77bf2e8415 100644
--- a/usr/src/lib/libfakekernel/common/copy.c
+++ b/usr/src/lib/libfakekernel/common/copy.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
@@ -20,6 +20,20 @@
#include <sys/errno.h>
int
+copyin(const void *u, void *k, size_t s)
+{
+ bcopy(u, k, s);
+ return (0);
+}
+
+int
+copyout(const void *k, void *u, size_t s)
+{
+ bcopy(k, u, s);
+ return (0);
+}
+
+int
copyinstr(const char *src, char *dst, size_t max_len, size_t *copied)
{
return (copystr(src, dst, max_len, copied));
@@ -48,3 +62,17 @@ ovbcopy(const void *src, void *dst, size_t len)
{
(void) memmove(dst, src, len);
}
+
+/* ARGSUSED */
+int
+ddi_copyin(const void *buf, void *kernbuf, size_t size, int flags)
+{
+ return (copyin(buf, kernbuf, size));
+}
+
+/* ARGSUSED */
+int
+ddi_copyout(const void *buf, void *kernbuf, size_t size, int flags)
+{
+ return (copyout(buf, kernbuf, size));
+}
diff --git a/usr/src/lib/libfakekernel/common/cred.c b/usr/src/lib/libfakekernel/common/cred.c
index 1563f02ac9..0920599d0a 100644
--- a/usr/src/lib/libfakekernel/common/cred.c
+++ b/usr/src/lib/libfakekernel/common/cred.c
@@ -10,28 +10,51 @@
*/
/*
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
* Copyright 2017 RackTop Systems.
*/
-
#include <sys/types.h>
#include <sys/time.h>
#include <sys/thread.h>
#include <sys/cred.h>
+#include <sys/sid.h>
+#include <strings.h>
+
+/*
+ * This library does not implement real credentials. All contexts
+ * use an opaque cred_t object, and all activity happens in the
+ * context of the user who runs the program.
+ */
+
+extern struct zone zone0;
struct cred {
+ uid_t cr_uid;
+ ksid_t *cr_ksid;
uint32_t pad[100];
};
cred_t cred0;
cred_t *kcred = &cred0;
+/*
+ * Note that fksmbd uses CRED() for SMB user logons, but uses
+ * zone_kcred() for operations done internally by the server.
+ * Let CRED() (_curcred()) return &cred1, so it's different from
+ * kcred, otherwise tests like: (cred == kcred) are always true.
+ * Also, only cred1 will have a ksid (not kcred).
+ * The UID and SID are both "nobody".
+ */
+ksiddomain_t ksdom1 = {1, 5, "S-1-0", {0}};
+ksid_t ksid1 = { 60001, 0, 0, &ksdom1};
+cred_t cred1 = { 60001, &ksid1 };
+
cred_t *
_curcred(void)
{
/* Thread-specific data? */
- return (&cred0);
+ return (&cred1);
}
/*ARGSUSED*/
@@ -50,14 +73,14 @@ crhold(cred_t *cr)
uid_t
crgetuid(const cred_t *cr)
{
- return (0);
+ return (cr->cr_uid);
}
/*ARGSUSED*/
uid_t
crgetruid(const cred_t *cr)
{
- return (0);
+ return (cr->cr_uid);
}
/*ARGSUSED*/
@@ -81,8 +104,35 @@ crgetgroups(const cred_t *cr)
return (NULL);
}
+/*ARGSUSED*/
+zoneid_t
+crgetzoneid(const cred_t *cr)
+{
+ return (GLOBAL_ZONEID);
+}
+
+/*ARGSUSED*/
+struct zone *
+crgetzone(const cred_t *cr)
+{
+ return (&zone0);
+}
+
cred_t *
zone_kcred(void)
{
return (kcred);
}
+
+/*ARGSUSED*/
+ksid_t *
+crgetsid(const cred_t *cr, int i)
+{
+ return (cr->cr_ksid);
+}
+
+cred_t *
+ddi_get_cred(void)
+{
+ return (_curcred());
+}
diff --git a/usr/src/lib/libfakekernel/common/kmisc.c b/usr/src/lib/libfakekernel/common/kmisc.c
index 2849552a66..5feaa66a28 100644
--- a/usr/src/lib/libfakekernel/common/kmisc.c
+++ b/usr/src/lib/libfakekernel/common/kmisc.c
@@ -30,9 +30,12 @@
#include <fakekernel.h>
pri_t minclsyspri = 60;
+extern zone_t zone0;
/* Some kernel code takes the address of this. */
-proc_t p0;
+proc_t p0 = {
+ .p_zone = &zone0, 0
+};
proc_t *
_curproc(void)
@@ -99,11 +102,10 @@ ddi_strtoul(const char *str, char **endp, int base, unsigned long *res)
}
int
-ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *res)
+ddi_strtoull(const char *str, char **endp, int base, u_longlong_t *res)
{
- char *end;
-
- *res = strtoull(str, &end, base);
+ errno = 0;
+ *res = strtoull(str, endp, base);
if (*res == 0)
return (errno);
return (0);
@@ -116,6 +118,7 @@ delay(clock_t ticks)
(void) poll(0, 0, msec);
}
+/* ARGSUSED */
int
issig(int why)
{
diff --git a/usr/src/lib/libfakekernel/common/mapfile-vers b/usr/src/lib/libfakekernel/common/mapfile-vers
index 1c41dd9b58..aa59ad2e46 100644
--- a/usr/src/lib/libfakekernel/common/mapfile-vers
+++ b/usr/src/lib/libfakekernel/common/mapfile-vers
@@ -43,7 +43,9 @@ SYMBOL_VERSION SUNWprivate_1.1 {
aok { FLAGS = NODIRECT };
boot_time;
cmn_err;
+ copyin;
copyinstr;
+ copyout;
copystr;
cyclic_add;
@@ -56,6 +58,8 @@ SYMBOL_VERSION SUNWprivate_1.1 {
crgetgid;
crgetngroups;
crgetgroups;
+ crgetzone;
+ crgetzoneid;
crhold;
cv_broadcast;
@@ -70,12 +74,16 @@ SYMBOL_VERSION SUNWprivate_1.1 {
cv_wait;
cv_wait_sig;
+ ddi_copyin;
+ ddi_copyout;
+ ddi_get_cred;
ddi_get_lbolt64;
ddi_get_lbolt;
ddi_get_pid;
ddi_strtoul;
ddi_strtoull;
+ debug_enter;
delay;
fm_panic;
@@ -197,7 +205,7 @@ SYMBOL_VERSION SUNWprivate_1.1 {
strfree;
system_taskq;
- system_taskq_fini;
+ system_taskq_fini;
system_taskq_init;
taskq_create;
taskq_create_proc;
@@ -227,8 +235,10 @@ SYMBOL_VERSION SUNWprivate_1.1 {
vcmn_err;
vmem_qcache_reap;
vpanic;
+ vzprintf;
zone0;
zone_kcred;
+ zprintf;
zthread_create;
zthread_exit;
diff --git a/usr/src/lib/libfakekernel/common/printf.c b/usr/src/lib/libfakekernel/common/printf.c
index c8f459dd8c..bbf350b75e 100644
--- a/usr/src/lib/libfakekernel/common/printf.c
+++ b/usr/src/lib/libfakekernel/common/printf.c
@@ -21,7 +21,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
* Copyright 2017 RackTop Systems.
* Copyright (c) 2018, Joyent, Inc.
*/
@@ -36,6 +36,7 @@
#include <fakekernel.h>
void abort(void) __NORETURN;
+void debug_enter(char *);
char *volatile panicstr;
va_list panicargs;
@@ -100,6 +101,24 @@ fakekernel_cprintf(const char *fmt, va_list adx, int flags,
fakekernel_putlog(bufp, len, flags);
}
+/* ARGSUSED */
+void
+vzprintf(zoneid_t zoneid, const char *fmt, va_list adx)
+{
+ fakekernel_cprintf(fmt, adx, SL_CONSOLE | SL_NOTE, "", "");
+}
+
+/*PRINTFLIKE2*/
+void
+zprintf(zoneid_t zoneid, const char *fmt, ...)
+{
+ va_list adx;
+
+ va_start(adx, fmt);
+ vzprintf(zoneid, fmt, adx);
+ va_end(adx);
+}
+
/*
* "User-level crash dump", if you will.
*/
@@ -116,6 +135,7 @@ vpanic(const char *fmt, va_list adx)
/* Call libc`assfail() so that mdb ::status works */
(void) vsnprintf(panicbuf, sizeof (panicbuf), fmt, adx);
+ debug_enter(panicbuf);
(void) assfail(panicbuf, "(panic)", 0);
abort(); /* avoid "noreturn" warnings */
@@ -164,3 +184,10 @@ cmn_err(int ce, const char *fmt, ...)
vcmn_err(ce, fmt, adx);
va_end(adx);
}
+
+/* ARGSUSED */
+void
+debug_enter(char *str)
+{
+ /* Just a place for a break point. */
+}
diff --git a/usr/src/lib/libfakekernel/common/rwlock.c b/usr/src/lib/libfakekernel/common/rwlock.c
index 17b4ca604d..edc9bfd092 100644
--- a/usr/src/lib/libfakekernel/common/rwlock.c
+++ b/usr/src/lib/libfakekernel/common/rwlock.c
@@ -23,7 +23,6 @@
#include <sys/errno.h>
#include <sys/debug.h>
#include <sys/param.h>
-#include <sys/synch32.h>
#include <sys/thread.h>
/* avoiding synch.h */
diff --git a/usr/src/lib/libfakekernel/common/sys/cmn_err.h b/usr/src/lib/libfakekernel/common/sys/cmn_err.h
index c77b22b868..b9818f58c5 100644
--- a/usr/src/lib/libfakekernel/common/sys/cmn_err.h
+++ b/usr/src/lib/libfakekernel/common/sys/cmn_err.h
@@ -64,6 +64,10 @@ extern void cmn_err(int, const char *, ...)
extern void vcmn_err(int, const char *, __va_list)
__KVPRINTFLIKE(2);
+/*PRINTFLIKE3*/
+extern void zcmn_err(zoneid_t, int, const char *, ...)
+ __KPRINTFLIKE(3);
+
/*PRINTFLIKE1*/
extern void panic(const char *, ...)
__KPRINTFLIKE(1) __NORETURN;
@@ -71,6 +75,10 @@ extern void panic(const char *, ...)
extern void vpanic(const char *, __va_list)
__KVPRINTFLIKE(1) __NORETURN;
+/*PRINTFLIKE2*/
+extern void zprintf(zoneid_t, const char *, ...)
+ __KPRINTFLIKE(2);
+
#endif /* !_ASM && (_KERNEL || _FAKE_KERNEL) */
#ifdef __cplusplus
diff --git a/usr/src/lib/libfakekernel/common/sys/cred.h b/usr/src/lib/libfakekernel/common/sys/cred.h
index d544e04275..a338214843 100644
--- a/usr/src/lib/libfakekernel/common/sys/cred.h
+++ b/usr/src/lib/libfakekernel/common/sys/cred.h
@@ -27,7 +27,7 @@
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
+/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
@@ -66,6 +66,8 @@ extern void cred_init(void);
extern void crhold(cred_t *);
extern void crfree(cred_t *);
+extern int groupmember(gid_t, const cred_t *);
+
extern cred_t *zone_kcred(void);
extern uid_t crgetuid(const cred_t *);
@@ -75,6 +77,7 @@ extern gid_t crgetgid(const cred_t *);
extern gid_t crgetrgid(const cred_t *);
extern gid_t crgetsgid(const cred_t *);
extern zoneid_t crgetzoneid(const cred_t *);
+extern struct zone *crgetzone(const cred_t *);
extern projid_t crgetprojid(const cred_t *);
extern const gid_t *crgetgroups(const cred_t *);
diff --git a/usr/src/lib/libfakekernel/common/sys/cyclic.h b/usr/src/lib/libfakekernel/common/sys/cyclic.h
new file mode 100644
index 0000000000..56589ae7f1
--- /dev/null
+++ b/usr/src/lib/libfakekernel/common/sys/cyclic.h
@@ -0,0 +1,87 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright 2017 RackTop Systems.
+ */
+
+#ifndef _SYS_CYCLIC_H
+#define _SYS_CYCLIC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _ASM
+#include <sys/time.h>
+#endif /* !_ASM */
+
+#define CY_LOW_LEVEL 0
+#define CY_LOCK_LEVEL 1
+#define CY_HIGH_LEVEL 2
+#define CY_SOFT_LEVELS 2
+#define CY_LEVELS 3
+
+#ifndef _ASM
+
+typedef uintptr_t cyclic_id_t;
+typedef int cyc_index_t;
+typedef int cyc_cookie_t;
+typedef uint16_t cyc_level_t;
+typedef void (*cyc_func_t)(void *);
+typedef void *cyb_arg_t;
+
+#define CYCLIC_NONE ((cyclic_id_t)0)
+
+typedef struct cyc_handler {
+ cyc_func_t cyh_func;
+ void *cyh_arg;
+ cyc_level_t cyh_level;
+} cyc_handler_t;
+
+typedef struct cyc_time {
+ hrtime_t cyt_when;
+ hrtime_t cyt_interval;
+} cyc_time_t;
+
+#define CY_INFINITY INT64_MAX
+
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
+
+extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
+extern void cyclic_remove(cyclic_id_t);
+extern int cyclic_reprogram(cyclic_id_t, hrtime_t);
+extern hrtime_t cyclic_getres();
+
+extern void cyclic_suspend();
+extern void cyclic_resume();
+
+#endif /* _KERNEL || _FAKE_KERNEL */
+
+#endif /* !_ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_CYCLIC_H */
diff --git a/usr/src/lib/libfakekernel/common/uio.c b/usr/src/lib/libfakekernel/common/uio.c
index 3048faff58..99cb4e04e8 100644
--- a/usr/src/lib/libfakekernel/common/uio.c
+++ b/usr/src/lib/libfakekernel/common/uio.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
@@ -42,10 +42,10 @@ uiomove(void *p, size_t n, enum uio_rw rw, struct uio *uio)
}
switch (uio->uio_segflg) {
- case UIO_USERSPACE:
case UIO_USERISPACE:
return (EINVAL);
+ case UIO_USERSPACE:
case UIO_SYSSPACE:
if (rw == UIO_READ)
bcopy(p, iov->iov_base, cnt);