+/*
+ * Routine to panic if a pointer is not mapped to an expected zone.
+ * This can be used as a means of pinning an object to the zone it is expected
+ * to be a part of. Causes a panic if the address does not belong to any
+ * specified zone, does not belong to any zone, has been freed and therefore
+ * unmapped from the zone, or the pointer contains an uninitialized value that
+ * does not belong to any zone.
+ */
+
+void
+zone_require(void *addr, zone_t expected_zone)
+{
+ struct zone *src_zone = NULL;
+ struct zone_page_metadata *page_meta = get_zone_page_metadata((struct zone_free_element *)addr, FALSE);
+
+ src_zone = PAGE_METADATA_GET_ZONE(page_meta);
+ if (__improbable(src_zone == NULL)) {
+ panic("Address not in a zone for zone_require check (addr: %p)", addr);
+ }
+
+ if (__improbable(src_zone != expected_zone)) {
+ panic("Address not in expected zone for zone_require check (addr: %p, zone: %s)", addr, src_zone->zone_name);
+ }
+}
+