- goto out;
-
- /*
- * Set up Mach-O header.
- */
- mh = (struct mach_header *) header;
- mh->magic = orig_mh->magic;
- mh->cputype = orig_mh->cputype;
- mh->cpusubtype = orig_mh->cpusubtype;
- mh->filetype = orig_mh->filetype;
- mh->ncmds = 3;
- mh->sizeofcmds = header_size - sizeof(struct mach_header);
- mh->flags = orig_mh->flags;
-
- // Initialise the current file offset and addr
- offset = round_page(header_size);
- addr = (caddr_t) const_text->addr; // Load address of __TEXT,__const
-
- /*
- * Construct a TEXT segment load command
- * the only part of the TEXT segment we keep is the __TEXT,__const
- * which contains the kernel vtables.
- */
- sg = (struct segment_command *) &mh[1];
- bcopy(orig_ts, sg, orig_ts->cmdsize);
- sg->vmaddr = (unsigned long) addr;
- sg->vmsize = const_text->size;
- sg->fileoff = 0;
- sg->filesize = const_text->size + round_page(header_size);
- sg->maxprot = 0;
- sg->initprot = 0;
- sg->flags = 0;
- se = (struct section *)(sg+1);
- for ( j = 0; j < sg->nsects; j++, se++ ) {
- se->addr = (unsigned long) addr;
- se->size = 0;
- se->offset = offset;
- se->nreloc = 0;
- if (!strcmp("__const", se->sectname)) {
- se->size = const_text->size;
- addr += const_text->size;
- offset += const_text->size;
- const_text = se;
- }
- }
- offset = round_page(offset);
-
- // Now copy of the __DATA segment load command, the image need
- // not be stored to disk nobody needs it, yet!
- sg = (struct segment_command *)((int)sg + sg->cmdsize);
- bcopy(orig_ds, sg, orig_ds->cmdsize);
-
- sg->vmaddr = (unsigned long) addr;
- sg->vmsize = 0x1000; // One page for some reason?
- sg->fileoff = offset;
- sg->filesize = 0;
- sg->maxprot = 0;
- sg->initprot = 0;
- sg->flags = 0;
- se = (struct section *)(sg+1);
- for ( j = 0; j < sg->nsects; j++, se++ ) {
- se->addr = (unsigned long) addr;
- se->size = 0;
- se->offset = offset;
- se->nreloc = 0;
- }
- offset = round_page(offset);
-
-
- /*
- * Set up LC_SYMTAB command
- */
- st = (struct symtab_command *)((int)sg + sg->cmdsize);
- st->cmd = LC_SYMTAB;
- st->cmdsize = sizeof(struct symtab_command);
- st->symoff = offset;
- st->nsyms = orig_st->nsyms;
- st->strsize = orig_st->strsize;
- st->stroff = offset + st->nsyms * sizeof(struct nlist);
-
- /*
- * Convert the symbol table in place from section references
- * to absolute references.
- */
- sym = (struct nlist *) orig_le->vmaddr;
- for (i = 0; i < st->nsyms; i++, sym++ ) {
- if ( (sym->n_type & N_TYPE) == N_SECT) {
- sym->n_sect = NO_SECT;
- sym->n_type = (sym->n_type & ~N_TYPE) | N_ABS;
- }