Skip to content

Commit

Permalink
Implemented more APIs; a little further into Watcom C's wcc386.exe no…
Browse files Browse the repository at this point in the history
…w...
  • Loading branch information
icculus committed Oct 17, 2016
1 parent dc00a7e commit e011e5c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lx_loader.c
Expand Up @@ -528,7 +528,7 @@ static void freeLxModule(LxModule *lxmod)

// !!! FIXME: mutex from here
lxmod->refcount--;
printf("unref'd module '%s' to %u\n", lxmod->name, (uint) lxmod->refcount);
fprintf(stderr, "unref'd module '%s' to %u\n", lxmod->name, (uint) lxmod->refcount);
if (lxmod->refcount > 0)
return; // something is still using it.

Expand Down Expand Up @@ -1242,7 +1242,7 @@ static LxModule *loadLxModuleByModuleNameInternal(const char *modname, const int
return retval;
} // loadLxModuleByModuleNameInternal

static inline LxModule *loadLxModuleByModuleName(const char *modname)
static LxModule *loadLxModuleByModuleName(const char *modname)
{
return loadLxModuleByModuleNameInternal(modname, 0);
} // loadLxModuleByModuleName
Expand All @@ -1258,6 +1258,7 @@ int main(int argc, char **argv, char **envp)
GLoaderState->subprocess = (envr != NULL);
GLoaderState->initOs2Tib = initOs2Tib;
GLoaderState->deinitOs2Tib = deinitOs2Tib;
GLoaderState->loadModule = loadLxModuleByModuleName;

LxModule *lxmod = loadLxModuleByPath(envr ? envr : argv[1]);
if (!lxmod) {
Expand Down
1 change: 1 addition & 0 deletions lx_loader.h
Expand Up @@ -194,6 +194,7 @@ typedef struct LxLoaderState
int subprocess;
uint16 (*initOs2Tib)(uint8 *tibspace, void *_topOfStack, const size_t stacklen, const uint32 tid);
void (*deinitOs2Tib)(const uint16 selector);
LxModule *(*loadModule)(const char *modname);
} LxLoaderState;

typedef const LxExport *(*LxNativeModuleInitEntryPoint)(LxLoaderState *lx_state, uint32 *lx_num_exports);
Expand Down
63 changes: 63 additions & 0 deletions native/doscalls.c
Expand Up @@ -171,6 +171,7 @@ LX_NATIVE_MODULE_INIT({ if (!initDoscalls(lx_state)) return NULL; })
LX_NATIVE_EXPORT(DosGetDateTime, 230),
LX_NATIVE_EXPORT(DosDevConfig, 231),
LX_NATIVE_EXPORT(DosExit, 234),
LX_NATIVE_EXPORT(DosResetBuffer, 254),
LX_NATIVE_EXPORT(DosSetFilePtr, 256),
LX_NATIVE_EXPORT(DosClose, 257),
LX_NATIVE_EXPORT(DosDelete, 259),
Expand All @@ -192,6 +193,7 @@ LX_NATIVE_MODULE_INIT({ if (!initDoscalls(lx_state)) return NULL; })
LX_NATIVE_EXPORT(DosSetMem, 305),
LX_NATIVE_EXPORT(DosCreateThread, 311),
LX_NATIVE_EXPORT(DosGetInfoBlocks, 312),
LX_NATIVE_EXPORT(DosLoadModule, 318),
LX_NATIVE_EXPORT(DosQueryModuleHandle, 319),
LX_NATIVE_EXPORT(DosQueryModuleName, 320),
LX_NATIVE_EXPORT(DosQueryProcAddr, 321),
Expand Down Expand Up @@ -2541,5 +2543,66 @@ APIRET DosDevConfig(PVOID pdevinfo, ULONG item)
return NO_ERROR;
} // DosDevConfig

APIRET DosLoadModule(PSZ pszName, ULONG cbName, PSZ pszModname, PHMODULE phmod)
{
TRACE_NATIVE("DosLoadModule(%p, %u, '%s', %p)", pszName, (uint) cbName, pszModname, phmod);

FIXME("improve this");
*pszName = 0;

// !!! FIXME: there's no mutex on this global state at the moment!
LxModule *lxmod = GLoaderState->loadModule(pszModname);
if (!lxmod)
return ERROR_BAD_FORMAT;

*phmod = (HMODULE) lxmod;
return NO_ERROR;
} // DosLoadModule


static APIRET resetOneBuffer(const int fd)
{
if (fsync(fd) == -1) {
switch (errno) {
case EBADF: return ERROR_INVALID_HANDLE;
case EIO: return ERROR_ACCESS_DENIED;
case EROFS: return ERROR_ACCESS_DENIED;
case EINVAL: return ERROR_INVALID_HANDLE;
default: break;
} // switch
return ERROR_INVALID_HANDLE;
} // if

return NO_ERROR;
} // resetOneBuffer


APIRET OS2API DosResetBuffer(HFILE hFile)
{
TRACE_NATIVE("DosResetBuffer(%u)", (uint) hFile);

if (hFile == 0xFFFFFFFF) { // flush all files.
// !!! FIXME: this is holding the lock the whole time...
APIRET err = NO_ERROR;
grabLock(&GMutexDosCalls);
for (uint32 i = 0; i < MaxHFiles; i++) {
const int fd = HFiles[hFile].fd;
if (fd != -1) {
const APIRET thiserr = resetOneBuffer(fd);
if (err == NO_ERROR)
err = thiserr;
} // if
} // for
ungrabLock(&GMutexDosCalls);
return err;
} // if

// flush just one file.
const int fd = getHFileUnixDescriptor(hFile);
if (fd == -1)
return ERROR_INVALID_HANDLE;
return resetOneBuffer(fd);
} // DosResetBuffer

// end of doscalls.c ...

2 changes: 2 additions & 0 deletions native/doscalls.h
Expand Up @@ -411,6 +411,8 @@ APIRET OS2API DosFindNext(HDIR hDir, PVOID pfindbuf, ULONG cbfindbuf, PULONG pcF
APIRET OS2API DosFindClose(HDIR hDir);
APIRET OS2API DosQueryCurrentDisk(PULONG pdisknum, PULONG plogical);
APIRET OS2API DosDevConfig(PVOID pdevinfo, ULONG item);
APIRET OS2API DosLoadModule(PSZ pszName, ULONG cbName, PSZ pszModname, PHMODULE phmod);
APIRET OS2API DosResetBuffer(HFILE hFile);

#ifdef __cplusplus
}
Expand Down

0 comments on commit e011e5c

Please sign in to comment.