WIN32 fixes

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@639 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-10-17 01:37:46 +00:00
parent 4a71cbda80
commit a1edbf5b9c
4 changed files with 47 additions and 44 deletions

View File

@ -12,7 +12,7 @@
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: allocating space * * comments: allocating space *
* version:$Id: alloc.c,v 1.23 2002-10-10 05:58:48 vsc Exp $ * * version:$Id: alloc.c,v 1.24 2002-10-17 01:37:46 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
@ -48,13 +48,14 @@ static char SccsId[] = "%W% %G%";
#endif #endif
#endif #endif
#if !HAVE_SNPRINTF #if HAVE_SNPRINTF
#define snprintf(A,B,C) sprintf(A,C) #define snprintf3(A,B,C) snprintf(A,B,C)
#define snprintf(A,B,C,D) sprintf(A,C,D) #define snprintf4(A,B,C,D) snprintf(A,B,C,D)
#define snprintf(A,B,C,D,E) sprintf(A,C,D,E) #define snprintf5(A,B,C,D,E) snprintf(A,B,C,D,E)
#define snprintf(A,B,C,D,E,F) sprintf(A,C,D,E,F) #else
#define snprintf(A,B,C,D,E,F,G) sprintf(A,C,D,E,F,G) #define snprintf3(A,B,C) sprintf(A,C)
#define snprintf(A,B,C,D,E,F,G,H) sprintf(A,C,D,E,F,G,H) #define snprintf4(A,B,C,D) sprintf(A,C,D)
#define snprintf5(A,B,C,D,E) sprintf(A,C,D,E)
#endif #endif
STATIC_PROTO(void FreeBlock, (BlockHeader *)); STATIC_PROTO(void FreeBlock, (BlockHeader *));
@ -391,7 +392,8 @@ AllocCodeSpace(unsigned int size)
#include "windows.h" #include "windows.h"
#define BASE_ADDRESS ((LPVOID) MMAP_ADDR) #define BASE_ADDRESS ((LPVOID) MMAP_ADDR)
#define MAX_WORKSPACE 0x80000000L /* #define MAX_WORKSPACE 0x40000000L */
#define MAX_WORKSPACE 0x20000000L
static LPVOID brk; static LPVOID brk;
@ -410,14 +412,9 @@ ExtendWorkSpace(Int s)
return TRUE; return TRUE;
} }
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
#if HAVE_STRERROR snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE,
"VirtualAlloc could not commit %ld bytes", "VirtualAlloc could not commit %ld bytes",
s); (long int)s);
#else
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mkstemp could not create temporary file %s", file);
#endif /* HAVE_STRERROR */
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return FALSE; return FALSE;
} }
@ -432,19 +429,20 @@ InitWorkSpace(Int s)
page_size = si.dwPageSize; page_size = si.dwPageSize;
b = VirtualAlloc(BASE_ADDRESS, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS); b = VirtualAlloc(BASE_ADDRESS, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS);
if (b==NULL) { if (b==NULL) {
YP_fprintf(YP_stderr,"[ Warning: YAP reserving space at a variable address ]\n"); fprintf(stderr,"[ Warning: YAP reserving space at a variable address ]\n");
b = VirtualAlloc(0x0, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS); b = VirtualAlloc(0x0, MAX_WORKSPACE, MEM_RESERVE, PAGE_NOACCESS);
if (b == NULL) { if (b == NULL) {
Error(FATAL_ERROR,"VirtualAlloc failed"); Error(FATAL_ERROR,TermNil,"VirtualAlloc failed");
return(0); return(0);
} }
} }
brk = BASE_ADDRESS; brk = BASE_ADDRESS;
if (ExtendWorkSpace(s)) { if (ExtendWorkSpace(s)) {
return BASE_ADDRESS; return BASE_ADDRESS;
} else { } else {
Error(FATAL_ERROR,"VirtualAlloc Failed"); Error(FATAL_ERROR,TermNil,"VirtualAlloc Failed");
return(0); return(0);
} }
} }
@ -611,11 +609,11 @@ ExtendWorkSpace(Int s)
if (mkstemp(file) == -1) { if (mkstemp(file) == -1) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
#if HAVE_STRERROR #if HAVE_STRERROR
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf5(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mkstemp could not create temporary file %s (%s)", "mkstemp could not create temporary file %s (%s)",
file, strerror(errno)); file, strerror(errno));
#else #else
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mkstemp could not create temporary file %s", file); "mkstemp could not create temporary file %s", file);
#endif /* HAVE_STRERROR */ #endif /* HAVE_STRERROR */
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
@ -633,14 +631,14 @@ ExtendWorkSpace(Int s)
fd = open(file, O_CREAT|O_RDWR); fd = open(file, O_CREAT|O_RDWR);
if (fd < 0) { if (fd < 0) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not open %s", file); "mmap could not open %s", file);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return FALSE; return FALSE;
} }
if (lseek(fd, s, SEEK_SET) < 0) { if (lseek(fd, s, SEEK_SET) < 0) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not lseek in mmapped file %s", file); "mmap could not lseek in mmapped file %s", file);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
close(fd); close(fd);
@ -648,7 +646,7 @@ ExtendWorkSpace(Int s)
} }
if (write(fd, "", 1) < 0) { if (write(fd, "", 1) < 0) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not write in mmapped file %s", file); "mmap could not write in mmapped file %s", file);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
close(fd); close(fd);
@ -656,7 +654,7 @@ ExtendWorkSpace(Int s)
} }
if (unlink(file) < 0) { if (unlink(file) < 0) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not unlink mmapped file %s", file); "mmap could not unlink mmapped file %s", file);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
close(fd); close(fd);
@ -673,10 +671,10 @@ ExtendWorkSpace(Int s)
if (close(fd) == -1) { if (close(fd) == -1) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
#if HAVE_STRERROR #if HAVE_STRERROR
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not close file (%s) ]\n", strerror(errno)); "mmap could not close file (%s) ]\n", strerror(errno));
#else #else
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf3(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not close file ]\n"); "mmap could not close file ]\n");
#endif #endif
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
@ -686,10 +684,10 @@ ExtendWorkSpace(Int s)
if (a == (MALLOC_T) - 1) { if (a == (MALLOC_T) - 1) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
#if HAVE_STRERROR #if HAVE_STRERROR
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf5(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes (%s)", (int)s, strerror(errno)); "could not allocate %d bytes (%s)", (int)s, strerror(errno));
#else #else
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes", (int)s); "could not allocate %d bytes", (int)s);
#endif #endif
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
@ -697,7 +695,7 @@ ExtendWorkSpace(Int s)
} }
if (a != WorkSpaceTop) { if (a != WorkSpaceTop) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf5(ErrorMessage, MAX_ERROR_MSG_SIZE,
"mmap could not grow memory at %p, got %p", WorkSpaceTop, a ); "mmap could not grow memory at %p, got %p", WorkSpaceTop, a );
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return FALSE; return FALSE;
@ -761,21 +759,21 @@ ExtendWorkSpace(Int s)
/* mapping heap area */ /* mapping heap area */
if((shm_id = shmget(IPC_PRIVATE, (size_t)s, SHM_R|SHM_W)) == -1) { if((shm_id = shmget(IPC_PRIVATE, (size_t)s, SHM_R|SHM_W)) == -1) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not shmget %d bytes", s); "could not shmget %d bytes", s);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
} }
if((ptr = (MALLOC_T)shmat(shm_id, WorkSpaceTop, 0)) == (MALLOC_T) -1) { if((ptr = (MALLOC_T)shmat(shm_id, WorkSpaceTop, 0)) == (MALLOC_T) -1) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not shmat at %p", MMAP_ADDR); "could not shmat at %p", MMAP_ADDR);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
} }
if (shmctl(shm_id, IPC_RMID, 0) != 0) { if (shmctl(shm_id, IPC_RMID, 0) != 0) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not remove shm segment", shm_id); "could not remove shm segment", shm_id);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
@ -835,8 +833,8 @@ ExtendWorkSpace(Int s)
PrologMode = ExtendStackMode; PrologMode = ExtendStackMode;
if (ptr == ((MALLOC_T) - 1)) { if (ptr == ((MALLOC_T) - 1)) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
, "could not expand stacks over %d bytes", s); "could not expand stacks over %d bytes", s);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
} }
@ -968,21 +966,21 @@ ExtendWorkSpace(Int s)
ptr = (MALLOC_T)realloc((void *)HeapBase, total_space); ptr = (MALLOC_T)realloc((void *)HeapBase, total_space);
if (ptr == NULL) { if (ptr == NULL) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not allocate %d bytes", s); "could not allocate %d bytes", s);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
} }
if (ptr != (MALLOC_T)HeapBase) { if (ptr != (MALLOC_T)HeapBase) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf4(ErrorMessage, MAX_ERROR_MSG_SIZE,
"could not expand contiguous stacks %d bytes", s); "could not expand contiguous stacks %d bytes", s);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);
} }
if ((CELL)ptr & MBIT) { if ((CELL)ptr & MBIT) {
ErrorMessage = ErrorSay; ErrorMessage = ErrorSay;
snprintf(ErrorMessage, MAX_ERROR_MSG_SIZE, snprintf5(ErrorMessage, MAX_ERROR_MSG_SIZE,
"memory at %p conflicts with MBIT %lx", ptr, MBIT); "memory at %p conflicts with MBIT %lx", ptr, MBIT);
PrologMode = OldPrologMode; PrologMode = OldPrologMode;
return(FALSE); return(FALSE);

View File

@ -30,8 +30,11 @@ static char SccsId[] = "%W% %G%";
#if _MSC_VER || defined(__MINGW32__) #if _MSC_VER || defined(__MINGW32__)
#define _WIN32_WINNT 0x0400 #define _WIN32_WINNT 0x0400
#endif #endif
#include "absmi.h" #include "Yap.h"
#include "Yatom.h"
#include "Heap.h"
#include "yapio.h" #include "yapio.h"
#include "eval.h"
#include "alloc.h" #include "alloc.h"
#include <math.h> #include <math.h>
#if STDC_HEADERS #if STDC_HEADERS
@ -135,7 +138,7 @@ dir_separator (int ch)
return (ch == ':'); return (ch == ':');
#elif ATARI || _MSC_VER #elif ATARI || _MSC_VER
return (ch == '\\'); return (ch == '\\');
#elif defined(__MINGW32__) #elif defined(__MINGW32__) || defined(__CYGWIN__)
return (ch == '\\' || ch == '/'); return (ch == '\\' || ch == '/');
#else #else
return (ch == '/'); return (ch == '/');

View File

@ -54,7 +54,7 @@
#endif #endif
#endif #endif
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32)
#ifdef NO_DYN #ifdef NO_DYN
#undef NO_DYN #undef NO_DYN
#define LOAD_DLL 1 #define LOAD_DLL 1

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.32 2002-10-10 05:58:49 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.33 2002-10-17 01:37:46 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -257,8 +257,10 @@ extern char Option[20];
#endif #endif
#elif __svr4__ || defined(__SVR4) #elif __svr4__ || defined(__SVR4)
#define MMAP_ADDR 0x02000000 #define MMAP_ADDR 0x02000000
#elif defined(_WIN32) || defined(__CYGWIN__) #elif defined(_WIN32)
#define MMAP_ADDR 0x30000000L #define MMAP_ADDR 0x18000000L
#elif defined(__CYGWIN__)
#define MMAP_ADDR 0x20040000L
#endif #endif
#endif /* !IN_SECOND_QUADRANT */ #endif /* !IN_SECOND_QUADRANT */