+#define LINKER_SET_OBJECT_FOREACH(_object, _pvar, _cast, _set) \
+ for (_pvar = (_cast) LINKER_SET_OBJECT_BEGIN(_object, _set); \
+ _pvar < (_cast) LINKER_SET_OBJECT_LIMIT(_object, _set); \
+ _pvar++)
+
+#define LINKER_SET_OBJECT_ITEM(_object, _set, _i) \
+ ((LINKER_SET_OBJECT_BEGIN(_object, _set))[_i])
+
+#define LINKER_SET_BEGIN(_set) \
+ LINKER_SET_OBJECT_BEGIN((kernel_mach_header_t *)&_mh_execute_header, _set)
+#define LINKER_SET_LIMIT(_set) \
+ LINKER_SET_OBJECT_LIMIT((kernel_mach_header_t *)&_mh_execute_header, _set)
+#define LINKER_SET_FOREACH(_pvar, _cast, _set) \
+ LINKER_SET_OBJECT_FOREACH((kernel_mach_header_t *)&_mh_execute_header, _pvar, _cast, _set)
+#define LINKER_SET_ITEM(_set, _i) \
+ LINKER_SET_OBJECT_ITEM((kernel_mach_header_t *)&_mh_execute_header, _set, _i)
+
+/*
+ * Implementation.
+ *
+ * void **__linker_set_object_begin(_header, _set)
+ * Returns a pointer to the first pointer in the linker set.
+ * void **__linker_set_object_limi(_header, _set)
+ * Returns an upper bound to the linker set (base + size).
+ */
+
+static __inline void **
+__linker_set_object_begin(kernel_mach_header_t *_header, const char *_set)
+ __attribute__((__const__));
+static __inline void **
+__linker_set_object_begin(kernel_mach_header_t *_header, const char *_set)
+{
+ void *_set_begin;
+ unsigned long _size;
+
+ _set_begin = getsectdatafromheader(_header, "__DATA", _set, &_size);
+ return( (void **) _set_begin );
+}
+
+static __inline void **
+__linker_set_object_limit(kernel_mach_header_t *_header, const char *_set)
+ __attribute__((__const__));
+static __inline void **
+__linker_set_object_limit(kernel_mach_header_t *_header, const char *_set)
+{
+ void *_set_begin;
+ unsigned long _size;
+
+ _set_begin = getsectdatafromheader(_header, "__DATA", _set, &_size);
+
+ return ((void **) ((uintptr_t) _set_begin + _size));
+}