[MLton-commit] r4523
Wesley Terpstra
MLton@mlton.org
Wed, 10 May 2006 11:09:27 -0700
sufficient to get mingw runtime to compile
----------------------------------------------------------------------
U mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c
U mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h
U mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c
----------------------------------------------------------------------
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c 2006-05-10 16:44:52 UTC (rev 4522)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.c 2006-05-10 18:09:24 UTC (rev 4523)
@@ -16,7 +16,7 @@
Windows_release (base);
}
-Word32 GC_totalRam (GC_state s) {
+Word32 GC_totalRam (void) {
MEMORYSTATUS memStat;
memStat.dwLength = sizeof(memStat);
@@ -89,6 +89,7 @@
int setitimer (int which,
const struct itimerval *value,
struct itimerval *ovalue) {
+ // !!! perhaps used code from alarm?
die ("setitimer not implemented");
}
@@ -98,7 +99,7 @@
static struct rlimit rlimits[RLIM_NLIMITS];
-static void initRlimits () {
+static void initRlimits (void) {
static int done = FALSE;
int lim;
@@ -191,6 +192,13 @@
return _chmod (fname, mode);
}
+int fchdir (int filedes) {
+ char fname[MAX_PATH + 1];
+
+ GetWin32FileName (filedes, fname);
+ return chdir (fname);
+}
+
int chown (const char *path, uid_t owner, gid_t group) {
die ("chown not implemented");
}
@@ -213,14 +221,14 @@
}
int mkdir2 (const char *pathname, mode_t mode) {
- return mkdir (pathname);
+ return mkdir (pathname, mode);
}
int mkfifo (const char *pathname, mode_t mode) {
die ("mkfifo not implemented");
}
-long pathconf (char *path, int name) {
+long pathconf (const char *path, int name) {
die ("pathconf not implemented");
}
@@ -232,6 +240,20 @@
die ("symlink not implemented");
}
+int truncate (const char *path, off_t len) {
+ int fd;
+
+ if ((fd = open(path, O_RDWR)) == -1)
+ return -1;
+ if (ftruncate(fd, len) < 0) {
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+
+
/* ------------------------------------------------- */
/* Posix.IO */
/* ------------------------------------------------- */
@@ -245,29 +267,29 @@
}
int pipe (int filedes[2]) {
- HANDLE read;
- HANDLE write;
+ HANDLE read_h;
+ HANDLE write_h;
/* We pass no security attributes (0), so the current policy gets
* inherited. The pipe is set to NOT stay open in child processes.
* This will be corrected using DuplicateHandle in create()
* The 4k buffersize is choosen b/c that's what linux uses.
*/
- if (!CreatePipe(&read, &write, 0, 4096)) {
+ if (!CreatePipe(&read_h, &write_h, 0, 4096)) {
errno = ENOMEM; /* fake errno: out of resources */
return -1;
}
/* This requires Win98+
* Choosing text/binary mode is defered till a later setbin/text call
*/
- filedes[0] = _open_osfhandle((long)read, _O_RDONLY);
- filedes[1] = _open_osfhandle((long)write, _O_WRONLY);
+ filedes[0] = _open_osfhandle((long)read_h, _O_RDONLY);
+ filedes[1] = _open_osfhandle((long)write_h, _O_WRONLY);
if (filedes[0] == -1 or filedes[1] == -1) {
if (filedes[0] == -1)
- CloseHandle(read);
+ CloseHandle(read_h);
else close(filedes[0]);
if (filedes[1] == -1)
- CloseHandle(write);
+ CloseHandle(write_h);
else close(filedes[1]);
errno = ENFILE;
@@ -428,8 +450,9 @@
static int curr_timer_dur = 0;
static LARGE_INTEGER timer_start_val;
+
VOID CALLBACK alarm_signalled(HWND window, UINT message,
- UINT_PTR timer_id, DWORD time)
+ UINT_PTR timer_id, DWORD timestamp)
{
printf("Timer fired\n");
}
@@ -565,19 +588,24 @@
return (*set & SIGTOMASK(signum)) ? 1 : 0;
}
+
+/* With a bit of work and a redirected signal() function, we could
+ * probably emulate these methods properly. AtM blocking is a lie.
+ */
+static sigset_t signals_blocked = 0;
+static sigset_t signals_pending = 0;
+
int sigpending (sigset_t *set) {
- die ("sigpending not implemented");
+ *set = signals_pending;
+ return 0;
}
int sigprocmask (int how, const sigset_t *set, sigset_t *oldset) {
-
- sigset_t opmask;
-
if (oldset) {
- //*oldset = opmask;
+ *oldset = signals_blocked;
}
if (set) {
- sigset_t newmask = opmask;
+ sigset_t newmask = signals_blocked;
switch (how) {
case SIG_BLOCK:
@@ -595,24 +623,25 @@
default:
return -1;
}
- //(void) set_signal_mask (newmask, opmask);
+
+ signals_blocked = newmask;
}
return 0;
}
int sigsuspend (const sigset_t *mask) {
- die ("sigsuspend not implemented");
+ die("sigsuspend is unimplemented, but could be hacked in if needed");
}
/* ------------------------------------------------- */
/* Posix.IO */
/* ------------------------------------------------- */
-void Posix_IO_setbin (Fd fd) {
+void Posix_IO_setbin (C_Fd_t fd) {
_setmode (fd, _O_BINARY);
}
-void Posix_IO_settext (Fd fd) {
+void Posix_IO_settext (C_Fd_t fd) {
_setmode (fd, _O_TEXT);
}
@@ -707,7 +736,7 @@
/* Process */
/* ------------------------------------------------- */
-Pid MLton_Process_cwait (Pid pid, Pointer status) {
+C_PId_t MLton_Process_cwait (C_PId_t pid, Pointer status) {
HANDLE h;
h = (HANDLE)pid;
@@ -740,7 +769,7 @@
}
/* ------------------------------------------------- */
-/* Socket */
+/* Syslog */
/* ------------------------------------------------- */
static const char* logident = "<unknown>";
@@ -776,8 +805,8 @@
if ((logopt & LOG_PERROR) != 0) {
if ((logopt & LOG_PID) != 0)
- fprintf("%s(%d): %s: %s\n", logident, getpid(), severity[priority], msg);
+ fprintf(stderr, "%s(%d): %s: %s\n", logident, getpid(), severity[priority], msg);
else
- fprintf("%s: %s: %s\n", logident, severity[priority], msg);
+ fprintf(stderr, "%s: %s: %s\n", logident, severity[priority], msg);
}
}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h 2006-05-10 16:44:52 UTC (rev 4522)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/mingw.h 2006-05-10 18:09:24 UTC (rev 4523)
@@ -12,6 +12,7 @@
#include <sys/types.h>
#include <winsock2.h>
#include <ws2tcpip.h>
+#include <psapi.h>
#undef max
#define HAS_FEROUND TRUE
@@ -58,6 +59,8 @@
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
+#define F_GETOWN 5
+#define F_SETOWN 6
#define F_GETLK 7
#define F_SETLK 8
#define F_RDLCK 1
@@ -66,8 +69,6 @@
#define F_SETLKW 9
#define FD_CLOEXEC 1
-#define MSG_DONTWAIT 0
-
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
#define SHUT_RDWR SD_BOTH
@@ -180,23 +181,35 @@
#define S_IXGRP 0000010
#define S_IXOTH 0000001
+// Do not exist in a windows filesystem
+#define S_IFLNK 0
+#define S_IFSOCK 0
+#define S_ISVTX 0
+
#define O_NOCTTY 0x8000
#define O_NONBLOCK 0x4000
+// Synchronized writes? Safety of any kind? ... and windows?! hell no!
+#define O_SYNC 0
+
#define S_ISLNK(m) FALSE
#define S_ISSOCK(m) FALSE
int chown (const char *path, uid_t owner, gid_t group);
int fchmod (int filedes, mode_t mode);
+int fchdir (int filedes);
int fchown (int fd, uid_t owner, gid_t group);
long fpathconf (int filedes, int name);
int link (const char *oldpath, const char *newpath);
int lstat (const char *file_name, struct stat *buf);
int mkfifo (const char *pathname, mode_t mode);
-long pathconf (char *path, int name);
+long pathconf (const char *path, int name);
int readlink (const char *path, char *buf, size_t bufsiz);
int symlink (const char *oldpath, const char *newpath);
+int truncate (const char *path, off_t len);
+#define mkdir(f, m) mkdir(f); chmod(f, m)
+
/* ------------------------------------------------- */
/* Posix.IO */
/* ------------------------------------------------- */
@@ -329,7 +342,7 @@
#define _NSIG 32
-typedef void (*_sig_func_ptr)(void);
+typedef __p_sig_fn_t _sig_func_ptr;
struct sigaction {
int sa_flags;
@@ -503,9 +516,18 @@
/* Socket */
/* ------------------------------------------------- */
+// Unimplemented on windows:
#define MSG_DONTWAIT 0
-#define UNIX_PATH_MAX 108
+#define MSG_WAITALL 0
+#define MSG_EOR 0
+#define MSG_CTRUNC 0
+// Has a different name:
+#define MSG_TRUNC MSG_PARTIAL
+
+
+#define UNIX_PATH_MAX 108
+
typedef unsigned short sa_family_t;
struct sockaddr_un {
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c 2006-05-10 16:44:52 UTC (rev 4522)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/windows.c 2006-05-10 18:09:24 UTC (rev 4523)
@@ -1,10 +1,11 @@
HANDLE fileDesHandle (int fd);
-static void displayMaps () {
+
+static void displayMaps (void) {
MEMORY_BASIC_INFORMATION buf;
- LPCVOID lpAddress;
- char *state = "<unset>";
- char *protect = "<unset>";
+ LPVOID lpAddress;
+ const char *state = "<unset>";
+ const char *protect = "<unset>";
for (lpAddress = 0; lpAddress < (LPCVOID)0x80000000; ) {
VirtualQuery (lpAddress, &buf, sizeof (buf));
@@ -53,14 +54,14 @@
break;
}
fprintf(stderr, "0x%8x %10u %s %s\n",
- (uint)buf.BaseAddress,
- (uint)buf.RegionSize,
+ (unsigned int)buf.BaseAddress,
+ (unsigned int)buf.RegionSize,
state, protect);
- lpAddress += buf.RegionSize;
+ lpAddress = (unsigned char*)lpAddress + buf.RegionSize;
}
}
-void GC_displayMem () {
+void GC_displayMem (void) {
MEMORYSTATUS ms;
ms.dwLength = sizeof (MEMORYSTATUS);
@@ -72,7 +73,7 @@
ms.dwAvailPageFile,
ms.dwTotalVirtual,
ms.dwAvailVirtual);
- showMaps ();
+ displayMaps ();
}
static HANDLE dupHandle (int fd) {
@@ -181,7 +182,7 @@
return result;
}
-Int Windows_Process_terminate (Pid pid, Int sig) {
+C_Errno_t(C_Int_t) Windows_Process_terminate (C_PId_t pid, C_Signal_t sig) {
HANDLE h;
h = (HANDLE)pid;