File: session.c

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (69 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*	$Id: session.c,v 1.4 2003/09/01 15:04:26 skaus Exp $
	$Locker:  $	$Name:  $	$State: Exp $

	Save/restore the current session

	this copies the Context into near memory (if space allows)
	and restores it later

	$Log: session.c,v $
	Revision 1.4  2003/09/01 15:04:26  skaus
	bugfix: LOADHIGH: deallocating context if /L is present {Tom Ehlert}
	
	Revision 1.3  2002/11/12 21:56:17  skaus
	v0.83 Beta 52:
	
	Revision 1.2  2002/11/12 19:48:48  skaus
	bugfix: COPY: additional output to honor redirection {Eric Auer} [bugID #1313]
	
	Revision 1.1  2002/11/12 18:31:57  skaus
	add: save/restore session (swap context) {Tom Ehlert}
	
*/

#include "../config.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include <suppl.h>
#include <mcb.h>
#include <environ.h>

#include "..\err_fcts.h"
#include "..\include\command.h"
#include "..\include\context.h"
#include "..\include\crossjmp.h"
#include "..\include\misc.h"

static unsigned ctxtSavedSize;
static void *ctxtSavePtr;

void saveSession(void)
{
	if(ctxt && swapContext) {
		ctxtSavedSize = mcb_length(ctxt);
		dprintf(("[MEM: save context: %u bytes from 0x%04x]\n"
		 , ctxtSavedSize, ctxt)); 
		ctxtSavePtr = malloc(ctxtSavedSize);
		if(ctxtSavePtr) {
			_fmemcpy(ctxtSavePtr, MK_FP(ctxt,0), ctxtSavedSize);		
			DOSfree(ctxt);
#ifdef DEBUG
			ctxt = 0;
#endif
		}
	}
}
void restoreSession(void)
{
	assert(ctxt == 0);
	if(ctxtSavePtr) {
		dprintf(("[MEM: restore context: %u bytes]\n", ctxtSavedSize));
		ctxtCreateMemBlock(ctxtSavedSize);
		_fmemcpy( MK_FP(ctxt,0), ctxtSavePtr, ctxtSavedSize);		
		free(ctxtSavePtr);
		ctxtSavePtr = 0;
	}
}