Changeset 14601


Ignore:
Timestamp:
Jan 27, 2011, 5:33:43 AM (8 years ago)
Author:
gb
Message:

save_application's first arg is signed; if it's negative, save
a native library on Darwin (so far.)

Juggle things around to enable this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/image.c

    r14329 r14601  
    497497}
    498498
    499 OSErr
    500 save_application(unsigned fd, Boolean egc_was_enabled)
    501 {
    502   openmcl_image_file_header fh;
    503   openmcl_image_section_header sections[NUM_IMAGE_SECTIONS];
    504   openmcl_image_file_trailer trailer;
    505   area *areas[NUM_IMAGE_SECTIONS], *a;
    506   int i, err;
    507   off_t header_pos, eof_pos;
    508 #if WORD_SIZE == 64
    509   off_t image_data_pos;
    510   signed_natural section_data_delta;
    511 #endif
    512 
    513   /*
    514     Coerce macptrs to dead_macptrs.
    515   */
    516  
    517   prepare_to_write_dynamic_space(active_dynamic_area);
    518   prepare_to_write_dynamic_space(managed_static_area);
    519 
    520   /*
    521      If we ever support continuing after saving an image,
    522      undo this .. */
    523 
    524   if (static_cons_area->high > static_cons_area->low) {
    525     active_dynamic_area->low = static_cons_area->high;
    526     tenured_area->static_dnodes -= area_dnode(static_cons_area->high, static_cons_area->low);
    527   }
    528 
    529   areas[0] = nilreg_area;
    530   areas[1] = readonly_area;
    531   areas[2] = active_dynamic_area;
    532   areas[3] = managed_static_area;
    533   areas[4] = static_cons_area;
    534   for (i = 0; i < NUM_IMAGE_SECTIONS; i++) {
    535     a = areas[i];
    536     sections[i].code = a->code;
    537     sections[i].area = NULL;
    538     sections[i].memory_size  = a->active - a->low;
    539     if (a == active_dynamic_area) {
    540       sections[i].static_dnodes = tenured_area->static_dnodes;
    541     } else {
    542       sections[i].static_dnodes = 0;
    543     }
    544   }
    545   fh.sig0 = IMAGE_SIG0;
    546   fh.sig1 = IMAGE_SIG1;
    547   fh.sig2 = IMAGE_SIG2;
    548   fh.sig3 = IMAGE_SIG3;
    549   fh.timestamp = time(NULL);
    550   CANONICAL_IMAGE_BASE(&fh) = IMAGE_BASE_ADDRESS;
    551   ACTUAL_IMAGE_BASE(&fh) = image_base;
    552   fh.nsections = NUM_IMAGE_SECTIONS;
    553   fh.abi_version=ABI_VERSION_CURRENT;
    554 #if WORD_SIZE == 64
    555   fh.section_data_offset_high = 0;
    556   fh.section_data_offset_low = 0;
    557 #else
    558   fh.pad0[0] = fh.pad0[1] = 0;
    559   fh.pad1[0] = fh.pad1[1] = fh.pad1[2] = fh.pad1[3] = 0;
    560 #endif
    561   fh.flags = PLATFORM;
    562 
    563 #if WORD_SIZE == 64
    564   image_data_pos = seek_to_next_page(fd);
    565 #else
    566   err = write_file_and_section_headers(fd, &fh, sections, NUM_IMAGE_SECTIONS, &header_pos);
    567   if (err) {
    568     return err;
    569   }
    570 #endif
    571 
    572 
    573   {
    574     area *g0_area = g1_area->younger;
    575 
    576     /* Save GC config */
    577     lisp_global(LISP_HEAP_THRESHOLD) = lisp_heap_gc_threshold;
    578     lisp_global(G0_THRESHOLD) = g0_area->threshold;
    579     lisp_global(G1_THRESHOLD) = g1_area->threshold;
    580     lisp_global(G2_THRESHOLD) = g2_area->threshold;
    581     lisp_global(EGC_ENABLED) = (LispObj)egc_was_enabled;
    582     lisp_global(GC_NOTIFY_THRESHOLD) = lisp_heap_notify_threshold;
    583   }
     499void
     500prepare_to_write_static_space(Boolean egc_was_enabled)
     501{
     502  area *g0_area = g1_area->younger;
     503  int i;
     504
     505  /* Save GC config */
     506  lisp_global(LISP_HEAP_THRESHOLD) = lisp_heap_gc_threshold;
     507  lisp_global(G0_THRESHOLD) = g0_area->threshold;
     508  lisp_global(G1_THRESHOLD) = g1_area->threshold;
     509  lisp_global(G2_THRESHOLD) = g2_area->threshold;
     510  lisp_global(EGC_ENABLED) = (LispObj)egc_was_enabled;
     511  lisp_global(GC_NOTIFY_THRESHOLD) = lisp_heap_notify_threshold;
    584512  /*
    585513    lisp_global(GC_NUM) and lisp_global(FWDNUM) are persistent,
     
    609537    }
    610538  }
     539}
     540
     541
     542OSErr
     543save_application_internal(unsigned fd, Boolean egc_was_enabled)
     544{
     545  openmcl_image_file_header fh;
     546  openmcl_image_section_header sections[NUM_IMAGE_SECTIONS];
     547  openmcl_image_file_trailer trailer;
     548  area *areas[NUM_IMAGE_SECTIONS], *a;
     549  int i, err;
     550  off_t header_pos, eof_pos;
     551#if WORD_SIZE == 64
     552  off_t image_data_pos;
     553  signed_natural section_data_delta;
     554#endif
     555
     556  /*
     557    Coerce macptrs to dead_macptrs.
     558  */
     559 
     560  prepare_to_write_dynamic_space(active_dynamic_area);
     561  prepare_to_write_dynamic_space(managed_static_area);
     562
     563  /*
     564     If we ever support continuing after saving an image,
     565     undo this .. */
     566
     567  if (static_cons_area->high > static_cons_area->low) {
     568    active_dynamic_area->low = static_cons_area->high;
     569    tenured_area->static_dnodes -= area_dnode(static_cons_area->high, static_cons_area->low);
     570  }
     571
     572  areas[0] = nilreg_area;
     573  areas[1] = readonly_area;
     574  areas[2] = active_dynamic_area;
     575  areas[3] = managed_static_area;
     576  areas[4] = static_cons_area;
     577  for (i = 0; i < NUM_IMAGE_SECTIONS; i++) {
     578    a = areas[i];
     579    sections[i].code = a->code;
     580    sections[i].area = NULL;
     581    sections[i].memory_size  = a->active - a->low;
     582    if (a == active_dynamic_area) {
     583      sections[i].static_dnodes = tenured_area->static_dnodes;
     584    } else {
     585      sections[i].static_dnodes = 0;
     586    }
     587  }
     588  fh.sig0 = IMAGE_SIG0;
     589  fh.sig1 = IMAGE_SIG1;
     590  fh.sig2 = IMAGE_SIG2;
     591  fh.sig3 = IMAGE_SIG3;
     592  fh.timestamp = time(NULL);
     593  CANONICAL_IMAGE_BASE(&fh) = IMAGE_BASE_ADDRESS;
     594  ACTUAL_IMAGE_BASE(&fh) = image_base;
     595  fh.nsections = NUM_IMAGE_SECTIONS;
     596  fh.abi_version=ABI_VERSION_CURRENT;
     597#if WORD_SIZE == 64
     598  fh.section_data_offset_high = 0;
     599  fh.section_data_offset_low = 0;
     600#else
     601  fh.pad0[0] = fh.pad0[1] = 0;
     602  fh.pad1[0] = fh.pad1[1] = fh.pad1[2] = fh.pad1[3] = 0;
     603#endif
     604  fh.flags = PLATFORM;
     605
     606#if WORD_SIZE == 64
     607  image_data_pos = seek_to_next_page(fd);
     608#else
     609  err = write_file_and_section_headers(fd, &fh, sections, NUM_IMAGE_SECTIONS, &header_pos);
     610  if (err) {
     611    return err;
     612  }
     613#endif
     614
     615  prepare_to_write_static_space(egc_was_enabled);
     616
     617
    611618
    612619  for (i = 0; i < NUM_IMAGE_SECTIONS; i++) {
     
    657664  return i;
    658665}
     666
     667OSErr
     668save_application(int fd, Boolean egc_was_enabled)
     669{
     670#ifdef DARWIN
     671#ifdef X86
     672  extern void save_native_library(int, Boolean);
     673 
     674  if (fd < 0) {
     675    save_native_library(-fd, egc_was_enabled);
     676    return 0;
     677  }
     678#endif
     679#endif
     680  return save_application_internal(fd, egc_was_enabled);
     681}
     682
    659683     
    660684
Note: See TracChangeset for help on using the changeset viewer.