git: faf25f48d601 - main - stand: Work around upstream issues in the standalone environment

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 09 Jul 2022 05:03:29 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=faf25f48d601ae39f5752602f3020e2e92605625

commit faf25f48d601ae39f5752602f3020e2e92605625
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-07-08 23:34:46 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-07-09 04:49:55 +0000

    stand: Work around upstream issues in the standalone environment
    
    There's a number of issues with including zfs_context.h from a
    standalone environment. First, sys/uio_imp.h isn't at all safe for this
    environment, so define its guard #defines so that its contents are
    skipped. Next, there's a problem including string.h to get the mem*
    routines, so just define them here. ZFS_MODULE_PARAM_ARGS isn't defined
    properly. I had wanted to define it when I was upstreaming changes to
    include/os/freebsd/spl/sys/zfs_context.h, but they ran into resistance
    so I'm defining that here now (it is also defined in zstd_shim.c, but
    that will disappear once the issues it works around are
    cleared). Finally, sys/sysmacros.h has to be included now before
    sys/atomic.h, but upstream includes it after so include it here so that
    the guards make the out-of-order includes in upstream irrelevant.
    
    Sponsored by:           Netflix
    Reviewed by:            kevans
    Differential Revision:  https://reviews.freebsd.org/D35750
---
 stand/libsa/zfs/spl/sys/zfs_context.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/stand/libsa/zfs/spl/sys/zfs_context.h b/stand/libsa/zfs/spl/sys/zfs_context.h
new file mode 100644
index 000000000000..48f164317611
--- /dev/null
+++ b/stand/libsa/zfs/spl/sys/zfs_context.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2022, Netflix, Inc
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+/* TODO: openzfs/include/sys/uio_impl.h must not be included in stand */
+#ifndef _SYS_UIO_IMPL_H
+#define _SYS_UIO_IMPL_H
+#endif
+
+/*
+ * sys/atomic.h must be included after sys/sysmacros.h. The latter includes
+ * machine/atomic.h, which interferes. Sadly, upstream includes them in the
+ * wrong order, so we include it here to fix that.
+ */
+#include <sys/sysmacros.h>
+
+#include_next <sys/zfs_context.h>
+
+#define	ZFS_MODULE_PARAM_ARGS void
+
+/*
+ * Not sure why I need these, but including the canonical stand.h fails because
+ * the normal string.h doesn't like all the other shenanigans in this environment.
+ */
+void *memcpy(void *dst, const void *src, size_t len);
+void *memset(void *dest, int c, size_t len);
+void *memmem(const void *big, size_t big_len, const void *little,
+         size_t little_len);