-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIOHibernatePrivate.h
549 lines (447 loc) · 15.6 KB
/
IOHibernatePrivate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef KERNEL
#include <libkern/crypto/aes.h>
#include <uuid/uuid.h>
#endif
#ifndef __IOKIT_IOHIBERNATEPRIVATE_H
#define __IOKIT_IOHIBERNATEPRIVATE_H
struct IOPolledFileExtent
{
uint64_t start;
uint64_t length;
};
typedef struct IOPolledFileExtent IOPolledFileExtent;
struct IOHibernateImageHeader
{
uint64_t imageSize;
uint64_t image1Size;
uint32_t restore1CodePhysPage;
uint32_t reserved1;
uint64_t restore1CodeVirt;
uint32_t restore1PageCount;
uint32_t restore1CodeOffset;
uint32_t restore1StackOffset;
uint32_t pageCount;
uint32_t bitmapSize;
uint32_t restore1Sum;
uint32_t image1Sum;
uint32_t image2Sum;
uint32_t actualRestore1Sum;
uint32_t actualImage1Sum;
uint32_t actualImage2Sum;
uint32_t actualUncompressedPages;
uint32_t conflictCount;
uint32_t nextFree;
uint32_t signature;
uint32_t processorFlags;
uint32_t runtimePages;
uint32_t runtimePageCount;
uint64_t runtimeVirtualPages __attribute__ ((packed));
uint32_t performanceDataStart;
uint32_t performanceDataSize;
uint64_t encryptStart __attribute__ ((packed));
uint64_t machineSignature __attribute__ ((packed));
uint32_t previewSize;
uint32_t previewPageListSize;
uint32_t diag[4];
uint32_t handoffPages;
uint32_t handoffPageCount;
uint32_t systemTableOffset;
uint32_t debugFlags;
uint32_t options;
uint32_t sleepTime;
uint32_t compression;
uint32_t reserved[58]; // make sizeof == 512
uint32_t booterTime0;
uint32_t booterTime1;
uint32_t booterTime2;
uint32_t booterStart;
uint32_t smcStart;
uint32_t connectDisplayTime;
uint32_t splashTime;
uint32_t booterTime;
uint32_t trampolineTime;
uint64_t encryptEnd __attribute__ ((packed));
uint64_t deviceBase __attribute__ ((packed));
uint32_t deviceBlockSize;
uint32_t fileExtentMapSize;
IOPolledFileExtent fileExtentMap[2];
};
typedef struct IOHibernateImageHeader IOHibernateImageHeader;
enum
{
kIOHibernateDebugRestoreLogs = 0x00000001
};
// options & IOHibernateOptions property
enum
{
kIOHibernateOptionSSD = 0x00000001,
kIOHibernateOptionColor = 0x00000002,
kIOHibernateOptionProgress = 0x00000004,
kIOHibernateOptionDarkWake = 0x00000008,
};
struct hibernate_bitmap_t
{
uint32_t first_page;
uint32_t last_page;
uint32_t bitmapwords;
uint32_t bitmap[0];
};
typedef struct hibernate_bitmap_t hibernate_bitmap_t;
struct hibernate_page_list_t
{
uint32_t list_size;
uint32_t page_count;
uint32_t bank_count;
hibernate_bitmap_t bank_bitmap[0];
};
typedef struct hibernate_page_list_t hibernate_page_list_t;
#if defined(_AES_H)
struct hibernate_cryptwakevars_t
{
uint8_t aes_iv[AES_BLOCK_SIZE];
};
typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
struct hibernate_cryptvars_t
{
uint8_t aes_iv[AES_BLOCK_SIZE];
aes_ctx ctx;
};
typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
#endif /* defined(_AES_H) */
enum
{
kIOHibernateHandoffType = 0x686f0000,
kIOHibernateHandoffTypeEnd = kIOHibernateHandoffType + 0,
kIOHibernateHandoffTypeGraphicsInfo = kIOHibernateHandoffType + 1,
kIOHibernateHandoffTypeCryptVars = kIOHibernateHandoffType + 2,
kIOHibernateHandoffTypeMemoryMap = kIOHibernateHandoffType + 3,
kIOHibernateHandoffTypeDeviceTree = kIOHibernateHandoffType + 4,
kIOHibernateHandoffTypeDeviceProperties = kIOHibernateHandoffType + 5,
kIOHibernateHandoffTypeKeyStore = kIOHibernateHandoffType + 6,
};
struct IOHibernateHandoff
{
uint32_t type;
uint32_t bytecount;
uint8_t data[];
};
typedef struct IOHibernateHandoff IOHibernateHandoff;
enum
{
kIOHibernateProgressCount = 19,
kIOHibernateProgressWidth = 7,
kIOHibernateProgressHeight = 16,
kIOHibernateProgressSpacing = 3,
kIOHibernateProgressOriginY = 81,
kIOHibernateProgressSaveUnderSize = 2*5+14*2,
kIOHibernateProgressLightGray = 230,
kIOHibernateProgressMidGray = 174,
kIOHibernateProgressDarkGray = 92
};
enum
{
kIOHibernatePostWriteSleep = 0,
kIOHibernatePostWriteWake = 1,
kIOHibernatePostWriteHalt = 2,
kIOHibernatePostWriteRestart = 3
};
struct hibernate_graphics_t
{
uint64_t physicalAddress; // Base address of video memory
int32_t gfxStatus; // EFI config restore status
uint32_t rowBytes; // Number of bytes per pixel row
uint32_t width; // Width
uint32_t height; // Height
uint32_t depth; // Pixel Depth
uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
};
typedef struct hibernate_graphics_t hibernate_graphics_t;
#define DECLARE_IOHIBERNATEPROGRESSALPHA \
static const uint8_t gIOHibernateProgressAlpha \
[kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
{ \
{ 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
{ 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
{ 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
{ 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
};
struct hibernate_preview_t
{
uint32_t imageCount; // Number of images
uint32_t width; // Width
uint32_t height; // Height
uint32_t depth; // Pixel Depth
uint32_t lockTime; // Lock time
uint32_t reservedG[8]; // reserved
uint32_t reservedK[8]; // reserved
};
typedef struct hibernate_preview_t hibernate_preview_t;
struct hibernate_statistics_t
{
uint64_t image1Size;
uint64_t imageSize;
uint32_t image1Pages;
uint32_t imagePages;
uint32_t booterStart;
uint32_t smcStart;
uint32_t booterDuration;
uint32_t booterConnectDisplayDuration;
uint32_t booterSplashDuration;
uint32_t booterDuration0;
uint32_t booterDuration1;
uint32_t booterDuration2;
uint32_t trampolineDuration;
uint32_t kernelImageReadDuration;
uint32_t graphicsReadyTime;
uint32_t wakeNotificationTime;
uint32_t lockScreenReadyTime;
uint32_t hidReadyTime;
uint32_t wakeCapability;
uint32_t resvA[15];
};
typedef struct hibernate_statistics_t hibernate_statistics_t;
#define kIOSysctlHibernateStatistics "kern.hibernatestatistics"
#define kIOSysctlHibernateGraphicsReady "kern.hibernategraphicsready"
#define kIOSysctlHibernateWakeNotify "kern.hibernatewakenotification"
#define kIOSysctlHibernateScreenReady "kern.hibernatelockscreenready"
#define kIOSysctlHibernateHIDReady "kern.hibernatehidready"
#ifdef KERNEL
#ifdef __cplusplus
void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
IOReturn IOHibernateSystemSleep(void);
void IOOpenDebugDataFile(const char *fname, uint64_t size);
void IOCloseDebugDataFile();
IOReturn IOHibernateIOKitSleep(void);
IOReturn IOHibernateSystemHasSlept(void);
IOReturn IOHibernateSystemWake(void);
IOReturn IOHibernateSystemPostWake(void);
bool IOHibernateWasScreenLocked(void);
void IOHibernateSetScreenLocked(uint32_t lockState);
void IOHibernateSetWakeCapabilities(uint32_t capability);
void IOHibernateSystemRestart(void);
#endif /* __cplusplus */
void
vm_compressor_do_warmup(void);
hibernate_page_list_t *
hibernate_page_list_allocate(boolean_t log);
kern_return_t
hibernate_alloc_page_lists(
hibernate_page_list_t ** page_list_ret,
hibernate_page_list_t ** page_list_wired_ret,
hibernate_page_list_t ** page_list_pal_ret);
kern_return_t
hibernate_setup(IOHibernateImageHeader * header,
boolean_t vmflush,
hibernate_page_list_t * page_list,
hibernate_page_list_t * page_list_wired,
hibernate_page_list_t * page_list_pal);
kern_return_t
hibernate_teardown(hibernate_page_list_t * page_list,
hibernate_page_list_t * page_list_wired,
hibernate_page_list_t * page_list_pal);
kern_return_t
hibernate_pin_swap(boolean_t begin);
kern_return_t
hibernate_processor_setup(IOHibernateImageHeader * header);
void
hibernate_gobble_pages(uint32_t gobble_count, uint32_t free_page_time);
void
hibernate_free_gobble_pages(void);
void
hibernate_vm_lock_queues(void);
void
hibernate_vm_unlock_queues(void);
void
hibernate_vm_lock(void);
void
hibernate_vm_unlock(void);
// mark pages not to be saved, based on VM system accounting
void
hibernate_page_list_setall(hibernate_page_list_t * page_list,
hibernate_page_list_t * page_list_wired,
hibernate_page_list_t * page_list_pal,
boolean_t preflight,
boolean_t discard_all,
uint32_t * pagesOut);
// mark pages to be saved, or pages not to be saved but available
// for scratch usage during restore
void
hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
hibernate_page_list_t * page_list_wired,
boolean_t preflight,
uint32_t * pagesOut);
// mark pages not to be saved and not for scratch usage during restore
void
hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
hibernate_page_list_t * page_list_wired,
uint32_t * pagesOut);
void
hibernate_page_list_discard(hibernate_page_list_t * page_list);
int
hibernate_should_abort(void);
void
hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
void
hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
boolean_t
hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
hibernate_bitmap_t *
hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
uint32_t
hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
uintptr_t
hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
void
hibernate_machine_init(void);
uint32_t
hibernate_write_image(void);
long
hibernate_machine_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
long
hibernate_kernel_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
void
hibernate_newruntime_map(void * map, vm_size_t map_size,
uint32_t system_table_offset);
extern uint32_t gIOHibernateState;
extern uint32_t gIOHibernateMode;
extern uint32_t gIOHibernateDebugFlags;
extern uint32_t gIOHibernateFreeTime; // max time to spend freeing pages (ms)
extern boolean_t gIOHibernateStandbyDisabled;
extern uint8_t gIOHibernateRestoreStack[];
extern uint8_t gIOHibernateRestoreStackEnd[];
extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
#define HIBLOG(fmt, args...) \
{ kprintf(fmt, ## args); printf(fmt, ## args); }
#define HIBPRINT(fmt, args...) \
{ kprintf(fmt, ## args); }
#endif /* KERNEL */
// gIOHibernateState, kIOHibernateStateKey
enum
{
kIOHibernateStateInactive = 0,
kIOHibernateStateHibernating = 1, /* writing image */
kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */
};
// gIOHibernateMode, kIOHibernateModeKey
enum
{
kIOHibernateModeOn = 0x00000001,
kIOHibernateModeSleep = 0x00000002,
kIOHibernateModeEncrypt = 0x00000004,
kIOHibernateModeDiscardCleanInactive = 0x00000008,
kIOHibernateModeDiscardCleanActive = 0x00000010,
kIOHibernateModeSwitch = 0x00000020,
kIOHibernateModeRestart = 0x00000040,
kIOHibernateModeSSDInvert = 0x00000080,
kIOHibernateModeFileResize = 0x00000100,
};
// IOHibernateImageHeader.signature
enum
{
kIOHibernateHeaderSignature = 0x73696d65,
kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a,
kIOHibernateHeaderOpenSignature = 0xf1e0be9d,
kIOHibernateHeaderDebugDataSignature = 0xfcddfcdd
};
// kind for hibernate_set_page_state()
enum
{
kIOHibernatePageStateFree = 0,
kIOHibernatePageStateWiredSave = 1,
kIOHibernatePageStateUnwiredSave = 2
};
#define kIOHibernateModeKey "Hibernate Mode"
#define kIOHibernateFileKey "Hibernate File"
#define kIOHibernateFileMinSizeKey "Hibernate File Min"
#define kIOHibernateFileMaxSizeKey "Hibernate File Max"
#define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
#define kIOHibernateFreeTimeKey "Hibernate Free Time"
#define kIOHibernateStateKey "IOHibernateState"
#define kIOHibernateFeatureKey "Hibernation"
#define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
#ifndef kIOHibernatePreviewActiveKey
#define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
// values for kIOHibernatePreviewActiveKey
enum {
kIOHibernatePreviewActive = 0x00000001,
kIOHibernatePreviewUpdates = 0x00000002
};
#endif
#define kIOHibernateOptionsKey "IOHibernateOptions"
#define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
enum {
kIOHibernateGfxStatusUnknown = ((int32_t) 0xFFFFFFFF)
};
#define kIOHibernateBootImageKey "boot-image"
#define kIOHibernateBootImageKeyKey "boot-image-key"
#define kIOHibernateBootSignatureKey "boot-signature"
#define kIOHibernateMemorySignatureKey "memory-signature"
#define kIOHibernateMemorySignatureEnvKey "mem-sig"
#define kIOHibernateMachineSignatureKey "machine-signature"
#define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
#define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables"
#define kIOHibernateBootSwitchVarsKey "boot-switch-vars"
#define kIOHibernateBootNoteKey "boot-note"
#define kIOHibernateUseKernelInterpreter 0x80000000
enum
{
kIOPreviewImageIndexDesktop = 0,
kIOPreviewImageIndexLockScreen = 1,
kIOPreviewImageCount = 2
};
enum
{
kIOScreenLockNoLock = 1,
kIOScreenLockUnlocked = 2,
kIOScreenLockLocked = 3,
kIOScreenLockFileVaultDialog = 4,
};
#define kIOScreenLockStateKey "IOScreenLockState"
#endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */
#ifdef __cplusplus
}
#endif