summaryrefslogtreecommitdiff
path: root/emu/Nt
diff options
context:
space:
mode:
Diffstat (limited to 'emu/Nt')
-rw-r--r--emu/Nt/cmd.c84
-rw-r--r--emu/Nt/os.c105
-rw-r--r--emu/Nt/win.c130
3 files changed, 98 insertions, 221 deletions
diff --git a/emu/Nt/cmd.c b/emu/Nt/cmd.c
index a03b949b..764d328b 100644
--- a/emu/Nt/cmd.c
+++ b/emu/Nt/cmd.c
@@ -104,11 +104,11 @@ exporthandle(HANDLE h, int close)
/* TO DO: check that oserrstr will have the right text on error */
void*
-oscmd(char **args, int nice, char *dir, int *rpfd, int *wpfd)
+oscmd(char **args, int nice, char *dir, int *fd)
{
STARTUPINFO si;
SECURITY_ATTRIBUTES sec;
- HANDLE rh, wh, srh, swh;
+ HANDLE rh, wh, eh, srh, swh, seh;
PROCESS_INFORMATION pinfo;
char *cmd;
wchar_t *wcmd, *wdir;
@@ -126,35 +126,22 @@ oscmd(char **args, int nice, char *dir, int *rpfd, int *wpfd)
sec.nLength = sizeof(sec);
sec.lpSecurityDescriptor = 0;
sec.bInheritHandle = 0;
- if(!CreatePipe(&rh, &swh, &sec, 0)) {
- print("can't create pipe\n");
- free(cmd);
- free(wcmd);
- free(wdir);
- return nil;
- }
- if(!CreatePipe(&srh, &wh, &sec, 0)) {
- print("can't create pipe\n");
- CloseHandle(rh);
- CloseHandle(swh);
- free(cmd);
- free(wcmd);
- free(wdir);
- return nil;
- }
+ rh = wh = eh = srh = swh = seh = nil;
+ if(!CreatePipe(&rh, &swh, &sec, 0))
+ goto Error;
+ if(!CreatePipe(&srh, &wh, &sec, 0))
+ goto Error;
+ if(!CreatePipe(&seh, &eh, &sec, 0))
+ goto Error;
rh = exporthandle(rh, 1);
+ if(rh == nil)
+ goto Error;
wh = exporthandle(wh, 1);
- if (rh == nil || wh == nil) {
- print("can't dup pipes\n");
- CloseHandle(rh);
- CloseHandle(swh);
- CloseHandle(wh);
- CloseHandle(srh);
- free(cmd);
- free(wcmd);
- free(wdir);
- return nil;
- }
+ if(wh == nil)
+ goto Error;
+ eh = exporthandle(eh, 1);
+ if(eh == nil)
+ goto Error;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
@@ -162,7 +149,7 @@ oscmd(char **args, int nice, char *dir, int *rpfd, int *wpfd)
si.wShowWindow = SW_SHOW;
si.hStdInput = rh;
si.hStdOutput = wh;
- si.hStdError = exporthandle(wh, 0);
+ si.hStdError = eh;
prio = 0;
if(nice){
@@ -175,21 +162,14 @@ oscmd(char **args, int nice, char *dir, int *rpfd, int *wpfd)
if(!CreateProcess(nil/*wpath*/, wcmd, 0, 0, 1,
CREATE_NEW_PROCESS_GROUP|CREATE_DEFAULT_ERROR_MODE|prio,
0 /*env*/, wdir, &si, &pinfo)){
- print("can't create process '%Q' %d\n", wcmd, GetLastError());
- CloseHandle(si.hStdInput);
- CloseHandle(swh);
- CloseHandle(si.hStdOutput);
- CloseHandle(si.hStdError);
- CloseHandle(srh);
- free(cmd);
- free(wcmd);
- free(wdir);
- return nil;
+ //print("can't create process '%Q' %d\n", wcmd, GetLastError());
+ goto Error;
}
- *rpfd = nth2fd(srh);
- *wpfd = nth2fd(swh);
- if(*wpfd == 1 || *wpfd == 2)
+ fd[0] = nth2fd(swh);
+ fd[1] = nth2fd(srh);
+ fd[2] = nth2fd(seh);
+ if(fd[1] == 1 || fd[2] == 2)
panic("invalid mapping of handle to fd");
CloseHandle(si.hStdInput);
CloseHandle(si.hStdOutput);
@@ -209,6 +189,24 @@ oscmd(char **args, int nice, char *dir, int *rpfd, int *wpfd)
free(wcmd);
free(wdir);
return pinfo.hProcess;
+
+Error:
+ if(rh)
+ CloseHandle(rh);
+ if(wh)
+ CloseHandle(wh);
+ if(eh)
+ CloseHandle(eh);
+ if(srh)
+ CloseHandle(srh);
+ if(swh)
+ CloseHandle(swh);
+ if(seh)
+ CloseHandle(seh);
+ free(cmd);
+ free(wcmd);
+ free(wdir);
+ return nil;
}
int
diff --git a/emu/Nt/os.c b/emu/Nt/os.c
index 023d47c3..3f7156d9 100644
--- a/emu/Nt/os.c
+++ b/emu/Nt/os.c
@@ -64,24 +64,24 @@ pfree(Proc *p)
}
free(e->user);
free(p->prog);
+ CloseHandle((HANDLE)p->os);
free(p);
}
-static ulong erendezvous(void*, ulong);
-
void
osblock(void)
{
- erendezvous(up, 0);
+ if(WaitForSingleObject((HANDLE)up->os, INFINITE) != WAIT_OBJECT_0)
+ panic("osblock failed");
}
void
osready(Proc *p)
{
- erendezvous(p, 0);
+ if(SetEvent((HANDLE)p->os) == FALSE)
+ panic("osready failed");
}
-
void
pexit(char *msg, int t)
{
@@ -118,11 +118,9 @@ tramp(LPVOID p)
up = p;
up->func(up->arg);
pexit("", 0);
- // should never get here but tidy up anyway
- _asm {
- mov fs:[0],-1
- add esp, 8
- }
+ /* not reached */
+ for(;;)
+ panic("tramp");
return 0;
}
@@ -140,6 +138,12 @@ kproc(char *name, void (*func)(void*), void *arg, int flags)
print("out of kernel processes\n");
return -1;
}
+ p->os = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if(p->os == NULL){
+ pfree(p);
+ print("can't allocate os event\n");
+ return -1;
+ }
if(flags & KPDUPPG) {
pg = up->env->pgrp;
@@ -429,7 +433,7 @@ libinit(char *imod)
lasterror = GetLastError();
if(PlatformId == VER_PLATFORM_WIN32_NT || lasterror != ERROR_NOT_LOGGED_ON)
print("cannot GetUserName: %d\n", lasterror);
- } else {
+ }else{
uns = narrowen(wuname);
snprint(uname, sizeof(uname), "%s", uns);
free(uns);
@@ -439,85 +443,6 @@ libinit(char *imod)
emuinit(imod);
}
-enum
-{
- NHLOG = 7,
- NHASH = (1<<NHLOG)
-};
-
-typedef struct Tag Tag;
-struct Tag
-{
- void* tag;
- ulong val;
- HANDLE pid;
- Tag* next;
-};
-
-static Tag* ht[NHASH];
-static Tag* ft;
-static Lock hlock;
-static int nsema;
-
-static ulong
-erendezvous(void *tag, ulong value)
-{
- int h;
- ulong rval;
- Tag *t, **l, *f;
-
-
- h = (ulong)tag & (NHASH-1);
-
- lock(&hlock);
- l = &ht[h];
- for(t = ht[h]; t; t = t->next) {
- if(t->tag == tag) {
- rval = t->val;
- t->val = value;
- t->tag = 0;
- unlock(&hlock);
- if(SetEvent(t->pid) == FALSE)
- panic("Release failed\n");
- return rval;
- }
- }
-
- t = ft;
- if(t == 0) {
- t = malloc(sizeof(Tag));
- if(t == nil)
- panic("rendezvous: no memory");
- t->pid = CreateEvent(0, 0, 0, 0);
- }
- else
- ft = t->next;
-
- t->tag = tag;
- t->val = value;
- t->next = *l;
- *l = t;
- unlock(&hlock);
-
- if(WaitForSingleObject(t->pid, INFINITE) != WAIT_OBJECT_0)
- panic("WaitForSingleObject failed\n");
-
- lock(&hlock);
- rval = t->val;
- for(f = *l; f; f = f->next) {
- if(f == t) {
- *l = f->next;
- break;
- }
- l = &f->next;
- }
- t->next = ft;
- ft = t;
- unlock(&hlock);
-
- return rval;
-}
-
void
FPsave(void *fptr)
{
diff --git a/emu/Nt/win.c b/emu/Nt/win.c
index f9a6aa7d..2e984642 100644
--- a/emu/Nt/win.c
+++ b/emu/Nt/win.c
@@ -1,74 +1,42 @@
-#define Unknown win_Unknown
+#define Unknown WUnknown
+#define Colormap WColormap
+#define Cursor WCursor
+#define Display WDisplay
+#define Drawable WDrawable
+#define Font WFont
+#define GC WGC
+#define Point WPoint
+#define Rectangle WRectangle
+#define Screen WScreen
+#define Visual WVisual
+#define Window WWindow
+
#include <windows.h>
+
+#undef Colormap
+#undef Cursor
+#undef Display
+#undef XDrawable
+#undef Font
+#undef GC
+#undef Point
+#undef Rectangle
+#undef Screen
+#undef Visual
+#undef Window
#undef Unknown
+
#include "dat.h"
#include "fns.h"
#include "error.h"
-
+#include <draw.h>
#include "keyboard.h"
#include "cursor.h"
-/*
- * image channel descriptors - copied from draw.h as it clashes with windows.h on many things
- */
-enum {
- CRed = 0,
- CGreen,
- CBlue,
- CGrey,
- CAlpha,
- CMap,
- CIgnore,
- NChan,
-};
-
-#define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
-#define CHAN1(a,b) __DC(a,b)
-#define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
-#define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
-#define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
-
-#define NBITS(c) ((c)&15)
-#define TYPE(c) (((c)>>4)&15)
-
-enum {
- GREY1 = CHAN1(CGrey, 1),
- GREY2 = CHAN1(CGrey, 2),
- GREY4 = CHAN1(CGrey, 4),
- GREY8 = CHAN1(CGrey, 8),
- CMAP8 = CHAN1(CMap, 8),
- RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
- RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
- RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
- RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
- ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
- XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
-};
-
extern ulong displaychan;
-extern void drawend(void);
-
-/*
- * defs for image types to overcome name conflicts
- */
-typedef struct IPoint IPoint;
-typedef struct IRectangle IRectangle;
-
-struct IPoint
-{
- LONG x;
- LONG y;
-};
-
-struct IRectangle
-{
- IPoint min;
- IPoint max;
-};
-
extern char* runestoutf(char*, Rune*, int);
-extern int bytesperline(IRectangle, int);
+extern int bytesperline(Rectangle, int);
extern int main(int argc, char **argv);
static void dprint(char*, ...);
static DWORD WINAPI winproc(LPVOID);
@@ -105,7 +73,7 @@ WinMain(HINSTANCE winst, HINSTANCE wprevinst, LPSTR cmdline, int wcmdshow)
return 0;
}
-void
+static void
dprint(char *fmt, ...)
{
va_list arg;
@@ -118,17 +86,6 @@ dprint(char *fmt, ...)
OutputDebugString(buf);
}
-int
-col(int v, int n)
-{
- int i, c;
-
- c = 0;
- for(i = 0; i < 8; i += n)
- c |= v << (16-(n+i));
- return c >> 8;
-}
-
static void
graphicscmap(PALETTEENTRY *pal)
{
@@ -190,11 +147,13 @@ autochan(void)
return CMAP8;
if (bpp < 24)
return RGB15;
- return RGB24;
+ if (bpp < 32)
+ return RGB24;
+ return XRGB32;
}
uchar*
-attachscreen(IRectangle *r, ulong *chan, int *d, int *width, int *softscreen)
+attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen)
{
int i, k;
ulong c;
@@ -314,7 +273,7 @@ attachscreen(IRectangle *r, ulong *chan, int *d, int *width, int *softscreen)
}
void
-flushmemscreen(IRectangle r)
+flushmemscreen(Rectangle r)
{
RECT wr;
@@ -385,11 +344,12 @@ WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
b |= 1;
if(wparam & MK_MBUTTON)
b |= 2;
- if(wparam & MK_RBUTTON)
+ if(wparam & MK_RBUTTON) {
if(wparam & MK_CONTROL)
b |= 2; //simulate middle button
else
b |= 4; //right button
+ }
mousetrack(b, x, y, 0);
break;
case WM_SYSKEYDOWN:
@@ -590,8 +550,7 @@ winproc(LPVOID x)
if(AdjustWindowRect(&size, ws, 0)) {
maxxsize = size.right - size.left;
maxysize = size.bottom - size.top;
- }
- else {
+ }else{
maxxsize = Xsize + 40;
maxysize = Ysize + 40;
}
@@ -611,8 +570,7 @@ winproc(LPVOID x)
inst, /* program handle */
NULL /* create parms */
);
- }
- else {
+ }else{
window = CreateWindowExA(
0, /* extended style */
"inferno", /* class */
@@ -644,15 +602,13 @@ winproc(LPVOID x)
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
- }
- else {
+ }else{
while(GetMessageA(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
attached = 0;
- /* drawend(); */
ExitThread(msg.wParam);
return 0;
}
@@ -663,7 +619,7 @@ setpointer(int x, int y)
POINT pt;
pt.x = x; pt.y = y;
- ClientToScreen(window, (LPPOINT)&pt);
+ ClientToScreen(window, &pt);
SetCursorPos(pt.x, pt.y);
}
@@ -671,7 +627,7 @@ void
drawcursor(Drawcursor* c)
{
HCURSOR nh, oh;
- IRectangle ir;
+ Rectangle ir;
int i, h, j, bpl, ch, cw;
uchar *bs, *bc, *and, *xor, *cand, *cxor;
@@ -690,7 +646,6 @@ drawcursor(Drawcursor* c)
ir.min.y = c->miny;
ir.max.x = c->maxx;
ir.max.y = c->maxy;
- /* passing IRectangle to Rectangle is safe */
bpl = bytesperline(ir, 1);
h = (c->maxy-c->miny)/2;
@@ -728,8 +683,7 @@ drawcursor(Drawcursor* c)
SendMessage(window, WM_SETCURSOR, (int)window, 0);
if(oh != NULL)
DestroyCursor(oh);
- }
- else {
+ }else{
print("CreateCursor error %d\n", GetLastError());
print("CXCURSOR=%d\n", GetSystemMetrics(SM_CXCURSOR));
print("CYCURSOR=%d\n", GetSystemMetrics(SM_CYCURSOR));