]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/arm64/loose_ends.c
xnu-6153.141.1.tar.gz
[apple/xnu.git] / osfmk / arm64 / loose_ends.c
index 495cc7c03d9fb24197330c33df18a0b553020f68..8b7ea91f4c4a738b3334969852015ed33c4802b2 100644 (file)
@@ -185,6 +185,8 @@ bzero_phys_nc(addr64_t src64, vm_size_t bytes)
        bzero_phys(src64, bytes);
 }
 
+extern void *secure_memset(void *, int, size_t);
+
 /* Zero bytes starting at a physical address */
 void
 bzero_phys(addr64_t src, vm_size_t bytes)
@@ -202,15 +204,14 @@ bzero_phys(addr64_t src, vm_size_t bytes)
 
                boolean_t use_copy_window = !pmap_valid_address(src);
                pn = (ppnum_t)(src >> PAGE_SHIFT);
+               wimg_bits = pmap_cache_attributes(pn);
 #if !defined(__ARM_COHERENT_IO__) && !__ARM_PTE_PHYSMAP__
                count = PAGE_SIZE - offset;
-               wimg_bits = pmap_cache_attributes(pn);
                if ((wimg_bits & VM_WIMG_MASK) != VM_WIMG_DEFAULT) {
                        use_copy_window = TRUE;
                }
 #else
                if (use_copy_window) {
-                       wimg_bits = pmap_cache_attributes(pn);
                        count = PAGE_SIZE - offset;
                }
 #endif
@@ -229,7 +230,17 @@ bzero_phys(addr64_t src, vm_size_t bytes)
                        count = bytes;
                }
 
-               bzero(buf, count);
+               switch (wimg_bits & VM_WIMG_MASK) {
+               case VM_WIMG_DEFAULT:
+               case VM_WIMG_WCOMB:
+               case VM_WIMG_INNERWBACK:
+               case VM_WIMG_WTHRU:
+                       bzero(buf, count);
+                       break;
+               default:
+                       /* 'dc zva' performed by bzero is not safe for device memory */
+                       secure_memset((void*)buf, 0, count);
+               }
 
                if (use_copy_window) {
                        pmap_unmap_cpu_windows_copy(index);