Patch title: Release 84 bulk changes
Abstract:
File: /pliant/language/os/dump.c
Key:
    Removed line
    Added line
   
// Copyright  Hubert Tonneau  hubert.tonneau@pliant.cx
//
// This program is free software; you can redistribute it an
// modify it under the terms of the GNU General Public Licen
// as published by the Free Software Foundation.
// 
// This program is distributed in the hope that it will be u
// but WITHOUT ANY WARRANTY; without even the implied warran
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// version 2 along with this program; if not, write to the F
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA


FUNCTION Void process_backup(struct Str *filename) {
  Char buffer[256]; struct Str temp; Any handle;
  struct PliantSignature s;
  struct MemoryPool *pool; Int i; struct MemoryChunk *c; str
  struct PliantArea a;
  Arrow *r; struct DelayedAction *da;
  memory_shrink(true);
  if(!build_full_br_name(filename,buffer,&temp)) {
    consolen(Z,"invalid dump file name ",S,filename,EOL);
    return; }
  handle=file_open(&temp,file_out);
  if(handle==-1) {
    consolen(Z,"failed to open dump file ",S,&temp,EOL);
    return; }
  G.execution_phase=phase_shutdown;
// Copyright  Hubert Tonneau  hubert.tonneau@pliant.cx
//
// This program is free software; you can redistribute it an
// modify it under the terms of the GNU General Public Licen
// as published by the Free Software Foundation.
// 
// This program is distributed in the hope that it will be u
// but WITHOUT ANY WARRANTY; without even the implied warran
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// version 2 along with this program; if not, write to the F
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA


FUNCTION Void process_backup(struct Str *filename) {
  Char buffer[256]; struct Str temp; Any handle;
  struct PliantSignature s;
  struct MemoryPool *pool; Int i; struct MemoryChunk *c; str
  struct PliantArea a;
  Arrow *r; struct DelayedAction *da;
  memory_shrink(true);
  if(!build_full_br_name(filename,buffer,&temp)) {
    consolen(Z,"invalid dump file name ",S,filename,EOL);
    return; }
  handle=file_open(&temp,file_out);
  if(handle==-1) {
    consolen(Z,"failed to open dump file ",S,&temp,EOL);
    return; }
  G.execution_phase=phase_shutdown;
  for(r=List_first(G.shutdown_actions); r!=G.null_constant; 
  for(r=List_last(G.shutdown_actions); r!=G.null_constant; r=List_previous(r)) {
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((ShutdownActionPrototype)da->function->exe)(da->paramet
  G.execution_phase=phase_backup;
  s.signature=0x738F5EC1;
  s.c_level=c_debugging_level;
  s.release=pliant_release_number;
  #if defined(_DLL_)
    s.expression_compile=Expression_compile;
  #endif
  file_write(handle,(Address)&s,sizeof(s));
  file_write(handle,(Address)&G,sizeof(G));
  for(pool=&G.memory_pool; pool!=null; pool=pool->next)
    for(i=0; i<pool->nb_area; i++) {
      a.address=pool->areas[i].address;
      for(c=Chunk_first(a.address); !Chunk_is_stop(c); c=Chu
        #ifdef _MARK_OBJECTS_
         if(!Chunk_is_inuse(c) && !Chunk_is_committed(c)) {
        #else
         if(!Chunk_is_committed(c)) {
        #endif
          c2=(struct MemoryChunk2 *)c;
          a.size=(Int)c2->decomitted_address-(Int)a.address;
          file_write(handle,(Address)&a,sizeof(a));
          file_write(handle,a.address,a.size);
          a.address=address_translate(c2->decomitted_address
      a.size=(Int)address_translate(pool->areas[i].address,p
      file_write(handle,(Address)&a,sizeof(a));
      file_write(handle,a.address,a.size); }
  a.address=null,a.size=0;
  file_write(handle,(Address)&a,sizeof(a));
  for(r=List_first(G.backup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((BackupActionPrototype)da->function->exe)(da->parameter
  file_close(handle);
  G.execution_phase=phase_wakeup;
  for(r=List_first(G.wakeup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((WakeupActionPrototype)da->function->exe)(da->parameter
  G.execution_phase=phase_run; }


FUNCTION Bool process_restore(Int debugging_level,Char *plia
  Char buffer[256]; struct Str temp; Any handle;
  struct PliantSignature s;
  struct MemoryPool *pool; Int i;
  struct PliantArea a; Int red;
  Arrow *r; struct DelayedAction *da;
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R1\r",3);
  #endif
  G.debugging_level=debugging_level;
  G.pliant_root_path.chars=pliant_path; G.pliant_root_path.l
  if(!build_full_br_name(filename,buffer,&temp)) return fals
  handle=file_open(&temp,file_in); if(handle==-1) return fal
  file_read(handle,(Address)&s,sizeof(s));
  #if defined(_DLL_)
    if(s.signature!=0x738F5EC1 || s.c_level!=c_debugging_lev
  #else
    if(s.signature!=0x738F5EC1 || s.c_level!=c_debugging_lev
  #endif
    file_close(handle);
    consolen(Z,"File ",S,filename,Z," is not compatible with
    return false; }
  file_read(handle,(Address)&G,sizeof(G));
  G.memory_current_consumed=0;
  G.memory_maximum_consumed=0;
  G.execution_phase=phase_restore;
  for(pool=&G.memory_pool; pool!=null; pool=pool->next)
    for(i=0; i<pool->nb_area; i++) {
      a.address=memory_page_reserve(pool->areas[i].address,p
      if(a.address!=pool->areas[i].address) {
        consolen(Z,"Failed to restore memory from ",S,filena
        process_exit(error_id_restore); } }
  for(;;) {
    a.address=null; file_read(handle,(Address)&a,sizeof(a));
    memory_page_commit(a.address,a.size);
    red=file_read(handle,a.address,a.size);
    if(red!=a.size) {
      consolen(Z,"File ",S,filename,Z," is corrupted !",EOL)
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((ShutdownActionPrototype)da->function->exe)(da->paramet
  G.execution_phase=phase_backup;
  s.signature=0x738F5EC1;
  s.c_level=c_debugging_level;
  s.release=pliant_release_number;
  #if defined(_DLL_)
    s.expression_compile=Expression_compile;
  #endif
  file_write(handle,(Address)&s,sizeof(s));
  file_write(handle,(Address)&G,sizeof(G));
  for(pool=&G.memory_pool; pool!=null; pool=pool->next)
    for(i=0; i<pool->nb_area; i++) {
      a.address=pool->areas[i].address;
      for(c=Chunk_first(a.address); !Chunk_is_stop(c); c=Chu
        #ifdef _MARK_OBJECTS_
         if(!Chunk_is_inuse(c) && !Chunk_is_committed(c)) {
        #else
         if(!Chunk_is_committed(c)) {
        #endif
          c2=(struct MemoryChunk2 *)c;
          a.size=(Int)c2->decomitted_address-(Int)a.address;
          file_write(handle,(Address)&a,sizeof(a));
          file_write(handle,a.address,a.size);
          a.address=address_translate(c2->decomitted_address
      a.size=(Int)address_translate(pool->areas[i].address,p
      file_write(handle,(Address)&a,sizeof(a));
      file_write(handle,a.address,a.size); }
  a.address=null,a.size=0;
  file_write(handle,(Address)&a,sizeof(a));
  for(r=List_first(G.backup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((BackupActionPrototype)da->function->exe)(da->parameter
  file_close(handle);
  G.execution_phase=phase_wakeup;
  for(r=List_first(G.wakeup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((WakeupActionPrototype)da->function->exe)(da->parameter
  G.execution_phase=phase_run; }


FUNCTION Bool process_restore(Int debugging_level,Char *plia
  Char buffer[256]; struct Str temp; Any handle;
  struct PliantSignature s;
  struct MemoryPool *pool; Int i;
  struct PliantArea a; Int red;
  Arrow *r; struct DelayedAction *da;
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R1\r",3);
  #endif
  G.debugging_level=debugging_level;
  G.pliant_root_path.chars=pliant_path; G.pliant_root_path.l
  if(!build_full_br_name(filename,buffer,&temp)) return fals
  handle=file_open(&temp,file_in); if(handle==-1) return fal
  file_read(handle,(Address)&s,sizeof(s));
  #if defined(_DLL_)
    if(s.signature!=0x738F5EC1 || s.c_level!=c_debugging_lev
  #else
    if(s.signature!=0x738F5EC1 || s.c_level!=c_debugging_lev
  #endif
    file_close(handle);
    consolen(Z,"File ",S,filename,Z," is not compatible with
    return false; }
  file_read(handle,(Address)&G,sizeof(G));
  G.memory_current_consumed=0;
  G.memory_maximum_consumed=0;
  G.execution_phase=phase_restore;
  for(pool=&G.memory_pool; pool!=null; pool=pool->next)
    for(i=0; i<pool->nb_area; i++) {
      a.address=memory_page_reserve(pool->areas[i].address,p
      if(a.address!=pool->areas[i].address) {
        consolen(Z,"Failed to restore memory from ",S,filena
        process_exit(error_id_restore); } }
  for(;;) {
    a.address=null; file_read(handle,(Address)&a,sizeof(a));
    memory_page_commit(a.address,a.size);
    red=file_read(handle,a.address,a.size);
    if(red!=a.size) {
      consolen(Z,"File ",S,filename,Z," is corrupted !",EOL)
      file_close(handle);
      handle=file_open(&temp,file_out);
      s.signature=0;
      file_write(handle,(Address)&s,sizeof(s));
      file_close(handle);
      process_exit(error_id_restore); } }
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R2\r",3);
  #endif
  #ifndef _STATIC_
    restore_externals();
  #endif
  for(r=List_first(G.restore_actions); r!=G.null_constant; r
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((RestoreActionPrototype)da->function->exe)(da->paramete
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R3\r",3);
  #endif
  file_close(handle);
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"  \r",3);
  #endif
  G.execution_phase=phase_wakeup;
  for(r=List_first(G.wakeup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((WakeupActionPrototype)da->function->exe)(da->parameter
  G.execution_phase=phase_run;
  return true; }
      process_exit(error_id_restore); } }
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R2\r",3);
  #endif
  #ifndef _STATIC_
    restore_externals();
  #endif
  for(r=List_first(G.restore_actions); r!=G.null_constant; r
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((RestoreActionPrototype)da->function->exe)(da->paramete
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"R3\r",3);
  #endif
  file_close(handle);
  #if defined(_LINUX_API_) && defined(_CHECK_) && defined(_V
    write(1,"  \r",3);
  #endif
  G.execution_phase=phase_wakeup;
  for(r=List_first(G.wakeup_actions); r!=G.null_constant; r=
    check(entry_type(*r)==G.type_DelayedAction);
    da=(struct DelayedAction *)*r;
    ((WakeupActionPrototype)da->function->exe)(da->parameter
  G.execution_phase=phase_run;
  return true; }