X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..a39ff7e25e19b3a8c3020042a3872ca9ec9659f1:/iokit/Kernel/IOHibernateRestoreKernel.c diff --git a/iokit/Kernel/IOHibernateRestoreKernel.c b/iokit/Kernel/IOHibernateRestoreKernel.c index daf5d2804..fc5a1b7f2 100644 --- a/iokit/Kernel/IOHibernateRestoreKernel.c +++ b/iokit/Kernel/IOHibernateRestoreKernel.c @@ -73,17 +73,7 @@ extern void acpi_wake_prot_entry(void); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #if defined(__i386__) || defined(__x86_64__) - -#define rdtsc(lo,hi) \ - __asm__ volatile("lfence; rdtsc; lfence" : "=a" (lo), "=d" (hi)) - -static inline uint64_t rdtsc64(void) -{ - uint64_t lo, hi; - rdtsc(lo, hi); - return ((hi) << 32) | (lo); -} - +#include #else static inline uint64_t rdtsc64(void) @@ -396,13 +386,22 @@ store_one_page(uint32_t procFlags, uint32_t * src, uint32_t compressedSize, uint32_t * buffer, uint32_t ppnum) { uint64_t dst = ptoa_64(ppnum); - uint8_t scratch[WKdm_SCRATCH_BUF_SIZE] __attribute__ ((aligned (16))); + uint8_t scratch[WKdm_SCRATCH_BUF_SIZE_INTERNAL] __attribute__ ((aligned (16))); if (compressedSize != PAGE_SIZE) { dst = pal_hib_map(DEST_COPY_AREA, dst); - if (compressedSize) WKdm_decompress_new((WK_word*) src, (WK_word*)(uintptr_t)dst, (WK_word*) &scratch[0], PAGE_SIZE); - else bzero((void *) dst, PAGE_SIZE); + if (compressedSize != 4) WKdm_decompress_new((WK_word*) src, (WK_word*)(uintptr_t)dst, (WK_word*) &scratch[0], compressedSize); + else + { + size_t i; + uint32_t s, *d; + + s = *src; + d = (uint32_t *)(uintptr_t)dst; + if (!s) __nosan_bzero((void *) dst, PAGE_SIZE); + else for (i = 0; i < (PAGE_SIZE / sizeof(int32_t)); i++) *d++ = s; + } } else { @@ -412,8 +411,6 @@ store_one_page(uint32_t procFlags, uint32_t * src, uint32_t compressedSize, return hibernate_sum_page((uint8_t *)(uintptr_t)dst, ppnum); } -#define C_ASSERT(e) typedef char __C_ASSERT__[(e) ? 1 : -1] - long hibernate_kernel_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4) @@ -449,7 +446,7 @@ hibernate_kernel_entrypoint(uint32_t p1, uint64_t timeStart; timeStart = rdtsc64(); - C_ASSERT(sizeof(IOHibernateImageHeader) == 512); + static_assert(sizeof(IOHibernateImageHeader) == 512); headerPhys = ptoa_64(p1); @@ -458,7 +455,7 @@ hibernate_kernel_entrypoint(uint32_t p1, debug_code(kIOHibernateRestoreCodeImageStart, headerPhys); - memcpy(gIOHibernateCurrentHeader, + __nosan_memcpy(gIOHibernateCurrentHeader, (void *) pal_hib_map(IMAGE_AREA, headerPhys), sizeof(IOHibernateImageHeader)); @@ -631,7 +628,7 @@ hibernate_kernel_entrypoint(uint32_t p1, // alloc new buffer page bufferPage = hibernate_page_list_grab(map, &nextFree); dst = (uint32_t *)pal_hib_map(DEST_COPY_AREA, ptoa_64(bufferPage)); - memcpy(dst, src, compressedSize); + __nosan_memcpy(dst, src, compressedSize); } if (copyPageIndex > ((PAGE_SIZE >> 2) - 3)) { @@ -697,6 +694,8 @@ hibernate_kernel_entrypoint(uint32_t p1, gIOHibernateCurrentHeader->trampolineTime = (((rdtsc64() - timeStart)) >> 8); +// debug_code('done', 0); + #if CONFIG_SLEEP #if defined(__i386__) || defined(__x86_64__) typedef void (*ResetProc)(void);