X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/2d21ac55c334faf3a56e5634905ed6987fc787d4..6d2010ae8f7a6078e10b361c6962983bab233e0f:/osfmk/kdp/ml/i386/kdp_vm.c diff --git a/osfmk/kdp/ml/i386/kdp_vm.c b/osfmk/kdp/ml/i386/kdp_vm.c index 9b3b85ad9..5633c73b9 100644 --- a/osfmk/kdp/ml/i386/kdp_vm.c +++ b/osfmk/kdp/ml/i386/kdp_vm.c @@ -44,24 +44,6 @@ #include #include -unsigned kdp_vm_read( caddr_t, caddr_t, unsigned); -unsigned kdp_vm_write( caddr_t, caddr_t, unsigned); - -boolean_t kdp_read_io; -boolean_t kdp_trans_off; -uint32_t kdp_src_high32; -extern pmap_paddr_t avail_start, avail_end; - -extern void bcopy_phys(addr64_t from, addr64_t to, int size); -static addr64_t kdp_vtophys(pmap_t pmap, addr64_t va); - -pmap_t kdp_pmap = 0; - -unsigned int not_in_kdp = 1; /* Cleared when we begin to access vm functions in kdp */ - -extern vm_offset_t sectTEXTB, sectDATAB, sectLINKB, sectPRELINKB; -extern int sectSizeTEXT, sectSizeDATA, sectSizeLINK, sectSizePRELINK; - int kern_dump(void); int kdp_dump_trap(int type, x86_saved_state32_t *regs); @@ -86,128 +68,6 @@ typedef struct { char command_buffer[512]; -static addr64_t -kdp_vtophys( - pmap_t pmap, - addr64_t va) -{ - addr64_t pa; - ppnum_t pp; - - pp = pmap_find_phys(pmap, va); - if(!pp) return 0; - - pa = ((addr64_t)pp << 12) | (va & 0x0000000000000FFFULL); - return(pa); -} - -/* - * - */ -unsigned kdp_vm_read( - caddr_t src, - caddr_t dst, - unsigned len) -{ - addr64_t cur_virt_src = (addr64_t)((unsigned int)src | (((uint64_t)kdp_src_high32) << 32)); - addr64_t cur_virt_dst = (addr64_t)((unsigned int)dst); - addr64_t cur_phys_dst, cur_phys_src; - unsigned resid = len; - unsigned cnt = 0; - pmap_t src_pmap = kernel_pmap; - -/* If a different pmap has been specified with kdp_pmap, use it to translate the - * source (cur_virt_src); otherwise, the source is translated using the - * kernel_pmap. - */ - if (kdp_pmap) - src_pmap = kdp_pmap; - - while (resid != 0) { -/* Translate, unless kdp_trans_off is set */ - if (!kdp_trans_off) { - if (!(cur_phys_src = kdp_vtophys(src_pmap, - cur_virt_src))) - goto exit; - } - else - cur_phys_src = cur_virt_src; - -/* Always translate the destination buffer using the kernel_pmap */ - if(!(cur_phys_dst = kdp_vtophys(kernel_pmap, cur_virt_dst))) - goto exit; - - /* Validate physical page numbers unless kdp_read_io is set */ - if (kdp_read_io == FALSE) - if (!pmap_valid_page(i386_btop(cur_phys_dst)) || !pmap_valid_page(i386_btop(cur_phys_src))) - goto exit; - -/* Get length left on page */ - cnt = PAGE_SIZE - (cur_phys_src & PAGE_MASK); - if (cnt > (PAGE_SIZE - (cur_phys_dst & PAGE_MASK))) - cnt = PAGE_SIZE - (cur_phys_dst & PAGE_MASK); - if (cnt > resid) - cnt = resid; - -/* Do a physical copy */ - bcopy_phys(cur_phys_src, cur_phys_dst, cnt); - - cur_virt_src += cnt; - cur_virt_dst += cnt; - resid -= cnt; - } -exit: - return (len - resid); -} - -/* - * - */ -unsigned kdp_vm_write( - caddr_t src, - caddr_t dst, - unsigned len) -{ - addr64_t cur_virt_src, cur_virt_dst; - addr64_t cur_phys_src, cur_phys_dst; - unsigned resid, cnt, cnt_src, cnt_dst; - -#ifdef KDP_VM_WRITE_DEBUG - printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src, dst, len, ((unsigned long *)src)[0], ((unsigned long *)src)[1]); -#endif - - cur_virt_src = (addr64_t)((unsigned int)src); - cur_virt_dst = (addr64_t)((unsigned int)dst); - - resid = len; - - while (resid != 0) { - if ((cur_phys_dst = kdp_vtophys(kernel_pmap, cur_virt_dst)) == 0) - goto exit; - - if ((cur_phys_src = kdp_vtophys(kernel_pmap, cur_virt_src)) == 0) - goto exit; - - cnt_src = ((cur_phys_src + PAGE_SIZE) & (PAGE_MASK)) - cur_phys_src; - cnt_dst = ((cur_phys_dst + PAGE_SIZE) & (PAGE_MASK)) - cur_phys_dst; - - if (cnt_src > cnt_dst) - cnt = cnt_dst; - else - cnt = cnt_src; - if (cnt > resid) - cnt = resid; - - bcopy_phys(cur_phys_src, cur_phys_dst, cnt); /* Copy stuff over */ - - cur_virt_src +=cnt; - cur_virt_dst +=cnt; - resid -= cnt; - } -exit: - return (len - resid); -} - static void kern_collectth_state(thread_t thread, tir_t *t) { @@ -246,7 +106,7 @@ kern_collectth_state(thread_t thread, tir_t *t) vm_offset_t kstack; bzero(tstate, x86_THREAD_STATE32_COUNT * sizeof(int)); if ((kstack = thread->kernel_stack) != 0){ - struct x86_kernel_state32 *iks = STACK_IKS(kstack); + struct x86_kernel_state *iks = STACK_IKS(kstack); tstate->ebx = iks->k_ebx; tstate->esp = iks->k_esp; tstate->ebp = iks->k_ebp; @@ -293,15 +153,16 @@ kern_dump(void) vm_map_t map; unsigned int thread_count, segment_count; unsigned int command_size = 0, header_size = 0, tstate_size = 0; - unsigned int hoffset = 0, foffset = 0, nfoffset = 0, vmoffset = 0; - unsigned int max_header_size = 0; - vm_offset_t header; + + uint64_t hoffset = 0, foffset = 0, nfoffset = 0, max_header_size; + vm_offset_t header, txstart; + vm_address_t vmoffset; + struct mach_header *mh; struct segment_command *sc; vm_size_t size; vm_prot_t prot = 0; vm_prot_t maxprot = 0; - vm_inherit_t inherit = 0; mythread_state_flavor_t flavors[MAX_TSTATE_FLAVORS]; vm_size_t nflavors; vm_size_t i; @@ -313,14 +174,9 @@ kern_dump(void) int error = 0; int panic_error = 0; - unsigned int txstart = 0; - unsigned int mach_section_count = 4; - unsigned int num_sects_txed = 0; map = kernel_map; - not_in_kdp = 0; /* Signal vm functions not to acquire locks */ - thread_count = 1; segment_count = get_vmmap_entries(map); @@ -333,7 +189,7 @@ kern_dump(void) tstate_size += sizeof(mythread_state_flavor_t) + (flavors[i].count * sizeof(int)); - command_size = (segment_count + mach_section_count) * + command_size = (segment_count) * sizeof(struct segment_command) + thread_count * sizeof(struct thread_command) + tstate_size * thread_count; @@ -351,7 +207,7 @@ kern_dump(void) mh->cputype = cpu_type(); mh->cpusubtype = cpu_subtype(); mh->filetype = MH_CORE; - mh->ncmds = segment_count + thread_count + mach_section_count; + mh->ncmds = segment_count + thread_count; mh->sizeofcmds = command_size; mh->flags = 0; @@ -364,7 +220,7 @@ kern_dump(void) max_header_size = foffset; - vmoffset = VM_MIN_ADDRESS; /* offset into VM */ + vmoffset = VM_MIN_KERNEL_ADDRESS; /* offset into VM */ /* Transmit the Mach-O MH_CORE header, and seek forward past the * area reserved for the segment and thread commands @@ -388,64 +244,36 @@ kern_dump(void) error = panic_error; goto out; } - printf ("Transmitting kernel state, please wait: "); - - while ((segment_count > 0) || (kret == KERN_SUCCESS)){ - /* Check if we've transmitted all the kernel sections */ - if (num_sects_txed == mach_section_count) { - - while (1) { - - /* - * Get region information for next region. - */ - - vbrcount = VM_REGION_SUBMAP_INFO_COUNT_64; - if((kret = vm_region_recurse_64(map, - &vmoffset, &size, &nesting_depth, - (vm_region_recurse_info_t)&vbr, - &vbrcount)) != KERN_SUCCESS) { - break; - } - - if(vbr.is_submap) { - nesting_depth++; - continue; - } else { - break; - } - } + printf ("Transmitting kernel state:\n"); - if(kret != KERN_SUCCESS) - break; + while ((segment_count > 0) || (kret == KERN_SUCCESS)) { + while (1) { - prot = vbr.protection; - maxprot = vbr.max_protection; - inherit = vbr.inheritance; - } - else - { - switch (num_sects_txed) { - case 0: - /* Transmit the kernel text section */ - vmoffset = sectTEXTB; - size = sectSizeTEXT; - break; - case 1: - vmoffset = sectDATAB; - size = sectSizeDATA; - break; - case 2: - vmoffset = sectPRELINKB; - size = sectSizePRELINK; + /* + * Get region information for next region. + */ + + vbrcount = VM_REGION_SUBMAP_INFO_COUNT_64; + if((kret = vm_region_recurse_64(map, + &vmoffset, &size, &nesting_depth, + (vm_region_recurse_info_t)&vbr, + &vbrcount)) != KERN_SUCCESS) { break; - case 3: - vmoffset = sectLINKB; - size = sectSizeLINK; + } + + if(vbr.is_submap) { + nesting_depth++; + continue; + } else { break; } - num_sects_txed++; } + + if(kret != KERN_SUCCESS) + break; + + prot = vbr.protection; + maxprot = vbr.max_protection; /* * Fill in segment command structure. */ @@ -458,7 +286,7 @@ kern_dump(void) sc->segname[0] = 0; sc->vmaddr = vmoffset; sc->vmsize = size; - sc->fileoff = foffset; + sc->fileoff = (uint32_t) foffset; sc->filesize = size; sc->maxprot = maxprot; sc->initprot = prot; @@ -531,8 +359,7 @@ kern_dump(void) } /* last packet */ - if ((panic_error = kdp_send_crashdump_pkt (KDP_EOF, NULL, 0, ((void *) 0))) < 0) - { + if ((panic_error = kdp_send_crashdump_pkt (KDP_EOF, NULL, 0, ((void *) 0))) < 0) { printf ("kdp_send_crashdump_pkt failed with error %d\n", panic_error); error = panic_error; goto out;