Changeset 14590
- Timestamp:
- Jan 21, 2011, 10:25:33 PM (14 years ago)
- Location:
- trunk/source/lisp-kernel
- Files:
-
- 2 edited
-
lisp-debug.c (modified) (1 diff)
-
mach-o-image.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/lisp-kernel/lisp-debug.c
r14484 r14590 886 886 (cs_area->low), (cs_area->high)); 887 887 fprintf(dbgout, "Value (lisp) stack area: low = 0x" LISP ", high = 0x" LISP "\n", 888 ( u64_t)(natural)(vs_area->low), (u64_t)(natural)vs_area->high);888 (natural)(vs_area->low), (natural)vs_area->high); 889 889 if (xp) { 890 890 fprintf(dbgout, "Exception stack pointer = 0x" LISP "\n", 891 891 #ifdef PPC 892 ( u64_t) (natural)(xpGPR(xp,1))892 (natural)(xpGPR(xp,1)) 893 893 #endif 894 894 #ifdef X86 895 ( u64_t) (natural)(xpGPR(xp,Isp))895 (natural)(xpGPR(xp,Isp)) 896 896 #endif 897 897 #ifdef ARM 898 ( u64_t) (natural)(xpGPR(xp,Rsp))898 (natural)(xpGPR(xp,Rsp)) 899 899 #endif 900 900 ); -
trunk/source/lisp-kernel/mach-o-image.c
r14584 r14590 26 26 typedef struct mach_header_64 macho_header; 27 27 #define MACHO_MAGIC MH_MAGIC_64 28 #define MACHO_LC_SEGMENT LC_SEGMENT_64 28 29 typedef struct segment_command_64 macho_segment_command; 29 30 typedef struct section_64 macho_section; … … 32 33 typedef struct mach_header_64 macho_header; 33 34 #define MACHO_MAGIC MH_MAGIC 35 #define MACHO_LC_SEGMENT LC_SEGMENT 34 36 typedef struct segment_command macho_segment_command; 35 37 typedef struct section macho_section; … … 53 55 macho_symbol_table *all_symbols, *local_symbols, *defined_external_symbols, *undefined_external_symbols; 54 56 57 macho_section * 58 nth_section_in_segment(macho_segment_command *segment, int sectno) 59 { 60 return (macho_section *)(((char *)segment)+sizeof(macho_segment_command)+(sizeof(macho_section) *sectno)); 61 } 62 55 63 ssize_t 56 64 safe_read(int fd, char *buf, size_t nbytes) … … 71 79 if (n == 0) { 72 80 fprintf(stderr, "unexpected end of file reading image\n"); 81 exit(1); 82 } 83 total += n; 84 buf += n; 85 } 86 return total; 87 } 88 89 ssize_t 90 safe_write(int fd, char *buf, size_t nbytes) 91 { 92 size_t total = 0; 93 ssize_t n; 94 while (total < nbytes) { 95 n = nbytes-total; 96 if (n > INT_MAX) { 97 n = INT_MAX; 98 } 99 n = write(fd, buf, n); 100 if (n < 0) { 101 perror("writing to image"); 73 102 exit(1); 74 103 } … … 216 245 } 217 246 247 void 248 add_lisp_function_stab(LispObj f, natural size_in_bytes, macho_string_table *strings, macho_symbol_table *syms, int section_ordinal) 249 { 250 macho_nlist symbol; 251 252 symbol.n_type = N_BNSYM; 253 symbol.n_un.n_strx = 1; 254 symbol.n_sect = section_ordinal; 255 symbol.n_desc = 0; 256 symbol.n_value = f; 257 add_symbol(&symbol, syms); 258 259 symbol.n_type = N_FUN; 260 symbol.n_un.n_strx = save_string(print_lisp_object(f),strings); 261 symbol.n_sect = section_ordinal; 262 symbol.n_desc = 0; 263 symbol.n_value = f; 264 add_symbol(&symbol, syms); 265 266 symbol.n_type = N_FUN; 267 symbol.n_un.n_strx = 1; 268 symbol.n_sect = NO_SECT; 269 symbol.n_desc = 0; 270 symbol.n_value = size_in_bytes; 271 add_symbol(&symbol, syms); 272 273 symbol.n_type = N_ENSYM; 274 symbol.n_un.n_strx = 1; 275 symbol.n_sect = section_ordinal; 276 symbol.n_desc = 0; 277 symbol.n_value = size_in_bytes; 278 add_symbol(&symbol, syms); 279 } 280 281 #ifdef X86 282 void 283 add_lisp_function_stabs(macho_symbol_table *symbols, macho_string_table *strings, int section_ordinal) 284 { 285 LispObj 286 *start = (LispObj *) readonly_area->low, 287 *end = (LispObj *) readonly_area->active, 288 header, 289 f; 290 int tag; 291 natural size_in_bytes; 292 293 while (start < end) { 294 header = *start; 295 tag = header_subtag(header); 296 if (tag == subtag_function) { 297 #ifdef X8632 298 f = ((LispObj)start)+fulltag_misc; 299 size_in_bytes = (header_element_count(header)<<node_shift)-tag_misc; 300 #endif 301 #ifdef X8664 302 f = ((LispObj)start)+fulltag_function; 303 size_in_bytes = (header_element_count(header)<<node_shift)-tag_function; 304 #endif 305 306 add_lisp_function_stab(f,size_in_bytes,strings,symbols,section_ordinal); 307 start += ((header_element_count(header)+2)&~1); 308 } else { 309 start = (LispObj *)skip_over_ivector((LispObj)start,header); 310 } 311 } 312 } 313 #endif 314 315 typedef struct { 316 char page[4096]; 317 int used; 318 int load_command_offsets[16]; 319 } macho_prefix; 320 321 macho_prefix * 322 init_macho_prefix(uint32_t magic, cpu_type_t cputype, cpu_subtype_t cpusubtype, uint32_t filetype, uint32_t flags) { 323 macho_prefix *p = calloc(1,sizeof(macho_prefix)); 324 macho_header *h = (macho_header *) p; 325 326 h->magic = magic; 327 h->cputype = cputype; 328 h->cpusubtype = cpusubtype; 329 h->filetype = filetype; 330 h->flags = flags; 331 p->used = sizeof(macho_header); 332 return p; 333 } 334 335 struct load_command * 336 add_load_command(macho_prefix *p, uint32_t cmd, uint32_t cmdsize) 337 { 338 struct load_command *l = (struct load_command *)&(p->page[p->used]); 339 macho_header *h = (macho_header *)p; 340 341 cmdsize = align_to_power_of_2(cmdsize,node_shift); 342 p->load_command_offsets[h->ncmds] = p->used; 343 p->used += cmdsize; 344 l->cmd = cmd; 345 l->cmdsize += cmdsize; 346 h->ncmds++; 347 h->sizeofcmds += cmdsize; 348 return l; 349 } 350 351 macho_segment_command * 352 add_segment(macho_prefix *p,char *segname, int nsections, ...) /* sectnames */ 353 { 354 macho_segment_command *seg = (macho_segment_command *) add_load_command(p, MACHO_LC_SEGMENT, sizeof(macho_segment_command)+(nsections * sizeof(macho_section))); 355 macho_section *sect = nth_section_in_segment(seg, 0); 356 va_list sectnames; 357 char *sectname; 358 359 seg->nsects = nsections; 360 strncpy(seg->segname,segname,sizeof(seg->segname)); 361 va_start(sectnames,nsections); 362 while(nsections--) { 363 sectname = va_arg(sectnames,char *); 364 strncpy(sect->sectname,sectname,sizeof(sect->sectname)); 365 strncpy(sect->segname,segname,sizeof(sect->segname)); 366 sect++; 367 } 368 return seg; 369 } 370 371 372 void 373 save_native_library(int fd) 374 { 375 macho_prefix *p = init_macho_prefix(MACHO_MAGIC, 376 #ifdef X8632 377 CPU_TYPE_I386, 378 CPU_SUBTYPE_X86_ALL, 379 #endif 380 #ifdef X8664 381 CPU_TYPE_X86_64, 382 CPU_SUBTYPE_X86_64_ALL, 383 #endif 384 #ifdef PPC32 385 CPU_TYPE_POWERPC, 386 CPU_SUBTYPE_POWERPC_ALL, 387 #endif 388 #ifdef PPC64 389 CPU_TYPE_POWERPC64, 390 CPU_TYPE_POWERPC_ALL, 391 #endif 392 #ifdef ARM 393 CPU_TYPE_ARM, 394 CPU_SUBTYPE_ARM_ALL, 395 #endif 396 MH_DYLIB, 397 MH_NOUNDEFS); 398 macho_segment_command *seg; 399 macho_section *sect; 400 off_t curpos = 4096; 401 402 403 seg = add_segment(p, "innocent", 1, "bystander"); 404 seg->vmaddr = (natural)(readonly_area->low-4096); 405 seg->vmsize = 4096; 406 seg->fileoff = 0; 407 seg->filesize = 4096; 408 seg->maxprot = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE; 409 seg->initprot = VM_PROT_READ|VM_PROT_EXECUTE; 410 sect = nth_section_in_segment(seg,0); 411 sect->addr = (natural)(readonly_area->low-1); 412 sect->size = 1; 413 sect->offset = 4095; 414 sect->flags = S_ATTR_SOME_INSTRUCTIONS | S_ATTR_PURE_INSTRUCTIONS; 415 p->page[4095] = 0xcc; 416 417 seg = add_segment(p,"READONLY",1,"readonly"); 418 seg->vmaddr = (natural)(readonly_area->low); 419 seg->vmsize = align_to_power_of_2(readonly_area->active-readonly_area->low,12); 420 seg->fileoff = curpos; 421 seg->filesize = seg->vmsize; 422 seg->maxprot = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE; 423 seg->initprot = VM_PROT_READ|VM_PROT_EXECUTE; 424 sect = nth_section_in_segment(seg,0); 425 sect->addr = (natural)(readonly_area->low); 426 sect->size = readonly_area->active-readonly_area->low; 427 sect->offset = seg->fileoff; 428 sect->flags = S_ATTR_SOME_INSTRUCTIONS; 429 lseek(fd,curpos,SEEK_SET); 430 safe_write(fd,readonly_area->low,seg->filesize); 431 432 433 434 }
Note:
See TracChangeset
for help on using the changeset viewer.
