2015-11-05 16:59:56 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
2015-04-15 11:21:15 +01:00
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: save.c *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: saving and restoring a Prolog computation *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "@(#)save.c 1.3 3/15/90";
|
|
|
|
#endif
|
|
|
|
|
2016-01-31 10:18:12 +00:00
|
|
|
#include "absmi.h"
|
|
|
|
#include "alloc.h"
|
2002-06-01 02:46:06 +01:00
|
|
|
#if _MSC_VER || defined(__MINGW32__)
|
2013-11-16 16:58:07 +00:00
|
|
|
#if HAVE_WINSOCK2_H
|
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
2002-06-01 02:46:06 +01:00
|
|
|
#include <windows.h>
|
2006-08-30 02:06:30 +01:00
|
|
|
#include <psapi.h>
|
2002-06-01 02:46:06 +01:00
|
|
|
#endif
|
2004-12-07 06:01:55 +00:00
|
|
|
#if USE_DL_MALLOC
|
|
|
|
#include "dlmalloc.h"
|
|
|
|
#endif
|
2015-10-20 08:06:46 +01:00
|
|
|
#include "YapText.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "sshift.h"
|
2016-01-31 10:18:12 +00:00
|
|
|
#include "yapio.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "Foreign.h"
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#if !HAVE_STRNCAT
|
|
|
|
#define strncat(X,Y,Z) strcat(X,Y)
|
|
|
|
#endif
|
|
|
|
#if !HAVE_STRNCPY
|
|
|
|
#define strncpy(X,Y,Z) strcpy(X,Y)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2001-05-28 20:54:53 +01:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2002-06-01 02:46:06 +01:00
|
|
|
#include "iopreds.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-06-01 02:46:06 +01:00
|
|
|
/********* hack for accesing several kinds of terms. Should be cleaned **/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
static char end_msg[256] ="*** End of YAP saved state *****";
|
|
|
|
|
2011-02-15 19:24:15 +00:00
|
|
|
/* SWI IO, must be restarted after restore */
|
|
|
|
void initIO(void);
|
2002-05-14 19:22:42 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
/*
|
2015-04-15 11:21:15 +01:00
|
|
|
*
|
2002-05-28 17:26:00 +01:00
|
|
|
#FOR DEBUGGING define DEBUG_RESTORE0 to check the file stuff,
|
|
|
|
#define DEBUG_RESTORE1 to see if it is able to prepare the chain,
|
|
|
|
#define DEBUG_RESTORE2 to see how things are going,
|
|
|
|
#define DEBUG_RESTORE3 to check if the atom chain is still a working chain,
|
2001-04-09 20:54:03 +01:00
|
|
|
* define DEBUG_RESTORE4 if you want to set the output for some
|
|
|
|
* particular file,
|
|
|
|
* define DEBUG_RESTORE5 if you want to see how the stacks are being
|
|
|
|
* cleaned up,
|
2015-04-15 11:21:15 +01:00
|
|
|
* define DEBUG_RESTORE6 if you want to follow the execution in
|
2001-04-09 20:54:03 +01:00
|
|
|
*
|
2015-04-15 11:21:15 +01:00
|
|
|
* Also a file is defined where you can write things, by default stderr
|
2001-04-09 20:54:03 +01:00
|
|
|
*
|
2015-04-15 11:21:15 +01:00
|
|
|
* Good Luck
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
static int myread(FILE *, char *, Int);
|
|
|
|
static Int mywrite(FILE *, char *, Int);
|
|
|
|
static FILE *open_file(char *, int);
|
2013-04-25 23:15:04 +01:00
|
|
|
static int close_file(void);
|
|
|
|
static Int putout(CELL);
|
|
|
|
static Int putcellptr(CELL *);
|
|
|
|
static CELL get_cell(void);
|
|
|
|
static CELL *get_cellptr( /* CELL * */ void);
|
|
|
|
static int put_info(int, int CACHE_TYPE);
|
|
|
|
static int save_regs(int CACHE_TYPE);
|
|
|
|
static int save_code_info(void);
|
|
|
|
static int save_heap(void);
|
|
|
|
static int save_stacks(int CACHE_TYPE);
|
|
|
|
static int save_crc(void);
|
|
|
|
static Int do_save(int CACHE_TYPE);
|
|
|
|
static Int p_save2( CACHE_TYPE1 );
|
|
|
|
static Int p_save_program( CACHE_TYPE1 );
|
|
|
|
static int check_header(CELL *, CELL *, CELL *, CELL * CACHE_TYPE);
|
|
|
|
static int get_heap_info(CACHE_TYPE1);
|
|
|
|
static int get_regs(int CACHE_TYPE);
|
|
|
|
static int get_insts(OPCODE []);
|
|
|
|
static int get_hash(void);
|
|
|
|
static int CopyCode( CACHE_TYPE1 );
|
|
|
|
static int CopyStacks( CACHE_TYPE1 );
|
|
|
|
static int get_coded(int, OPCODE [] CACHE_TYPE);
|
|
|
|
static void restore_codes(void);
|
|
|
|
static void RestoreDB(DBEntry * CACHE_TYPE);
|
2016-02-28 19:30:46 +00:00
|
|
|
static void RestoreDBTerm(DBTerm *, bool, int CACHE_TYPE);
|
|
|
|
static void CleanClauses(yamop *First, yamop *Last, PredEntry *pp USES_REGS);
|
2013-04-25 23:15:04 +01:00
|
|
|
static void rehash(CELL *, int, int CACHE_TYPE);
|
|
|
|
static void CleanCode(PredEntry * CACHE_TYPE);
|
|
|
|
static void RestoreEntries(PropEntry *, int CACHE_TYPE);
|
|
|
|
static void RestoreFreeSpace( CACHE_TYPE1 );
|
|
|
|
static void restore_heap(void);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG_RESTORE3
|
2013-04-25 23:15:04 +01:00
|
|
|
static void ShowAtoms(void);
|
|
|
|
static void ShowEntries(PropEntry *);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2016-05-10 08:33:44 +01:00
|
|
|
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *, CELL *, FILE **);
|
2013-04-25 23:15:04 +01:00
|
|
|
static void CloseRestore(void);
|
2009-11-23 16:01:41 +00:00
|
|
|
#ifndef _WIN32
|
2013-04-25 23:15:04 +01:00
|
|
|
static int check_opcodes(OPCODE []);
|
2009-11-23 16:01:41 +00:00
|
|
|
#endif
|
2013-04-25 23:15:04 +01:00
|
|
|
static void RestoreHeap(OPCODE [] CACHE_TYPE);
|
|
|
|
static Int p_restore( CACHE_TYPE1 );
|
|
|
|
static void restore_heap_regs( CACHE_TYPE1 );
|
|
|
|
static void restore_regs(int CACHE_TYPE);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MACYAP
|
2013-04-25 23:15:04 +01:00
|
|
|
static void NewFileInfo(long, long);
|
2001-04-09 20:54:03 +01:00
|
|
|
extern int DefVol;
|
|
|
|
#endif
|
|
|
|
|
2008-06-05 17:24:08 +01:00
|
|
|
#ifdef _WIN32
|
2001-05-28 20:54:53 +01:00
|
|
|
#if HAVE_IO_H
|
2001-04-09 20:54:03 +01:00
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2008-06-05 17:24:08 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef LIGHT
|
|
|
|
|
|
|
|
#include <unix.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
void
|
2001-04-09 20:54:03 +01:00
|
|
|
LightBug(char *);
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
LightBug(s)
|
2015-04-15 11:21:15 +01:00
|
|
|
char *s;
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LIGHT */
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static Int
|
2015-09-25 10:57:26 +01:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg)
|
2005-03-02 18:35:49 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2016-10-20 04:44:59 +01:00
|
|
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE+1);
|
2005-03-02 18:35:49 +00:00
|
|
|
#if HAVE_SNPRINTF
|
|
|
|
#if HAVE_STRERROR
|
2016-10-20 04:44:59 +01:00
|
|
|
snprintf(LOCAL_ErrorMessage,MAX_ERROR_MSG_SIZE,"%s (%s when reading %s)", msg,
|
|
|
|
strerror(errno), LOCAL_FileNameBuf);
|
2005-03-02 18:35:49 +00:00
|
|
|
#else
|
2015-04-15 11:21:15 +01:00
|
|
|
snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
|
2005-03-02 18:35:49 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if HAVE_STRERROR
|
2011-05-23 16:19:47 +01:00
|
|
|
sprintf(LOCAL_ErrorSay,"%s, (%s when reading %s)",msg,strerror(errno),LOCAL_FileNameBuf);
|
2005-03-02 18:35:49 +00:00
|
|
|
#else
|
2015-04-15 11:21:15 +01:00
|
|
|
sprintf(LOCAL_ErrorSay,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
|
2005-03-02 18:35:49 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_Error_TYPE = etype;
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
inline static
|
2015-06-19 01:30:13 +01:00
|
|
|
int myread(FILE *fd, char *buffer, Int len) {
|
2016-02-28 19:32:55 +00:00
|
|
|
size_t nread;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
while (len > 0) {
|
2015-06-19 01:30:13 +01:00
|
|
|
nread = fread(buffer, 1, (int)len, fd);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (nread < 1) {
|
2015-09-25 10:57:26 +01:00
|
|
|
return do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"bad read on saved state");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
buffer += nread;
|
|
|
|
len -= nread;
|
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return len;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static
|
2010-03-22 16:56:58 +00:00
|
|
|
Int
|
2015-06-19 01:30:13 +01:00
|
|
|
mywrite(FILE *fd, char *buff, Int len) {
|
2016-02-28 19:32:55 +00:00
|
|
|
size_t nwritten;
|
2015-06-19 01:30:13 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
while (len > 0) {
|
2015-06-19 01:30:13 +01:00
|
|
|
nwritten = fwrite(buff, 1, (size_t)len, fd);
|
2016-02-29 03:13:23 +00:00
|
|
|
if ((long int)nwritten < 0) {
|
2015-09-25 10:57:26 +01:00
|
|
|
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,"bad write on saved state");
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
buff += nwritten;
|
|
|
|
len -= nwritten;
|
|
|
|
}
|
2010-03-22 16:56:58 +00:00
|
|
|
return len;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FullSaved 1
|
|
|
|
|
|
|
|
/* Where the code was before */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef CELL *CELLPOINTER;
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
static FILE *splfild = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
#ifdef DEBUG_RESTORE4
|
|
|
|
static FILE *errout;
|
|
|
|
#else
|
2011-05-25 16:40:36 +01:00
|
|
|
#define errout GLOBAL_stderr
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
static Int OldHeapUsed;
|
|
|
|
|
|
|
|
static CELL which_save;
|
|
|
|
|
|
|
|
/* Open a file to read or to write */
|
2015-06-19 01:30:13 +01:00
|
|
|
static FILE *
|
2002-11-11 17:38:10 +00:00
|
|
|
open_file(char *my_file, int flag)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2015-06-19 01:30:13 +01:00
|
|
|
FILE *splfild;
|
2014-10-24 15:18:32 +01:00
|
|
|
char flags[6];
|
|
|
|
int i=0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2014-10-24 15:18:32 +01:00
|
|
|
if (flag & O_RDONLY) {
|
|
|
|
flags[i++] = 'r';
|
|
|
|
}
|
|
|
|
if (flag & O_CREAT) {
|
|
|
|
flags[i++] = 'w';
|
|
|
|
}
|
|
|
|
if (flag & O_WRONLY) {
|
|
|
|
flags[i++] = 'w';
|
|
|
|
}
|
|
|
|
if (flag & O_APPEND) {
|
|
|
|
flags[i++] = 'a';
|
|
|
|
}
|
|
|
|
#if _WIN32
|
|
|
|
if (flag & O_BINARY) {
|
|
|
|
flags[i++] = 'b';
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2014-10-24 15:18:32 +01:00
|
|
|
flags[i] = '\0';
|
2015-06-19 01:30:13 +01:00
|
|
|
splfild = fopen( my_file, flags);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef undf0
|
2014-10-24 15:18:32 +01:00
|
|
|
fprintf(errout, "Opened file %s\n", my_file);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2014-11-09 11:16:24 +00:00
|
|
|
return splfild;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
close_file(void)
|
|
|
|
{
|
2002-10-30 17:27:19 +00:00
|
|
|
if (splfild == 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return 0;
|
2015-06-19 01:30:13 +01:00
|
|
|
if (fclose(splfild) < 0)
|
2015-09-25 10:57:26 +01:00
|
|
|
return do_SYSTEM_ERROR_INTERNAL(SYSTEM_ERROR_INTERNAL,"bad close on saved state");
|
2001-04-09 20:54:03 +01:00
|
|
|
splfild = 0;
|
2010-03-22 16:56:58 +00:00
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stores a cell in a file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static Int
|
2001-04-09 20:54:03 +01:00
|
|
|
putout(CELL l)
|
|
|
|
{
|
2010-03-22 16:56:58 +00:00
|
|
|
return mywrite(splfild, (char *) &l, sizeof(CELL));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stores a pointer to a cell in a file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static Int
|
2001-04-09 20:54:03 +01:00
|
|
|
putcellptr(CELL *l)
|
|
|
|
{
|
2010-03-22 16:56:58 +00:00
|
|
|
return mywrite(splfild, (char *) &l, sizeof(CELLPOINTER));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* gets a cell from a file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static CELL
|
2001-04-09 20:54:03 +01:00
|
|
|
get_cell(void)
|
|
|
|
{
|
2002-10-30 17:27:19 +00:00
|
|
|
CELL l;
|
|
|
|
myread(splfild, (char *) &l, Unsigned(sizeof(CELL)));
|
|
|
|
return (l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* gets a cell from a file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static CELL
|
2002-10-30 17:27:19 +00:00
|
|
|
get_header_cell(void)
|
|
|
|
{
|
|
|
|
CELL l;
|
2014-10-25 16:46:13 +01:00
|
|
|
size_t count = 0;
|
|
|
|
int n;
|
2002-10-30 17:27:19 +00:00
|
|
|
while (count < sizeof(CELL)) {
|
2015-06-19 01:30:13 +01:00
|
|
|
if ((n = fread(&l, 1, sizeof(CELL)-count, splfild)) < 0) {
|
2015-09-25 10:57:26 +01:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to read saved state header");
|
2005-03-02 18:35:49 +00:00
|
|
|
return 0L;
|
2002-10-30 17:27:19 +00:00
|
|
|
}
|
|
|
|
count += n;
|
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return l;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* gets a pointer to cell from a file */
|
|
|
|
static CELL *
|
|
|
|
get_cellptr(void)
|
|
|
|
{
|
2002-10-30 17:27:19 +00:00
|
|
|
CELL *l;
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
if (myread(splfild, (char *) &l, Unsigned(sizeof(CELLPOINTER))) < 0)
|
|
|
|
return NULL;
|
2002-10-30 17:27:19 +00:00
|
|
|
return (l);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* writes the header (at the moment YAPV*), info about what kind of saved
|
2015-04-15 11:21:15 +01:00
|
|
|
* set, the work size, and the space ocuppied
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
put_info(int info, int mode USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
char msg[256];
|
|
|
|
|
2014-02-16 12:57:00 +00:00
|
|
|
sprintf(msg, "#!/bin/sh\nexec_dir=${YAPBINDIR:-%s}\nexec $exec_dir/yap $0 \"$@\"\n%cYAP-%s", YAP_BINDIR, 1, YAP_FULL_VERSION);
|
2010-03-22 16:56:58 +00:00
|
|
|
if (mywrite(splfild, msg, strlen(msg) + 1))
|
|
|
|
return -1;
|
|
|
|
if (putout(Unsigned(info)) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* say whether we just saved the heap or everything */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(mode) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* current state of stacks, to be used by SavedInfo */
|
|
|
|
/* space available in heap area */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (putout(Unsigned(LOCAL_GlobalBase)-Unsigned(Yap_HeapBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* space available for stacks */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (putout(Unsigned(LOCAL_LocalBase)-Unsigned(LOCAL_GlobalBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* space available for trail */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (putout(Unsigned(LOCAL_TrailTop)-Unsigned(LOCAL_TrailBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Space used in heap area */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Space used for local stack */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(Unsigned(LCL0)-Unsigned(ASP)) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Space used for global stack */
|
2014-01-19 21:15:05 +00:00
|
|
|
if (putout(Unsigned(HR) - Unsigned(LOCAL_GlobalBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Space used for trail */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (putout(Unsigned(TR) - Unsigned(LOCAL_TrailBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
save_regs(int mode USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
/* save all registers */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout((CELL)compile_arrays) < 0)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode == DO_EVERYTHING) {
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr((CELL *)CP) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(ENV) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(ASP) < 0)
|
|
|
|
return -1;
|
|
|
|
/* if (putout((CELL)N) < 0)
|
|
|
|
return -1; */
|
|
|
|
if (putcellptr(H0) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(LCL0) < 0)
|
|
|
|
return -1;
|
2014-01-19 21:15:05 +00:00
|
|
|
if (putcellptr(HR) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
|
|
|
if (putcellptr(HB) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr((CELL *)B) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr((CELL *)TR) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(YENV) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(S) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr((CELL *)P) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putout(CreepFlag) < 0)
|
|
|
|
return -1;
|
2013-12-12 14:24:40 +00:00
|
|
|
if (putout(EventFlag) < 0)
|
|
|
|
return -1;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if defined(YAPOR_SBA) || defined(TABLING)
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(H_FZ) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr((CELL *)B_FZ) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr((CELL *)TR_FZ) < 0)
|
|
|
|
return -1;
|
2011-03-30 15:32:59 +01:00
|
|
|
#endif /* YAPOR_SBA || TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(CurrentModule) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode == DO_EVERYTHING) {
|
|
|
|
#ifdef COROUTINING
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_WokenGoals) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#ifdef DEPTH_LIMIT
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(DEPTH) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_GcGeneration) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_GcPhase) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_GcCurrentPhase) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* The operand base */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(CellPtr(XREGS)) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putout(which_save) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Now start by saving the code */
|
|
|
|
/* the heap boundaries */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(CellPtr(Yap_HeapBase)) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(CellPtr(HeapTop)) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* and the space it ocuppies */
|
2016-01-03 02:06:09 +00:00
|
|
|
if (putout(Unsigned(HeapUsed)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Then the start of the free code */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(CellPtr(FreeBlocks)) < 0)
|
|
|
|
return -1;
|
2010-04-22 12:08:51 +01:00
|
|
|
if (putcellptr(CellPtr(AuxBase)) < 0)
|
|
|
|
return -1;
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(AuxSp) < 0)
|
|
|
|
return -1;
|
|
|
|
if (putcellptr(CellPtr(AuxTop)) < 0)
|
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putcellptr(CellPtr(LOCAL_ScratchPad.ptr)) < 0)
|
2010-04-22 12:08:51 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_ScratchPad.sz) < 0)
|
2010-04-22 12:08:51 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
if (putout(LOCAL_ScratchPad.msz) < 0)
|
2010-04-22 12:08:51 +01:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (mode == DO_EVERYTHING) {
|
|
|
|
/* put the old trail base, just in case it moves again */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(ARG1) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (which_save == 2) {
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putout(ARG2) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (putcellptr(CellPtr(LOCAL_TrailBase)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2010-03-22 16:56:58 +00:00
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
save_code_info(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* First the instructions */
|
|
|
|
{
|
|
|
|
op_numbers i;
|
|
|
|
|
|
|
|
OPCODE my_ops[_std_top+1];
|
|
|
|
for (i = _Ystop; i <= _std_top; ++i)
|
2002-11-18 18:18:05 +00:00
|
|
|
my_ops[i] = Yap_opcode(i);
|
2010-03-22 16:56:58 +00:00
|
|
|
if (mywrite(splfild, (char *)my_ops, sizeof(OPCODE)*(_std_top+1)) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* and the current character codes */
|
2015-10-22 00:45:21 +01:00
|
|
|
if (mywrite(splfild, (char *)Yap_chtype, NUMBER_OF_CHARS*sizeof(char_kind_t)) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
save_heap(void)
|
|
|
|
{
|
2010-01-22 22:29:07 +00:00
|
|
|
#ifdef USE_SYSTEM_MALLOC
|
2010-03-30 09:16:07 +01:00
|
|
|
return -1;
|
2010-01-22 22:29:07 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
int j;
|
|
|
|
/* Then save the whole heap */
|
2010-03-21 22:12:42 +00:00
|
|
|
Yap_ResetConsultStack();
|
2002-11-18 18:18:05 +00:00
|
|
|
j = Unsigned(HeapTop) - Unsigned(Yap_HeapBase);
|
2001-04-09 20:54:03 +01:00
|
|
|
/* store 10 more cells because of the memory manager */
|
2010-03-22 16:56:58 +00:00
|
|
|
if (mywrite(splfild, (char *) Yap_HeapBase, j) < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
save_stacks(int mode USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int j;
|
2015-04-15 11:21:15 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
switch (mode) {
|
|
|
|
case DO_EVERYTHING:
|
|
|
|
/* Now, go and save the state */
|
|
|
|
/* Save the local stack */
|
|
|
|
j = Unsigned(LCL0) - Unsigned(ASP);
|
2010-03-22 16:56:58 +00:00
|
|
|
if (mywrite(splfild, (char *) ASP, j) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Save the global stack */
|
2014-01-19 21:15:05 +00:00
|
|
|
j = Unsigned(HR) - Unsigned(LOCAL_GlobalBase);
|
2011-05-23 16:19:47 +01:00
|
|
|
if (mywrite(splfild, (char *) LOCAL_GlobalBase, j) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Save the trail */
|
2011-05-23 16:19:47 +01:00
|
|
|
j = Unsigned(TR) - Unsigned(LOCAL_TrailBase);
|
|
|
|
if (mywrite(splfild, (char *) LOCAL_TrailBase, j) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case DO_ONLY_CODE:
|
|
|
|
{
|
2015-04-15 11:21:15 +01:00
|
|
|
tr_fr_ptr tr_ptr = TR;
|
2011-05-23 16:19:47 +01:00
|
|
|
while (tr_ptr != (tr_fr_ptr)LOCAL_TrailBase) {
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL val = TrailTerm(tr_ptr-1);
|
2001-12-17 18:31:11 +00:00
|
|
|
if (IsVarTerm(val)) {
|
|
|
|
CELL *d1 = VarOfTerm(val);
|
2010-03-22 16:56:58 +00:00
|
|
|
if (d1 < (CELL *)HeapTop) {
|
|
|
|
if (putout(val) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
2001-12-17 18:31:11 +00:00
|
|
|
} else if (IsPairTerm(val)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *d1 = RepPair(val);
|
2010-03-22 16:56:58 +00:00
|
|
|
if (d1 < (CELL *)HeapTop) {
|
|
|
|
if (putout(val) < 0)
|
|
|
|
return -1;
|
2015-04-15 11:21:15 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
tr_ptr--;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 16:56:58 +00:00
|
|
|
if (putcellptr(NULL) < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-03-22 16:56:58 +00:00
|
|
|
return 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:56:58 +00:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
save_crc(void)
|
|
|
|
{
|
|
|
|
/* Save a CRC */
|
2010-03-22 16:56:58 +00:00
|
|
|
return mywrite(splfild, end_msg, 256);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
do_save(int mode USES_REGS) {
|
2001-04-09 20:54:03 +01:00
|
|
|
Term t1 = Deref(ARG1);
|
2006-05-19 15:31:32 +01:00
|
|
|
|
|
|
|
if (Yap_HoleSize) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
2006-08-30 02:06:30 +01:00
|
|
|
"restore/1: address space has holes of size %ld, cannot save", (long int)Yap_HoleSize);
|
2006-05-19 15:31:32 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (!Yap_GetName(LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST,t1,"save/1");
|
2005-03-02 18:35:49 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_CloseStreams(TRUE);
|
2011-05-23 16:19:47 +01:00
|
|
|
if ((splfild = open_file(LOCAL_FileNameBuf, O_WRONLY | O_CREAT)) < 0) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)),
|
2015-04-15 11:21:15 +01:00
|
|
|
"restore/1, open(%s)", strerror(errno));
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
if (put_info(FullSaved, mode PASS_REGS) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
2011-03-07 16:02:55 +00:00
|
|
|
if (save_regs(mode PASS_REGS) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
|
|
|
if (save_code_info() < 0)
|
|
|
|
return -1;
|
|
|
|
if (save_heap() < 0)
|
|
|
|
return -1;
|
2011-03-07 16:02:55 +00:00
|
|
|
if (save_stacks(mode PASS_REGS) < 0)
|
2010-03-22 16:56:58 +00:00
|
|
|
return -1;
|
|
|
|
if (save_crc() < 0)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
close_file();
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Saves a complete prolog environment */
|
2015-04-15 11:21:15 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_save2( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2015-01-30 07:25:34 +00:00
|
|
|
Int res;
|
|
|
|
yhandle_t CurSlot = Yap_StartSlots();
|
2010-11-25 16:33:25 +00:00
|
|
|
|
2010-11-29 18:08:11 +00:00
|
|
|
Term t;
|
2011-04-29 14:59:17 +01:00
|
|
|
#ifdef YAPOR
|
2011-05-10 11:47:18 +01:00
|
|
|
if (GLOBAL_number_workers != 1) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,
|
2015-04-15 11:21:15 +01:00
|
|
|
"cannot perform save: more than a worker/thread running");
|
2010-10-15 01:15:45 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-04-29 14:59:17 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef THREADS
|
2011-05-10 10:06:51 +01:00
|
|
|
if (GLOBAL_NOfThreads != 1) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,
|
2015-04-15 11:21:15 +01:00
|
|
|
"cannot perform save: more than a worker/thread running");
|
2002-10-21 23:52:36 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-04-29 14:59:17 +01:00
|
|
|
#endif /* THREADS */
|
2010-11-29 18:08:11 +00:00
|
|
|
/* avoid double saves */
|
|
|
|
if (IsNonVarTerm(t = Deref(ARG2)))
|
|
|
|
return TRUE;
|
|
|
|
if (!Yap_unify(ARG2,MkIntTerm(1)))
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
which_save = 2;
|
2015-02-03 02:36:51 +00:00
|
|
|
CurSlot = Yap_StartSlots();
|
2011-03-07 16:02:55 +00:00
|
|
|
res = do_save(DO_EVERYTHING PASS_REGS);
|
2015-02-03 02:36:51 +00:00
|
|
|
Yap_CloseSlots(CurSlot);
|
2010-11-29 18:08:11 +00:00
|
|
|
return res;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Just save the program, not the stacks */
|
2015-04-15 11:21:15 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_save_program( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
which_save = 0;
|
2011-03-07 16:02:55 +00:00
|
|
|
return do_save(DO_ONLY_CODE PASS_REGS);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, to restore the saved code */
|
|
|
|
|
|
|
|
/* First check out if we are dealing with a valid file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2010-11-07 19:32:40 +00:00
|
|
|
char pp[256];
|
2001-04-09 20:54:03 +01:00
|
|
|
char msg[256];
|
2002-12-27 16:53:09 +00:00
|
|
|
CELL hp_size, gb_size, lc_size, tr_size, mode;
|
2006-06-02 16:21:35 +01:00
|
|
|
int n;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-10-30 17:27:19 +00:00
|
|
|
/* make sure we always check if there are enough bytes */
|
2001-04-09 20:54:03 +01:00
|
|
|
/* skip the first line */
|
2006-06-02 16:21:35 +01:00
|
|
|
pp[0] = '\0';
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
2015-06-19 01:30:13 +01:00
|
|
|
if ((n = fread(pp, 1, 1, splfild)) <= 0) {
|
2015-09-25 10:57:26 +01:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan first line from saved state");
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
} while (pp[0] != 1);
|
|
|
|
/* now check the version */
|
2014-02-16 12:57:00 +00:00
|
|
|
sprintf(msg, "YAP-%s", YAP_FULL_VERSION);
|
2002-10-30 17:27:19 +00:00
|
|
|
{
|
|
|
|
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
|
|
|
|
while (count < to_read) {
|
2015-06-19 01:30:13 +01:00
|
|
|
if ((n = fread(pp, 1, to_read-count, splfild)) <= 0) {
|
2015-09-25 10:57:26 +01:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan version info from saved state");
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
}
|
|
|
|
count += n;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (strcmp(pp, msg) != 0) {
|
2016-10-20 04:44:59 +01:00
|
|
|
strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE-1);
|
2013-01-25 09:31:44 +00:00
|
|
|
strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE-1);
|
|
|
|
strncat(LOCAL_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE-1);
|
2015-09-25 10:57:26 +01:00
|
|
|
LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE;
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* check info on header */
|
|
|
|
/* ignore info on saved state */
|
2002-10-30 17:27:19 +00:00
|
|
|
*info = get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* check the restore mode */
|
2002-10-30 17:27:19 +00:00
|
|
|
mode = get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
if (mode != DO_EVERYTHING && mode != DO_ONLY_CODE) {
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* ignore info on stacks size */
|
2002-10-30 17:27:19 +00:00
|
|
|
*AHeap = get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
2002-10-30 17:27:19 +00:00
|
|
|
*AStack = get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
2002-10-30 17:27:19 +00:00
|
|
|
*ATrail = get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage) {
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2005-03-02 18:35:49 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
/* now, check whether we got enough enough space to load the
|
|
|
|
saved space */
|
2002-09-09 18:40:12 +01:00
|
|
|
hp_size = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2004-01-23 02:23:51 +00:00
|
|
|
while (Yap_HeapBase != NULL &&
|
|
|
|
hp_size > Unsigned(HeapLim) - Unsigned(Yap_HeapBase)) {
|
|
|
|
if(!Yap_growheap(FALSE, hp_size, NULL)) {
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-09 05:26:48 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
if (mode == DO_EVERYTHING) {
|
2002-10-30 17:27:19 +00:00
|
|
|
lc_size = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
gb_size=get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (Yap_HeapBase != NULL && lc_size+gb_size > Unsigned(LOCAL_LocalBase) - Unsigned(LOCAL_GlobalBase)) {
|
|
|
|
if (LOCAL_ErrorMessage != NULL)
|
|
|
|
LOCAL_ErrorMessage = "could not allocate enough stack space";
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2011-05-23 16:19:47 +01:00
|
|
|
if (Yap_HeapBase != NULL && (tr_size = get_cell()) > Unsigned(LOCAL_TrailTop) - Unsigned(LOCAL_TrailBase)) {
|
|
|
|
if (LOCAL_ErrorMessage != NULL)
|
|
|
|
LOCAL_ErrorMessage = "could not allocate enough trail space";
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* skip cell size */
|
2002-10-30 17:27:19 +00:00
|
|
|
get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
get_header_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets the state of the heap, and evaluates the related variables */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
get_heap_info(USES_REGS1)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_OldHeapBase = (ADDR) get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_OldHeapTop = (ADDR) get_cellptr();
|
2010-10-15 01:15:45 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
OldHeapUsed = (Int) get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
FreeBlocks = (BlockHeader *) get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2010-04-22 12:08:51 +01:00
|
|
|
AuxBase = (ADDR)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2004-10-28 21:12:23 +01:00
|
|
|
AuxSp = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2004-10-28 21:12:23 +01:00
|
|
|
AuxTop = (ADDR)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ScratchPad.ptr = (ADDR)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ScratchPad.sz = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ScratchPad.msz = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_HDiff = Unsigned(Yap_HeapBase) - Unsigned(LOCAL_OldHeapBase);
|
2005-03-02 18:35:49 +00:00
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets the register array */
|
|
|
|
/* Saves the old bases for the work areas */
|
|
|
|
/* and evaluates the difference from the old areas to the new ones */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
get_regs(int flag USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-23 16:19:47 +01:00
|
|
|
CELL *NewGlobalBase = (CELL *)LOCAL_GlobalBase;
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *NewLCL0 = LCL0;
|
|
|
|
CELL *OldXREGS;
|
|
|
|
|
|
|
|
/* Get regs */
|
|
|
|
compile_arrays = (int)get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2015-04-15 11:21:15 +01:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flag == DO_EVERYTHING) {
|
|
|
|
CP = (yamop *)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
ENV = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
ASP = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* N = get_cell(); */
|
|
|
|
H0 = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
LCL0 = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2014-01-19 21:15:05 +00:00
|
|
|
HR = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
HB = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
B = (choiceptr)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
TR = (tr_fr_ptr)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
YENV = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
S = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
P = (yamop *)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
CreepFlag = get_cell();
|
2013-12-12 14:24:40 +00:00
|
|
|
if (LOCAL_ErrorMessage)
|
|
|
|
return -1;
|
|
|
|
EventFlag = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2011-03-30 15:32:59 +01:00
|
|
|
#if defined(YAPOR_SBA) || defined(TABLING)
|
2005-10-31 12:27:54 +00:00
|
|
|
H_FZ = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-10-31 12:27:54 +00:00
|
|
|
return -1;
|
|
|
|
B_FZ = (choiceptr)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-10-31 12:27:54 +00:00
|
|
|
return -1;
|
|
|
|
TR_FZ = (tr_fr_ptr)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-10-31 12:27:54 +00:00
|
|
|
return -1;
|
2011-03-30 15:32:59 +01:00
|
|
|
#endif /* YAPOR_SBA || TABLING */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-05-14 19:22:42 +01:00
|
|
|
CurrentModule = get_cell();
|
2015-04-15 11:21:15 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flag == DO_EVERYTHING) {
|
|
|
|
#ifdef COROUTINING
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_WokenGoals = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
#ifdef DEPTH_LIMIT
|
|
|
|
DEPTH = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_GcGeneration = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-09-21 04:49:33 +01:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_GcPhase = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2006-03-06 14:04:57 +00:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_GcCurrentPhase = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2006-03-06 14:04:57 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* Get the old bases */
|
|
|
|
OldXREGS = get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
which_save = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_XDiff = (CELL)XREGS - (CELL)OldXREGS;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2011-03-07 16:02:55 +00:00
|
|
|
if (get_heap_info( PASS_REGS1 ) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flag == DO_EVERYTHING) {
|
|
|
|
ARG1 = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (which_save == 2) {
|
|
|
|
ARG2 = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
/* get old trail base */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_OldTrailBase = (ADDR)get_cellptr();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Save the old register where we can easily access them */
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_OldASP = ASP;
|
|
|
|
LOCAL_OldLCL0 = LCL0;
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_OldGlobalBase = (CELL *)LOCAL_GlobalBase;
|
2014-01-19 21:15:05 +00:00
|
|
|
LOCAL_OldH = HR;
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_OldTR = TR;
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_GDiff = Unsigned(NewGlobalBase) - Unsigned(LOCAL_GlobalBase);
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_GDiff0 = 0;
|
|
|
|
LOCAL_LDiff = Unsigned(NewLCL0) - Unsigned(LCL0);
|
|
|
|
LOCAL_TrDiff = LOCAL_LDiff;
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_GlobalBase = (ADDR)NewGlobalBase;
|
2001-04-09 20:54:03 +01:00
|
|
|
LCL0 = NewLCL0;
|
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the old opcodes and place them in a hash table */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
get_insts(OPCODE old_ops[])
|
|
|
|
{
|
2005-03-02 18:35:49 +00:00
|
|
|
return myread(splfild, (char *)old_ops, sizeof(OPCODE)*(_std_top+1));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the old atoms hash table */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
get_hash(void)
|
|
|
|
{
|
2015-10-22 00:45:21 +01:00
|
|
|
return myread(splfild, (char *)Yap_chtype , NUMBER_OF_CHARS*sizeof(char_kind_t));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy all of the old code to the new Heap */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
CopyCode( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-05-04 10:11:41 +01:00
|
|
|
if (myread(splfild, (char *) Yap_HeapBase, (Unsigned(LOCAL_OldHeapTop) - Unsigned(LOCAL_OldHeapBase))) < 0) {
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2010-10-15 01:15:45 +01:00
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the local and global stack and also the trail to their new home */
|
|
|
|
/* In REGS we still have nonadjusted values !! */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
CopyStacks( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Int j;
|
|
|
|
char *NewASP;
|
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
j = Unsigned(LOCAL_OldLCL0) - Unsigned(ASP);
|
|
|
|
NewASP = (char *) (Unsigned(ASP) + (Unsigned(LCL0) - Unsigned(LOCAL_OldLCL0)));
|
2005-03-02 18:35:49 +00:00
|
|
|
if (myread(splfild, (char *) NewASP, j) < 0)
|
|
|
|
return -1;
|
2014-01-19 21:15:05 +00:00
|
|
|
j = Unsigned(HR) - Unsigned(LOCAL_OldGlobalBase);
|
2011-05-23 16:19:47 +01:00
|
|
|
if (myread(splfild, (char *) LOCAL_GlobalBase, j) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2011-05-04 10:11:41 +01:00
|
|
|
j = Unsigned(TR) - Unsigned(LOCAL_OldTrailBase);
|
2011-05-23 16:19:47 +01:00
|
|
|
if (myread(splfild, LOCAL_TrailBase, j))
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the local and global stack and also the trail to their new home */
|
|
|
|
/* In REGS we still have nonadjusted values !! */
|
2005-03-02 18:35:49 +00:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
CopyTrailEntries( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
CELL entry, *Entries;
|
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
Entries = (CELL *)LOCAL_TrailBase;
|
2001-04-09 20:54:03 +01:00
|
|
|
do {
|
|
|
|
*Entries++ = entry = get_cell();
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
} while ((CODEADDR)entry != NULL);
|
2005-03-02 18:35:49 +00:00
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get things which are saved in the file */
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
get_coded(int flag, OPCODE old_ops[] USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
char my_end_msg[256];
|
2015-04-15 11:21:15 +01:00
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
if (get_regs(flag PASS_REGS) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
|
|
|
if (get_insts(old_ops) < 0)
|
|
|
|
return -1;
|
|
|
|
if (get_hash() < 0)
|
|
|
|
return -1;
|
2011-03-07 16:02:55 +00:00
|
|
|
if (CopyCode( PASS_REGS1 ) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
switch (flag) {
|
|
|
|
case DO_EVERYTHING:
|
2011-03-07 16:02:55 +00:00
|
|
|
if (CopyStacks( PASS_REGS1 ) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
case DO_ONLY_CODE:
|
2011-03-07 16:02:55 +00:00
|
|
|
if (CopyTrailEntries( PASS_REGS1 ) < 0)
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Check CRC */
|
2005-03-02 18:35:49 +00:00
|
|
|
if (myread(splfild, my_end_msg, 256) < 0)
|
|
|
|
return -1;
|
|
|
|
if (strcmp(end_msg,my_end_msg) != 0) {
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_ErrorMessage = "bad trailing CRC in saved state";
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2016-01-03 02:06:09 +00:00
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/* restore some heap registers */
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_heap_regs( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-02-15 12:41:33 +00:00
|
|
|
if (HeapTop) {
|
|
|
|
HeapTop = AddrAdjust(HeapTop);
|
|
|
|
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
|
|
|
|
}
|
2016-07-31 10:35:00 +01:00
|
|
|
// HeapMax = HeapUsed = OldHeapUsed;
|
2011-05-23 16:19:47 +01:00
|
|
|
HeapLim = LOCAL_GlobalBase;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust abstract machine registers */
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_regs(int flag USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_heap_regs( PASS_REGS1 );
|
2005-11-23 03:01:33 +00:00
|
|
|
if (CurrentModule) {
|
|
|
|
CurrentModule = AtomTermAdjust(CurrentModule);;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flag == DO_EVERYTHING) {
|
|
|
|
CP = PtoOpAdjust(CP);
|
|
|
|
ENV = PtoLocAdjust(ENV);
|
|
|
|
ASP = PtoLocAdjust(ASP);
|
2014-01-19 21:15:05 +00:00
|
|
|
HR = PtoGloAdjust(HR);
|
2001-04-09 20:54:03 +01:00
|
|
|
B = (choiceptr)PtoLocAdjust(CellPtr(B));
|
|
|
|
TR = PtoTRAdjust(TR);
|
|
|
|
P = PtoOpAdjust(P);
|
|
|
|
HB = PtoLocAdjust(HB);
|
|
|
|
YENV = PtoLocAdjust(YENV);
|
|
|
|
S = PtoGloAdjust(S);
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_WokenGoals = AbsAppl(PtoGloAdjust(RepAppl(LOCAL_WokenGoals)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recompute_mask(DBRef dbr)
|
|
|
|
{
|
|
|
|
if (dbr->Flags & DBNoVars) {
|
2003-08-27 14:37:10 +01:00
|
|
|
dbr->Mask = Yap_EvalMasks((Term) dbr->DBT.Entry, &(dbr->Key));
|
2001-04-09 20:54:03 +01:00
|
|
|
} else if (dbr->Flags & DBComplex) {
|
|
|
|
/* This is quite nasty, we want to recalculate the mask but
|
|
|
|
we don't want to rebuild the whole term. We'll just build whatever we
|
|
|
|
need to recompute the mask.
|
|
|
|
*/
|
2002-06-04 19:21:55 +01:00
|
|
|
CELL *x = (CELL *)HeapTop, *tp;
|
|
|
|
unsigned int Arity, i;
|
|
|
|
Term out;
|
2003-08-27 14:37:10 +01:00
|
|
|
char *tbase = CharP(dbr->DBT.Contents-1);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
if (IsPairTerm(dbr->DBT.Entry)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-06-04 19:21:55 +01:00
|
|
|
out = AbsPair(x);
|
|
|
|
Arity = 2;
|
2003-08-27 14:37:10 +01:00
|
|
|
tp = (CELL *)(tbase + (CELL) RepPair(dbr->DBT.Entry));
|
2002-06-04 19:21:55 +01:00
|
|
|
} else {
|
|
|
|
Functor f;
|
2015-04-15 11:21:15 +01:00
|
|
|
|
2003-08-27 14:37:10 +01:00
|
|
|
tp = (CELL *)(tbase + (CELL) RepAppl(dbr->DBT.Entry));
|
2002-06-04 19:21:55 +01:00
|
|
|
f = (Functor)(*tp++);
|
|
|
|
out = AbsAppl(x);
|
|
|
|
Arity = ArityOfFunctor(f);
|
|
|
|
*x++ = (CELL)f;
|
|
|
|
if (Arity > 3) Arity = 3;
|
|
|
|
}
|
|
|
|
for (i = 0; i < Arity; i++) {
|
|
|
|
register Term tw = *tp++;
|
|
|
|
if (IsVarTerm(tw)) {
|
|
|
|
RESET_VARIABLE(x);
|
|
|
|
} else if (IsApplTerm(tw)) {
|
|
|
|
/* just fetch the functor from where it is in the data-base.
|
|
|
|
This guarantees we have access to references and friends. */
|
|
|
|
CELL offset = (CELL)RepAppl(tw);
|
2003-08-27 14:37:10 +01:00
|
|
|
if (offset > dbr->DBT.NOfCells*sizeof(CELL))
|
2002-06-04 19:21:55 +01:00
|
|
|
*x = tw;
|
|
|
|
else
|
|
|
|
*x = AbsAppl((CELL *)(tbase + offset));
|
|
|
|
} else if (IsAtomicTerm(tw)) {
|
|
|
|
*x = tw;
|
|
|
|
} else if (IsPairTerm(tw)) {
|
|
|
|
*x = AbsPair(x);
|
|
|
|
}
|
|
|
|
x++;
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
dbr->Mask = Yap_EvalMasks(out, &(dbr->Key));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HASH_SHIFT 6
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is used to make an hash table correct, after displacing its elements,
|
|
|
|
* HCEnd should point to an area of free space, usually in the heap. The
|
|
|
|
* routine is very dependent on the hash function used, and it destroys the
|
2015-04-15 11:21:15 +01:00
|
|
|
* previous "hit" order
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
rehash(CELL *oldcode, int NOfE, int KindOfEntries USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register CELL *savep, *basep;
|
|
|
|
CELL *oldp = oldcode;
|
|
|
|
int TableSize = NOfE - 1, NOfEntries;
|
|
|
|
register int i;
|
|
|
|
int hash;
|
|
|
|
CELL WorkTerm, failplace = 0;
|
|
|
|
CELL *Base = oldcode;
|
|
|
|
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_HDiff == 0)
|
2015-04-15 11:21:15 +01:00
|
|
|
return;
|
2014-01-19 21:15:05 +00:00
|
|
|
basep = HR;
|
|
|
|
if (HR + (NOfE*2) > ASP) {
|
2001-04-09 20:54:03 +01:00
|
|
|
basep = (CELL *)TR;
|
2011-05-23 16:19:47 +01:00
|
|
|
if (basep + (NOfE*2) > (CELL *)LOCAL_TrailTop) {
|
|
|
|
if (!Yap_growtrail((ADDR)(basep + (NOfE*2))-LOCAL_TrailTop, TRUE)) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(RESOURCE_ERROR_TRAIL, TermNil,
|
2015-04-15 11:21:15 +01:00
|
|
|
"not enough space to restore hash tables for indexing");
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exit(1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < NOfE; ++i) {
|
|
|
|
if (*oldp == 0) {
|
|
|
|
failplace = oldp[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
oldp += 2;
|
|
|
|
}
|
|
|
|
savep = basep;
|
|
|
|
oldp = oldcode;
|
|
|
|
for (i = 0; i < NOfE; ++i) {
|
|
|
|
if (*oldp != 0) {
|
|
|
|
savep[0] = oldp[0];
|
|
|
|
savep[1] = oldp[1];
|
|
|
|
oldp[0] = 0;
|
|
|
|
oldp[1] = failplace;
|
|
|
|
savep += 2;
|
|
|
|
}
|
|
|
|
oldp += 2;
|
|
|
|
}
|
|
|
|
NOfEntries = (savep - basep)/2;
|
|
|
|
savep = basep;
|
|
|
|
for (i = 0; i < NOfEntries; ++i) {
|
|
|
|
register Int d;
|
|
|
|
CELL *hentry;
|
|
|
|
|
|
|
|
WorkTerm = savep[i*2];
|
|
|
|
hash = (Unsigned(WorkTerm) >> HASH_SHIFT) & TableSize;
|
|
|
|
hentry = Base + hash * 2;
|
|
|
|
d = TableSize & (Unsigned(WorkTerm) | 1);
|
|
|
|
while (*hentry) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef CLASHES
|
|
|
|
++clashes;
|
|
|
|
#endif /* CLASHES */
|
|
|
|
#endif /* DEBUG */
|
|
|
|
hash = (hash + d) & TableSize;
|
|
|
|
hentry = Base + hash * 2;
|
|
|
|
}
|
|
|
|
hentry[0] = WorkTerm;
|
|
|
|
hentry[1] = savep[i*2+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 14:26:56 +01:00
|
|
|
|
2015-08-07 22:57:53 +01:00
|
|
|
static void RestoreFlags( UInt NFlags )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-06-04 19:21:55 +01:00
|
|
|
#include "rheap.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-05-28 17:26:00 +01:00
|
|
|
/* restore the atom entries which are invisible for the user */
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2002-05-28 17:26:00 +01:00
|
|
|
RestoreIOStructures(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitStdStreams();
|
2002-05-28 17:26:00 +01:00
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreFreeSpace( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2004-12-07 06:01:55 +00:00
|
|
|
#if USE_DL_MALLOC
|
|
|
|
Yap_av = (struct malloc_state *)AddrAdjust((ADDR)Yap_av);
|
2005-11-23 03:01:33 +00:00
|
|
|
Yap_RestoreDLMalloc();
|
2009-05-23 00:35:24 +01:00
|
|
|
if (AuxSp != NULL) {
|
2011-05-04 10:11:41 +01:00
|
|
|
if (AuxBase < LOCAL_OldHeapBase || AuxBase > LOCAL_OldHeapTop) {
|
2009-05-23 00:35:24 +01:00
|
|
|
AuxSp = NULL;
|
|
|
|
AuxBase = NULL;
|
|
|
|
AuxTop = NULL;
|
|
|
|
} else {
|
|
|
|
AuxSp = PtoHeapCellAdjust(AuxSp);
|
|
|
|
AuxBase = AddrAdjust(AuxBase);
|
|
|
|
AuxTop = AddrAdjust(AuxTop);
|
2011-05-04 10:11:41 +01:00
|
|
|
LOCAL_ScratchPad.ptr = AddrAdjust(LOCAL_ScratchPad.ptr);
|
2009-05-23 00:35:24 +01:00
|
|
|
}
|
|
|
|
}
|
2004-12-07 06:01:55 +00:00
|
|
|
#else
|
|
|
|
/* restores the list of free space, with its curious structure */
|
2005-11-23 03:01:33 +00:00
|
|
|
BlockHeader *bpt, *bsz;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
if (FreeBlocks != NULL)
|
|
|
|
FreeBlocks = BlockAdjust(FreeBlocks);
|
|
|
|
bpt = FreeBlocks;
|
2004-10-28 21:12:23 +01:00
|
|
|
if (AuxSp != NULL)
|
|
|
|
AuxSp = CellPtoHeapAdjust(AuxSp);
|
|
|
|
if (AuxTop != NULL)
|
|
|
|
AuxTop = AddrAdjust(AuxTop);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (bpt != NULL) {
|
|
|
|
if (bpt->b_next != NULL) {
|
|
|
|
bsz = bpt->b_next = BlockAdjust(bpt->b_next);
|
|
|
|
while (bsz != NULL) {
|
2015-04-15 11:21:15 +01:00
|
|
|
if (bsz->b_next_size != NULL)
|
2001-04-09 20:54:03 +01:00
|
|
|
bsz->b_next_size = BlockAdjust(bsz->b_next_size);
|
2015-04-15 11:21:15 +01:00
|
|
|
if (bsz->b_next != NULL)
|
2001-04-09 20:54:03 +01:00
|
|
|
bsz->b_next = BlockAdjust(bsz->b_next);
|
2015-04-15 11:21:15 +01:00
|
|
|
bsz = bsz->b_next;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bpt->b_next_size != NULL)
|
|
|
|
bpt->b_next_size = BlockAdjust(bpt->b_next_size);
|
|
|
|
bpt = bpt->b_next_size;
|
|
|
|
}
|
|
|
|
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
|
2004-12-07 06:01:55 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2007-02-18 00:26:36 +00:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreAtomList(Atom atm USES_REGS)
|
2002-06-04 19:21:55 +01:00
|
|
|
{
|
|
|
|
AtomEntry *at;
|
|
|
|
|
|
|
|
at = RepAtom(atm);
|
|
|
|
if (EndOfPAEntr(at))
|
|
|
|
return;
|
|
|
|
do {
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreAtom(at PASS_REGS);
|
2008-05-12 23:31:37 +01:00
|
|
|
at = RepAtom(at->NextOfAE);
|
|
|
|
} while (!EndOfPAEntr(at));
|
2002-06-04 19:21:55 +01:00
|
|
|
}
|
|
|
|
|
2007-02-18 00:26:36 +00:00
|
|
|
|
2007-09-29 00:18:17 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreHashPreds( USES_REGS1 )
|
2007-09-29 00:18:17 +01:00
|
|
|
{
|
2008-04-01 15:09:43 +01:00
|
|
|
UInt size = PredHashTableSize;
|
2014-09-10 05:50:43 +01:00
|
|
|
bool malloced = FALSE;
|
2008-04-01 15:09:43 +01:00
|
|
|
PredEntry **np;
|
2007-09-29 00:18:17 +01:00
|
|
|
UInt i;
|
2009-10-28 13:11:35 +00:00
|
|
|
PredEntry **oldp = PredHash;
|
2007-09-29 00:18:17 +01:00
|
|
|
|
2014-06-14 10:27:39 +01:00
|
|
|
np = (PredEntry **) Yap_AllocAtomSpace(sizeof(PredEntry *)*size);
|
2007-09-29 00:18:17 +01:00
|
|
|
if (!np) {
|
2014-06-14 10:27:39 +01:00
|
|
|
if (!(np = (PredEntry **) malloc(sizeof(PredEntry *)*size))) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_FATAL,TermNil,"Could not allocate space for pred table");
|
2015-04-15 11:21:15 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-04-01 15:09:43 +01:00
|
|
|
malloced = TRUE;
|
2007-09-29 00:18:17 +01:00
|
|
|
}
|
2008-04-01 15:09:43 +01:00
|
|
|
for (i = 0; i < size; i++) {
|
2007-09-29 00:18:17 +01:00
|
|
|
np[i] = NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < PredHashTableSize; i++) {
|
2008-04-01 09:42:46 +01:00
|
|
|
PredEntry *p = oldp[i];
|
2007-09-29 00:18:17 +01:00
|
|
|
|
2008-04-01 09:42:46 +01:00
|
|
|
if (p)
|
|
|
|
p = PredEntryAdjust(p);
|
2007-09-29 00:18:17 +01:00
|
|
|
while (p) {
|
2008-04-01 09:42:46 +01:00
|
|
|
Prop nextp;
|
2007-09-29 00:18:17 +01:00
|
|
|
UInt hsh;
|
2015-04-15 11:21:15 +01:00
|
|
|
|
2008-04-01 09:42:46 +01:00
|
|
|
if (p->NextOfPE)
|
|
|
|
p->NextOfPE = PropAdjust(p->NextOfPE);
|
|
|
|
nextp = p->NextOfPE;
|
2011-03-07 16:02:55 +00:00
|
|
|
CleanCode(p PASS_REGS);
|
2008-04-01 15:09:43 +01:00
|
|
|
hsh = PRED_HASH(p->FunctorOfPred, p->ModuleOfPred, size);
|
2007-09-29 00:18:17 +01:00
|
|
|
p->NextOfPE = AbsPredProp(np[hsh]);
|
|
|
|
np[hsh] = p;
|
|
|
|
p = RepPredProp(nextp);
|
|
|
|
}
|
|
|
|
}
|
2008-04-01 15:09:43 +01:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
PredHash[i] = np[i];
|
|
|
|
}
|
|
|
|
if (malloced)
|
|
|
|
free((ADDR)np);
|
|
|
|
else
|
|
|
|
Yap_FreeAtomSpace((ADDR)np);
|
2007-09-29 00:18:17 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
/*
|
2015-04-15 11:21:15 +01:00
|
|
|
* This is the really tough part, to restore the whole of the heap
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
restore_heap(void)
|
|
|
|
{
|
2009-10-30 23:59:00 +00:00
|
|
|
restore_codes();
|
2002-05-28 17:26:00 +01:00
|
|
|
RestoreIOStructures();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_RESTORE3
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
ShowEntries(pp)
|
2015-04-15 11:21:15 +01:00
|
|
|
PropEntry *pp;
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
while (!EndOfPAEntr(pp)) {
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr,"Estou a ver a prop %x em %x\n", pp->KindOfPE, pp);
|
2001-04-09 20:54:03 +01:00
|
|
|
pp = RepProp(pp->NextOfPE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
ShowAtoms()
|
|
|
|
{
|
|
|
|
AtomHashEntry *HashPtr = HashChain;
|
|
|
|
register int i;
|
2003-10-28 01:16:03 +00:00
|
|
|
for (i = 0; i < AtomHashTableSize; ++i) {
|
2001-04-09 20:54:03 +01:00
|
|
|
if (HashPtr->Entry != NIL) {
|
|
|
|
AtomEntry *at;
|
|
|
|
at = RepAtom(HashPtr->Entry);
|
|
|
|
do {
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
|
2001-10-30 16:42:05 +00:00
|
|
|
ShowEntries(RepProp(at->PropsOfAE));
|
2001-04-09 20:54:03 +01:00
|
|
|
} while (!EndOfPAEntr(at = RepAtom(at->NextOfAE)));
|
|
|
|
}
|
|
|
|
HashPtr++;
|
|
|
|
}
|
2006-11-27 17:42:03 +00:00
|
|
|
HashPtr = WideHashChain;
|
|
|
|
for (i = 0; i < WideAtomHashTableSize; ++i) {
|
|
|
|
if (HashPtr->Entry != NIL) {
|
|
|
|
AtomEntry *at;
|
|
|
|
at = RepAtom(HashPtr->Entry);
|
|
|
|
do {
|
2011-05-25 16:40:36 +01:00
|
|
|
fprintf(GLOBAL_stderr,"Passei ao %s em %x\n", at->StrOfAE, at);
|
2006-11-27 17:42:03 +00:00
|
|
|
ShowEntries(RepProp(at->PropsOfAE));
|
|
|
|
} while (!EndOfPAEntr(at = RepAtom(at->NextOfAE)));
|
|
|
|
}
|
|
|
|
HashPtr++;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG_RESTORE3 */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2002-10-30 17:27:19 +00:00
|
|
|
static int
|
|
|
|
commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap) {
|
2015-04-15 11:21:15 +01:00
|
|
|
CACHE_REGS
|
|
|
|
int mode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-03-07 16:02:55 +00:00
|
|
|
if ((mode = check_header(Astate,ATrail,AStack,AHeap PASS_REGS)) == FAIL_RESTORE)
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FAIL_RESTORE);
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode = BootMode;
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_HeapBase) {
|
2015-06-19 01:30:13 +01:00
|
|
|
if (falseGlobalPrologFlag( HALT_AFTER_CONSULT_FLAG ) && !silentMode( )) {
|
2016-05-10 08:33:44 +01:00
|
|
|
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true, true);
|
2011-05-23 16:19:47 +01:00
|
|
|
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
|
2002-10-30 17:27:19 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_CloseStreams(TRUE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_RESTORE4
|
|
|
|
/*
|
2015-04-15 11:21:15 +01:00
|
|
|
* This should be another file, like the log file
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2011-05-25 16:40:36 +01:00
|
|
|
errout = GLOBAL_stderr;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2010-08-17 13:19:17 +01:00
|
|
|
return mode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp) {
|
2010-08-17 13:19:17 +01:00
|
|
|
int mode;
|
|
|
|
|
2011-08-31 21:59:30 +01:00
|
|
|
if (streamp) {
|
2015-06-19 01:30:13 +01:00
|
|
|
if ((*streamp = fopen(inpf, "rb"))) {
|
2011-09-01 14:11:38 +01:00
|
|
|
return DO_ONLY_CODE;
|
|
|
|
}
|
|
|
|
return FAIL_RESTORE;
|
2011-08-31 21:59:30 +01:00
|
|
|
}
|
2010-08-17 13:19:17 +01:00
|
|
|
if ((splfild = open_file(inpf, O_RDONLY)) < 0) {
|
|
|
|
return FAIL_RESTORE;
|
|
|
|
}
|
|
|
|
if ((mode = commit_to_saved_state(inpf,Astate,ATrail,AStack,AHeap)) != FAIL_RESTORE) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-04-15 11:21:15 +01:00
|
|
|
LOCAL_ErrorMessage = NULL;
|
2010-08-17 13:19:17 +01:00
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2016-05-10 08:33:44 +01:00
|
|
|
OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStack, CELL *AHeap, FILE **streamp)
|
2002-10-30 17:27:19 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-04-15 11:21:15 +01:00
|
|
|
|
|
|
|
int mode;
|
2016-02-28 19:32:55 +00:00
|
|
|
char fname[YAP_FILENAME_MAX +1];
|
2016-02-13 02:56:19 +00:00
|
|
|
|
|
|
|
if (!Yap_findFile( inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE, true, true))
|
2015-04-15 11:21:15 +01:00
|
|
|
return false;
|
2015-06-19 01:30:13 +01:00
|
|
|
if (fname[0] &&
|
2015-04-15 11:21:15 +01:00
|
|
|
(mode = try_open(fname,Astate,ATrail,AStack,AHeap,streamp)) != FAIL_RESTORE) {
|
|
|
|
return mode;
|
2006-08-30 02:06:30 +01:00
|
|
|
}
|
|
|
|
/* try to open from current directory */
|
2003-01-08 16:45:35 +00:00
|
|
|
/* could not open file */
|
2011-05-23 16:19:47 +01:00
|
|
|
if (LOCAL_ErrorMessage == NULL) {
|
2015-11-05 16:59:56 +00:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,"incorrect saved state ");
|
2015-04-15 11:21:15 +01:00
|
|
|
} else {
|
|
|
|
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
2015-09-25 10:57:26 +01:00
|
|
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,"could not open saved state");
|
2003-01-08 16:45:35 +00:00
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return FAIL_RESTORE;
|
2002-10-30 17:27:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 01:30:13 +01:00
|
|
|
FILE *
|
2016-05-10 08:33:44 +01:00
|
|
|
Yap_OpenRestore(const char *inpf, const char *YapLibDir)
|
2011-08-31 21:59:30 +01:00
|
|
|
{
|
2015-06-19 01:30:13 +01:00
|
|
|
FILE *stream = NULL;
|
2011-08-31 21:59:30 +01:00
|
|
|
|
2016-02-13 03:11:25 +00:00
|
|
|
if (!inpf)
|
|
|
|
inpf = "startup.yss";
|
|
|
|
if (!YapLibDir) {
|
|
|
|
YapLibDir = YAP_LIBDIR;
|
|
|
|
}
|
2011-08-31 21:59:30 +01:00
|
|
|
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2001-04-09 20:54:03 +01:00
|
|
|
CloseRestore(void)
|
|
|
|
{
|
2015-04-15 11:21:15 +01:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG_RESTORE3
|
2015-04-15 11:21:15 +01:00
|
|
|
ShowAtoms();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
close_file();
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode = UserMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2006-05-16 19:37:31 +01:00
|
|
|
#if !defined(_WIN32)
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2001-04-09 20:54:03 +01:00
|
|
|
check_opcodes(OPCODE old_ops[])
|
|
|
|
{
|
|
|
|
#if USE_THREADED_CODE
|
2014-09-10 05:50:43 +01:00
|
|
|
bool have_shifted = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
op_numbers op = _Ystop;
|
|
|
|
for (op = _Ystop; op < _std_top; op++) {
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_opcode(op) != old_ops[op]) {
|
2001-04-09 20:54:03 +01:00
|
|
|
have_shifted = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-05-16 19:37:31 +01:00
|
|
|
return have_shifted;
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2006-05-16 19:37:31 +01:00
|
|
|
/* be conservative */
|
|
|
|
return TRUE;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
2006-05-16 19:37:31 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreHeap(OPCODE old_ops[] USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2014-09-10 05:50:43 +01:00
|
|
|
bool heap_moved = (LOCAL_OldHeapBase != Yap_HeapBase ||
|
2015-04-15 11:21:15 +01:00
|
|
|
LOCAL_XDiff), opcodes_moved;
|
2004-07-15 16:47:08 +01:00
|
|
|
Term mod = CurrentModule;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2004-07-15 16:47:08 +01:00
|
|
|
CurrentModule = PROLOG_MODULE;
|
2006-05-16 19:37:31 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
/* It seems that under WIN32 opcodes may not have moved but the
|
2015-04-15 11:21:15 +01:00
|
|
|
remaining code may have bmoved */
|
2006-05-16 19:37:31 +01:00
|
|
|
opcodes_moved = TRUE;
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
opcodes_moved = check_opcodes(old_ops);
|
2006-05-16 19:37:31 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* opcodes_moved has side-effects and should be tried first */
|
2005-11-23 03:01:33 +00:00
|
|
|
if (heap_moved) {
|
2008-05-12 15:04:23 +01:00
|
|
|
opcodes_moved = TRUE;
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreFreeSpace( PASS_REGS1 );
|
2005-11-23 03:01:33 +00:00
|
|
|
}
|
2004-11-23 21:17:47 +00:00
|
|
|
if (heap_moved || opcodes_moved) {
|
2001-04-09 20:54:03 +01:00
|
|
|
restore_heap();
|
|
|
|
}
|
|
|
|
/* This must be done after restore_heap */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAbsmi();
|
2004-02-06 02:26:23 +00:00
|
|
|
if (opcodes_moved) {
|
|
|
|
Yap_InitCPreds();
|
|
|
|
Yap_InitBackCPreds();
|
|
|
|
}
|
|
|
|
if (!(Yap_ReInitConstExps() &&
|
|
|
|
Yap_ReInitUnaryExps() &&
|
|
|
|
Yap_ReInitBinaryExps())) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "arithmetic operator not in saved state");
|
2004-02-06 02:26:23 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef DEBUG_RESTORE1
|
2002-11-11 17:38:10 +00:00
|
|
|
fprintf(errout, "phase 1 done\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2004-07-15 16:47:08 +01:00
|
|
|
CurrentModule = mod;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called to know about the parameters of the last saved
|
2015-04-15 11:21:15 +01:00
|
|
|
* state
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2015-04-15 11:21:15 +01:00
|
|
|
int
|
2016-05-10 08:33:44 +01:00
|
|
|
Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail, CELL *AStack, CELL *AHeap)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2011-08-31 21:59:30 +01:00
|
|
|
return DO_ONLY_CODE;
|
|
|
|
|
2002-10-30 17:27:19 +00:00
|
|
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
|
|
|
int mode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-08-31 21:59:30 +01:00
|
|
|
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL);
|
2002-10-30 17:27:19 +00:00
|
|
|
if (mode == FAIL_RESTORE) {
|
2005-03-02 18:35:49 +00:00
|
|
|
return -1;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
close_file();
|
2002-10-30 17:27:19 +00:00
|
|
|
if (! *AHeap)
|
|
|
|
*AHeap = MyHeap / 1024;
|
|
|
|
if (mode != DO_ONLY_CODE && *AStack)
|
|
|
|
*AStack = MyStack / 1024;
|
|
|
|
if (mode != DO_ONLY_CODE && *ATrail)
|
|
|
|
*ATrail = MyTrail / 1024;
|
|
|
|
return (MyState);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-07 16:02:55 +00:00
|
|
|
UnmarkTrEntries( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
CELL entry, *Entries;
|
|
|
|
|
2015-11-05 16:59:56 +00:00
|
|
|
/* initialize a choice point */
|
2001-04-09 20:54:03 +01:00
|
|
|
B = (choiceptr)LCL0;
|
|
|
|
B--;
|
2002-05-14 19:22:42 +01:00
|
|
|
B->cp_ap = NOCODE;
|
2011-05-23 16:19:47 +01:00
|
|
|
Entries = (CELL *)LOCAL_TrailBase;
|
2001-12-17 18:31:11 +00:00
|
|
|
while ((entry = *Entries++) != (CELL)NULL) {
|
2008-04-01 09:42:46 +01:00
|
|
|
if (!IsVarTerm(entry)) {
|
|
|
|
if(IsPairTerm(entry)) {
|
|
|
|
CELL *ent = CellPtoHeapAdjust(RepPair(entry));
|
|
|
|
register CELL flags;
|
|
|
|
|
|
|
|
flags = *ent;
|
|
|
|
ResetFlag(InUseMask, flags);
|
|
|
|
*ent = flags;
|
|
|
|
if (FlagOn((DirtyMask|ErasedMask), flags)) {
|
|
|
|
if (FlagOn(DBClMask, flags)) {
|
|
|
|
Yap_ErDBE(DBStructFlagsToDBStruct(ent));
|
|
|
|
} else {
|
|
|
|
if (flags & LogUpdMask) {
|
|
|
|
if (flags & IndexMask) {
|
|
|
|
if (FlagOn(ErasedMask, flags))
|
|
|
|
Yap_ErLogUpdIndex(ClauseFlagsToLogUpdIndex(ent));
|
|
|
|
else
|
|
|
|
Yap_CleanUpIndex(ClauseFlagsToLogUpdIndex(ent));
|
|
|
|
} else {
|
|
|
|
Yap_ErLogUpdCl(ClauseFlagsToLogUpdClause(ent));
|
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2008-04-01 09:42:46 +01:00
|
|
|
Yap_ErCl(ClauseFlagsToDynamicClause(ent));
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2003-04-30 18:46:05 +01:00
|
|
|
}
|
2001-12-17 18:31:11 +00:00
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
2008-04-01 09:42:46 +01:00
|
|
|
} else /* if (IsApplTerm(d1)) */ {
|
|
|
|
Entries += 2;
|
2004-09-27 21:45:04 +01:00
|
|
|
#endif
|
2008-04-01 09:42:46 +01:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
B = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int in_limbo = FALSE;
|
|
|
|
|
2011-01-03 03:16:29 +00:00
|
|
|
/* cleanup any records we had in the saved state. They are now inaccessible */
|
|
|
|
static void
|
|
|
|
FreeRecords(void) {
|
|
|
|
struct record_list *ptr;
|
|
|
|
|
|
|
|
ptr = Yap_Records;
|
|
|
|
Yap_Records = NULL;
|
|
|
|
while (ptr) {
|
|
|
|
struct record_list *optr = ptr;
|
|
|
|
Yap_ReleaseTermFromDB(ptr->dbrecord);
|
|
|
|
ptr = ptr->next_rec;
|
|
|
|
Yap_FreeCodeSpace((void *)optr);
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called when wanting only to restore the heap and
|
2015-04-15 11:21:15 +01:00
|
|
|
* associated registers
|
2001-04-09 20:54:03 +01:00
|
|
|
*/
|
2015-04-15 11:21:15 +01:00
|
|
|
static int
|
2011-03-07 16:02:55 +00:00
|
|
|
Restore(char *s, char *lib_dir USES_REGS)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int restore_mode;
|
|
|
|
|
|
|
|
OPCODE old_ops[_std_top+1];
|
2002-10-30 17:27:19 +00:00
|
|
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
2008-03-22 23:35:00 +00:00
|
|
|
|
2011-08-31 21:59:30 +01:00
|
|
|
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack, &MyHeap, NULL)) == FAIL_RESTORE)
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ShutdownLoadForeign();
|
2001-04-09 20:54:03 +01:00
|
|
|
in_limbo = TRUE;
|
2011-03-07 16:02:55 +00:00
|
|
|
if (get_coded(restore_mode, old_ops PASS_REGS) < 0)
|
2015-04-15 11:21:15 +01:00
|
|
|
return FAIL_RESTORE;
|
2011-03-07 16:02:55 +00:00
|
|
|
restore_regs(restore_mode PASS_REGS);
|
2001-04-09 20:54:03 +01:00
|
|
|
in_limbo = FALSE;
|
|
|
|
/*#endif*/
|
2011-03-07 16:02:55 +00:00
|
|
|
RestoreHeap(old_ops PASS_REGS);
|
2001-04-09 20:54:03 +01:00
|
|
|
switch(restore_mode) {
|
|
|
|
case DO_EVERYTHING:
|
2011-05-04 10:11:41 +01:00
|
|
|
if (LOCAL_OldHeapBase != Yap_HeapBase ||
|
|
|
|
LOCAL_OldLCL0 != LCL0 ||
|
2011-05-23 16:19:47 +01:00
|
|
|
LOCAL_OldGlobalBase != (CELL *)LOCAL_GlobalBase ||
|
|
|
|
LOCAL_OldTrailBase != LOCAL_TrailBase) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_AdjustStacksAndTrail();
|
2001-04-09 20:54:03 +01:00
|
|
|
if (which_save == 2) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_AdjustRegs(2);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_AdjustRegs(1);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef DEBUG_RESTORE2
|
2002-11-11 17:38:10 +00:00
|
|
|
fprintf(errout, "phase 2 done\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DO_ONLY_CODE:
|
2011-03-07 16:02:55 +00:00
|
|
|
UnmarkTrEntries( PASS_REGS1 );
|
2012-12-11 22:07:10 +00:00
|
|
|
Yap_InitYaamRegs( 0 );
|
2001-04-09 20:54:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2004-05-13 21:54:58 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReOpenLoadForeign();
|
2011-04-04 14:36:06 +01:00
|
|
|
FreeRecords();
|
|
|
|
/* restart IO */
|
2015-06-19 01:30:13 +01:00
|
|
|
// initIO();
|
2001-04-09 20:54:03 +01:00
|
|
|
/* reset time */
|
2015-11-05 16:59:56 +00:00
|
|
|
Yap_ReInitWTime();
|
2009-05-23 00:35:24 +01:00
|
|
|
#if USE_DL_MALLOC || USE_SYSTEM_MALLOC
|
|
|
|
if (!AuxSp) {
|
2012-12-13 18:12:50 +00:00
|
|
|
Yap_InitPreAllocCodeSpace( 0 );
|
2009-05-23 00:35:24 +01:00
|
|
|
}
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
CloseRestore();
|
|
|
|
if (which_save == 2) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_unify(ARG2, MkIntTerm(0));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2005-03-02 18:35:49 +00:00
|
|
|
return restore_mode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
int
|
2011-08-31 21:59:30 +01:00
|
|
|
Yap_SavedStateRestore(char *s, char *lib_dir)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2015-04-15 11:21:15 +01:00
|
|
|
return Restore(s, lib_dir PASS_REGS);
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
static Int
|
2011-03-07 16:02:55 +00:00
|
|
|
p_restore( USES_REGS1 )
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int mode;
|
2010-11-29 18:08:11 +00:00
|
|
|
char s[YAP_FILENAME_MAX+1];
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
Term t1 = Deref(ARG1);
|
2011-04-29 14:59:17 +01:00
|
|
|
#ifdef YAPOR
|
2011-05-10 11:47:18 +01:00
|
|
|
if (GLOBAL_number_workers != 1) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,"cannot perform save: more than a worker/thread running");
|
2010-10-15 01:15:45 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-04-29 14:59:17 +01:00
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef THREADS
|
2011-05-10 10:06:51 +01:00
|
|
|
if (GLOBAL_NOfThreads != 1) {
|
2015-09-25 10:57:26 +01:00
|
|
|
Yap_Error(SYSTEM_ERROR_INTERNAL,TermNil,"cannot perform save: more than a worker/thread running");
|
2002-10-21 23:52:36 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-04-29 14:59:17 +01:00
|
|
|
#endif /* THREADS */
|
2010-11-29 18:08:11 +00:00
|
|
|
if (!Yap_GetName(s, YAP_FILENAME_MAX, t1)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(TYPE_ERROR_LIST,t1,"restore/1");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2011-03-07 16:02:55 +00:00
|
|
|
if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) {
|
2012-02-05 12:04:29 +00:00
|
|
|
Yap_RestartYap( 3 );
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
return(mode != FAIL_RESTORE);
|
|
|
|
}
|
|
|
|
|
2015-04-15 11:21:15 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSavePreds(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2012-10-19 18:10:48 +01:00
|
|
|
Yap_InitCPred("$save", 2, p_save2, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$save_program", 1, p_save_program, SyncPredFlag);
|
|
|
|
Yap_InitCPred("$restore", 1, p_restore, SyncPredFlag);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|