summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2017-03-28 19:54:10 +0300
committerHans Rosenfeld <hans.rosenfeld@joyent.com>2017-04-24 10:36:11 +0200
commitff7af0d3beb1bddf8bb93afc2e9042dc3828be3d (patch)
tree00d88b59ba5448b9612f490bfbf264b87b369033
parent63982b82e639bf9f496423925738dd3f86bda7aa (diff)
downloadillumos-joyent-ff7af0d3beb1bddf8bb93afc2e9042dc3828be3d.tar.gz
8007 want sys/stddef.h for offsetof and container_of macros
Reviewed by: Gordon Ross <gordon.w.ross@gmail.com> Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net> Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Reviewed by: Dan McDonald <danmcd@omniti.com> Reviewed by: Yuri Pankov <yuri.pankov@gmail.com> Approved by: Hans Rosenfeld <hans.rosenfeld@joyent.com>
-rw-r--r--usr/src/head/iso/stddef_iso.h10
-rw-r--r--usr/src/head/stddef.h3
-rw-r--r--usr/src/pkg/manifests/system-header.mf1
-rw-r--r--usr/src/uts/common/sys/Makefile1
-rw-r--r--usr/src/uts/common/sys/stddef.h48
-rw-r--r--usr/src/uts/common/sys/sysmacros.h13
-rw-r--r--usr/src/uts/i86pc/dboot/dboot_multiboot2.c11
7 files changed, 53 insertions, 34 deletions
diff --git a/usr/src/head/iso/stddef_iso.h b/usr/src/head/iso/stddef_iso.h
index b94960793c..37e10aec4b 100644
--- a/usr/src/head/iso/stddef_iso.h
+++ b/usr/src/head/iso/stddef_iso.h
@@ -82,16 +82,6 @@ typedef unsigned int size_t; /* (historical version) */
}
#endif /* end of namespace std */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define offsetof(s, m) __builtin_offsetof(s, m)
-#else
-#if __cplusplus >= 199711L
-#define offsetof(s, m) (std::size_t)(&(((s *)0)->m))
-#else
-#define offsetof(s, m) (size_t)(&(((s *)0)->m))
-#endif
-#endif /* GNUC, etc. */
-
#if !defined(_MAX_ALIGN_T)
#if !defined(_STRICT_SYMBOLS) || defined(_STDC_C11)
#define _MAX_ALIGN_T
diff --git a/usr/src/head/stddef.h b/usr/src/head/stddef.h
index 1e3d016048..6f04b7f7c9 100644
--- a/usr/src/head/stddef.h
+++ b/usr/src/head/stddef.h
@@ -31,10 +31,9 @@
#ifndef _STDDEF_H
#define _STDDEF_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/isa_defs.h>
#include <iso/stddef_iso.h>
+#include <sys/stddef.h>
/*
* Allow global visibility for symbols defined in
diff --git a/usr/src/pkg/manifests/system-header.mf b/usr/src/pkg/manifests/system-header.mf
index 7fec376963..4e135e7751 100644
--- a/usr/src/pkg/manifests/system-header.mf
+++ b/usr/src/pkg/manifests/system-header.mf
@@ -1433,6 +1433,7 @@ file path=usr/include/sys/stat_impl.h
file path=usr/include/sys/statfs.h
file path=usr/include/sys/statvfs.h
file path=usr/include/sys/stdbool.h
+file path=usr/include/sys/stddef.h
file path=usr/include/sys/stdint.h
file path=usr/include/sys/stermio.h
file path=usr/include/sys/stream.h
diff --git a/usr/src/uts/common/sys/Makefile b/usr/src/uts/common/sys/Makefile
index 78cee80777..1c7662c28a 100644
--- a/usr/src/uts/common/sys/Makefile
+++ b/usr/src/uts/common/sys/Makefile
@@ -538,6 +538,7 @@ CHKHDRS= \
statfs.h \
statvfs.h \
stdbool.h \
+ stddef.h \
stdint.h \
stermio.h \
stmf.h \
diff --git a/usr/src/uts/common/sys/stddef.h b/usr/src/uts/common/sys/stddef.h
new file mode 100644
index 0000000000..9dc9736241
--- /dev/null
+++ b/usr/src/uts/common/sys/stddef.h
@@ -0,0 +1,48 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Toomas Soome <tsoome@me.com>
+ */
+
+#ifndef _SYS_STDDEF_H
+#define _SYS_STDDEF_H
+
+/*
+ * Commonly used macros and definitions.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(offsetof)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define offsetof(s, m) __builtin_offsetof(s, m)
+#else
+#if __cplusplus >= 199711L
+#define offsetof(s, m) (std::size_t)(&(((s *)NULL)->m))
+#else
+#define offsetof(s, m) ((size_t)(&(((s *)NULL)->m)))
+#endif
+#endif
+#endif /* !offsetof */
+
+#if !defined(container_of)
+#define container_of(m, s, name) \
+ (void *)((uintptr_t)(m) - (uintptr_t)offsetof(s, name))
+#endif /* !container_of */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_STDDEF_H */
diff --git a/usr/src/uts/common/sys/sysmacros.h b/usr/src/uts/common/sys/sysmacros.h
index 2e895a8daf..03be89f461 100644
--- a/usr/src/uts/common/sys/sysmacros.h
+++ b/usr/src/uts/common/sys/sysmacros.h
@@ -33,6 +33,7 @@
#define _SYS_SYSMACROS_H
#include <sys/param.h>
+#include <sys/stddef.h>
#ifdef __cplusplus
extern "C" {
@@ -369,18 +370,8 @@ extern unsigned char bcd_to_byte[256];
/* avoid any possibility of clashing with <stddef.h> version */
#if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_KMEMUSER)
-#if !defined(offsetof)
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define offsetof(s, m) __builtin_offsetof(s, m)
-#else
-#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
-#endif
-#endif /* !offsetof */
-
-#define container_of(m, s, name) \
- (void *)((uintptr_t)(m) - (uintptr_t)offsetof(s, name))
-
#define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
+
#endif /* _KERNEL, !_KMEMUSER */
#ifdef __cplusplus
diff --git a/usr/src/uts/i86pc/dboot/dboot_multiboot2.c b/usr/src/uts/i86pc/dboot/dboot_multiboot2.c
index 4e01b0a222..ccf81cf773 100644
--- a/usr/src/uts/i86pc/dboot/dboot_multiboot2.c
+++ b/usr/src/uts/i86pc/dboot/dboot_multiboot2.c
@@ -24,17 +24,6 @@
#include <sys/multiboot2.h>
#include <sys/multiboot2_impl.h>
-/*
- * Remove offsetof definition when we have usable sys/stddef.h
- */
-#if !defined(offsetof)
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define offsetof(s, m) __builtin_offsetof(s, m)
-#else
-#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
-#endif
-#endif /* !offsetof */
-
struct dboot_multiboot2_iterate_ctx;
typedef boolean_t (*dboot_multiboot2_iterate_cb_t)