+ cryptvars = (kIOHibernateModeEncrypt & gIOHibernateMode) ? &gIOHibernateCryptWakeContext : 0;
+
+ if (gIOHibernateCurrentHeader->handoffPageCount > gIOHibernateHandoffPageCount)
+ panic("handoff overflow");
+
+ IOHibernateHandoff * handoff;
+ bool done = false;
+ bool foundCryptData = false;
+
+ for (handoff = (IOHibernateHandoff *) vars->handoffBuffer->getBytesNoCopy();
+ !done;
+ handoff = (IOHibernateHandoff *) &handoff->data[handoff->bytecount])
+ {
+// HIBPRINT("handoff %p, %x, %x\n", handoff, handoff->type, handoff->bytecount);
+ uint8_t * data = &handoff->data[0];
+ switch (handoff->type)
+ {
+ case kIOHibernateHandoffTypeEnd:
+ done = true;
+ break;
+
+ case kIOHibernateHandoffTypeGraphicsInfo:
+ bcopy(data, gIOHibernateGraphicsInfo, sizeof(*gIOHibernateGraphicsInfo));
+ break;
+
+ case kIOHibernateHandoffTypeCryptVars:
+ if (cryptvars)
+ {
+ hibernate_cryptwakevars_t *
+ wakevars = (hibernate_cryptwakevars_t *) &handoff->data[0];
+ bcopy(&wakevars->aes_iv[0], &cryptvars->aes_iv[0], sizeof(cryptvars->aes_iv));
+ }
+ foundCryptData = true;
+ bzero(data, handoff->bytecount);
+ break;
+
+ case kIOHibernateHandoffTypeMemoryMap:
+ hibernate_newruntime_map(data, handoff->bytecount,
+ gIOHibernateCurrentHeader->systemTableOffset);
+ break;
+
+ case kIOHibernateHandoffTypeDeviceTree:
+ {
+// DTEntry chosen = NULL;
+// HIBPRINT("DTLookupEntry %d\n", DTLookupEntry((const DTEntry) data, "/chosen", &chosen));
+ }
+ break;
+
+ default:
+ done = (kIOHibernateHandoffType != (handoff->type & 0xFFFF0000));
+ break;
+ }
+ }
+ if (cryptvars && !foundCryptData)
+ panic("hibernate handoff");
+