Lines Matching refs:seg
54 static kern_return_t reorder_sections(KXLDSeg *seg, KXLDArray *section_order);
64 static kern_return_t seg_export_macho_header_32(const KXLDSeg *seg, u_char *buf,
68 static kern_return_t seg_export_macho_header_64(const KXLDSeg *seg, u_char *buf,
72 static KXLDSect * get_sect_by_index(const KXLDSeg *seg, u_int idx);
78 kxld_seg_init_from_macho_32(KXLDSeg *seg, struct segment_command *src)
81 check(seg);
84 strlcpy(seg->segname, src->segname, sizeof(seg->segname));
85 seg->base_addr = src->vmaddr;
86 seg->link_addr = src->vmaddr;
87 seg->vmsize = src->vmsize;
88 seg->fileoff = src->fileoff;
89 seg->maxprot = src->maxprot;
90 seg->initprot = src->initprot;
91 seg->flags = src->flags;
93 rval = kxld_array_init(&seg->sects, sizeof(KXLDSect *), src->nsects);
107 kxld_seg_init_from_macho_64(KXLDSeg *seg, struct segment_command_64 *src)
110 check(seg);
113 strlcpy(seg->segname, src->segname, sizeof(seg->segname));
114 seg->base_addr = src->vmaddr;
115 seg->link_addr = src->vmaddr;
116 seg->vmsize = src->vmsize;
117 seg->fileoff = src->fileoff;
118 seg->maxprot = src->maxprot;
119 seg->initprot = src->initprot;
120 seg->flags = src->flags;
122 rval = kxld_array_init(&seg->sects, sizeof(KXLDSect *), src->nsects);
139 KXLDSeg *seg = NULL;
151 seg = kxld_array_get_item(segarray, 0);
152 seg->initprot = VM_PROT_ALL;
153 seg->maxprot = VM_PROT_ALL;
154 seg->link_addr = 0;
158 rval = kxld_array_init(&seg->sects, sizeof(KXLDSect *), sectarray->nitems);
163 sectp = kxld_array_get_item(&seg->sects, i);
180 KXLDSeg *seg = NULL;
189 seg = kxld_array_get_item(segarray, 0);
193 rval = reorder_sections(seg, section_order);
198 seg->link_addr = round_page(hdrsize);
202 sect_offset = (u_long) seg->link_addr;
203 for (i = 0; i < seg->sects.nitems; ++i) {
204 sect = *(KXLDSect **)kxld_array_get_item(&seg->sects, i);
212 seg->vmsize = round_page(sect_offset) - seg->link_addr;
266 reorder_sections(KXLDSeg *seg, KXLDArray *section_order)
278 check(seg);
286 seg->sects.nitems * sizeof(*reorder_buffer));
319 while (sect_index < seg->sects.nitems) {
320 sect = *(KXLDSect **) kxld_array_get_item(&seg->sects, sect_index);
336 *(KXLDSect **) kxld_array_get_item(&seg->sects, i);
363 (void) reorder_section(&seg->sects, §_reorder_index,
375 reorder_section(&seg->sects, §_reorder_index, reorder_buffer, i);
384 kxld_free(reorder_buffer, seg->sects.nitems * sizeof(*reorder_buffer));
414 KXLDSeg *seg = NULL;
420 seg = kxld_array_get_item(segs, 0);
424 le->link_addr = round_page(seg->link_addr + seg->vmsize);
438 kxld_seg_clear(KXLDSeg *seg)
440 check(seg);
442 bzero(seg->segname, sizeof(seg->segname));
443 seg->base_addr = 0;
444 seg->link_addr = 0;
445 seg->vmsize = 0;
446 seg->flags = 0;
447 seg->maxprot = 0;
448 seg->initprot = 0;
453 kxld_array_clear(&seg->sects);
459 kxld_seg_deinit(KXLDSeg *seg)
461 check(seg);
463 kxld_array_deinit(&seg->sects);
464 bzero(seg, sizeof(*seg));
470 kxld_seg_get_vmsize(const KXLDSeg *seg)
472 check(seg);
474 return seg->vmsize;
480 kxld_seg_get_macho_header_size(const KXLDSeg *seg, boolean_t is_32_bit)
484 check(seg);
491 size += seg->sects.nitems * kxld_sect_get_macho_header_size(is_32_bit);
501 kxld_seg_get_macho_data_size(const KXLDSeg *seg)
507 check(seg);
509 for (i = 0; i < seg->sects.nitems; ++i) {
510 sect = get_sect_by_index(seg, i);
522 get_sect_by_index(const KXLDSeg *seg, u_int idx)
524 check(seg);
526 return *(KXLDSect **) kxld_array_get_item(&seg->sects, idx);
532 kxld_seg_export_macho_to_file_buffer(const KXLDSeg *seg, u_char *buf,
546 check(seg);
555 seg, buf, header_offset, header_size, *data_offset);
560 for (i = 0; i < seg->sects.nitems; ++i) {
561 sect = get_sect_by_index(seg, i);
588 kxld_seg_export_macho_to_vm(const KXLDSeg *seg, u_char *buf,
595 u_long data_offset = (u_long) (seg->link_addr - file_link_addr);
598 check(seg);
606 seg, buf, header_offset, header_size, data_offset);
611 for (i = 0; i < seg->sects.nitems; ++i) {
612 sect = get_sect_by_index(seg, i);
629 seg_export_macho_header_32(const KXLDSeg *seg, u_char *buf,
635 check(seg);
647 (uint32_t) (seg->sects.nitems * kxld_sect_get_macho_header_size(TRUE));
648 strlcpy(seghdr->segname, seg->segname, sizeof(seghdr->segname));
649 seghdr->vmaddr = (uint32_t) seg->link_addr;
650 seghdr->vmsize = (uint32_t) seg->vmsize;
652 seghdr->filesize = (uint32_t) seg->vmsize;
653 seghdr->maxprot = seg->maxprot;
654 seghdr->initprot = seg->initprot;
655 seghdr->nsects = seg->sects.nitems;
669 seg_export_macho_header_64(const KXLDSeg *seg, u_char *buf,
675 check(seg);
687 (uint32_t) (seg->sects.nitems * kxld_sect_get_macho_header_size(FALSE));
688 strlcpy(seghdr->segname, seg->segname, sizeof(seghdr->segname));
689 seghdr->vmaddr = (uint64_t) seg->link_addr;
690 seghdr->vmsize = (uint64_t) seg->vmsize;
692 seghdr->filesize = (uint64_t) seg->vmsize;
693 seghdr->maxprot = seg->maxprot;
694 seghdr->initprot = seg->initprot;
695 seghdr->nsects = seg->sects.nitems;
708 kxld_seg_add_section(KXLDSeg *seg, KXLDSect *sect)
714 check(seg);
716 require_action(streq_safe(seg->segname, sect->segname, sizeof(seg->segname)),
721 for (i = 0; i < seg->sects.nitems; ++i) {
722 sectp = kxld_array_get_item(&seg->sects, i);
728 require_action(i < seg->sects.nitems, finish, rval=KERN_FAILURE);
740 kxld_seg_finish_init(KXLDSeg *seg)
748 if (seg->sects.nitems) {
749 for (i = 0; i < seg->sects.nitems; ++i) {
750 sect = get_sect_by_index(seg, i);
761 seg->vmsize = round_page(maxaddr + maxsize - seg->base_addr);
773 kxld_seg_set_vm_protections(KXLDSeg *seg, boolean_t strict_protections)
779 if (!seg) return;
782 if (streq_safe(seg->segname, SEG_TEXT, const_strlen(SEG_TEXT))) {
783 seg->initprot = TEXT_SEG_PROT;
784 seg->maxprot = VM_PROT_ALL;
786 seg->initprot = DATA_SEG_PROT;
787 seg->maxprot = DATA_SEG_PROT;
790 seg->initprot = VM_PROT_ALL;
791 seg->maxprot = VM_PROT_ALL;
798 kxld_seg_relocate(KXLDSeg *seg, kxld_addr_t link_addr)
803 seg->link_addr += link_addr;
804 for (i = 0; i < seg->sects.nitems; ++i) {
805 sect = get_sect_by_index(seg, i);
813 kxld_seg_populate_linkedit(KXLDSeg *seg, const KXLDSymtab *symtab, boolean_t is_32_bit
831 seg->vmsize = round_page(size);