| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Semaphores (16 & 32) |
Hallo, Darin!
*** Am Dienstag 28. Mai 1996 um 22:12 schrieb Darin McBride an Doug Nazar:
DM>> I'm trying to block Sq386p.exe which uses \SEM\SQUISH\DEFAULT,
DM>> however the Semaphores included in the Warp toolkit
DM>> want me to use \SEM32\ to start. Can I just use \SEM\ anyway?
I have written a small tool to accomplish this some time ago; it is called
sqisem11.zip (also contained in the TTick distribution archive) and can
create arbitrary 16- and 32-bit-semaphores. It is compiled with emx 0.9b.
Since Gnu C only generates 32-bit code, you have to thunk manually (this
consists of awkward macros and messing with selectors and strange pointers
into the stack :-) ).
DM> somehow somewhere. So, I found SMSERIAL.DLL, and a bit of investigation
DN>> void _Far16 _Pascal BbsSemSerialize(char * semaphoreName, char*
DN>> dontKnow);
Is this the prototype for smserial.dll? I experimented with smserial.dll
some time ago. implib and emximp tell me:
;
; smserial.def (created by emximp)
;
LIBRARY smserial
EXPORTS
BBSSEMSERIALIZE {at}1
It does not buy you anything, since it seems to be a 16-bit-DLL, too. So
either you create a thunked call to this function, or call the 16-bit
semaphore functions directly. You might want to check for the environment
variable BBSSEM which is used by Squish and Maximus (undocumented), so you
can switch from \sem\squish\default to something other.
My 16-bit-semaphore thunking library looks like this:
=== Cut ===
#ifndef _SEM16_H
#define _SEM16_H
#ifndef INCL_DOSSEMAPHORES
#define INCL_DOSSEMAPHORES
#endif
#include
#define CSEM_PRIVATE 0
#define CSEM_PUBLIC 1
#endif
USHORT _THUNK_PASCAL_FUNCTION(Dos16CreateSem) (USHORT, PHSEM, PSZ);
USHORT _THUNK_PASCAL_FUNCTION(Dos16OpenSem) (PHSEM, PSZ);
USHORT _THUNK_PASCAL_FUNCTION(Dos16SemRequest)(HSEM, LONG);
USHORT _THUNK_PASCAL_FUNCTION(Dos16SemWait) (HSEM, LONG);
USHORT _THUNK_PASCAL_FUNCTION(Dos16SemClear) (HSEM);
USHORT _THUNK_PASCAL_FUNCTION(Dos16SemSet) (HSEM);
USHORT _THUNK_PASCAL_FUNCTION(Dos16CloseSem) (HSEM);
USHORT DosSemWait (HSEM, LONG);
USHORT DosSemClear (HSEM);
USHORT DosSemSet (HSEM);
USHORT DosSemRequest(HSEM, LONG);
USHORT DosCreateSem (USHORT, PHSEM, PSZ);
USHORT DosOpenSem (PHSEM, PSZ);
USHORT DosCloseSem (HSEM);
=== Cut ===
The C code just consists of functions implementing the thunked calls and
forwarding the return code, like you can see from this example:
=== Cut ===
/* cpuclock.c */
/* Based on code by Kai Uwe Rommel and others. */
#include
#include
#include
#include
#include
#define INCL_DOSPROCESS
#include
USHORT _THUNK_FUNCTION(Dos16QProcStatus)();
USHORT DosQProcStatus(PVOID pvBuf, USHORT cbBuf) {
return((USHORT)
(_THUNK_PROLOG(4+2);
_THUNK_FLAT(pvBuf);
_THUNK_SHORT(cbBuf);
_THUNK_CALL(Dos16QProcStatus)));
}
#define PTR(ptr,ofs) ((void *)((char *)(ptr) + (ofs)))
struct procstat {
ULONG summary;
ULONG processes;
ULONG semaphores;
ULONG unknown1;
ULONG sharedmemory;
ULONG modules;
ULONG unknown2;
ULONG unknown3;
};
struct process {
ULONG type;
ULONG threadlist;
USHORT processid;
USHORT parentid;
USHORT sessiontype;
USHORT unknown1;
ULONG unknown2;
USHORT sessionid;
USHORT unknown3;
USHORT modulehandle;
USHORT threads;
/* lots of other unknown data */
};
struct thread {
ULONG rectype;
USHORT threadid;
USHORT threadsysid;
ULONG blockid;
ULONG priority;
ULONG systime;
ULONG usertime;
UCHAR status;
UCHAR pad1;
USHORT pad2;
};
clock_t clock(void) {
ULONG rc, i;
static void *buf;
static struct procstat *procstat;
static int pid, tid;
struct process *proc;
struct thread *thread;
if (_osmode!=OS2_MODE)
return ((clock_t)__clock());
if (buf==NULL) {
buf=_tmalloc(65535);
procstat=(struct procstat *)buf;
pid=getpid();
}
rc=DosQProcStatus(buf,65535);
if (rc !=0)
return ((clock_t)(-1));
thread=NULL;
for (proc=PTR(procstat->processes,0); proc->type !=3;
proc=PTR(proc->threadlist, proc->threads*sizeof(struct thread)))
if (proc->processid==pid) {
thread=PTR(proc->threadlist,0);
break;
}
if (thread==NULL)
return ((clock_t)(-1));
#ifdef __MT__
tid=*_threadid;
#else
tid=1;
#endif
for (i=0; ithreads; ++i, ++thread)
if (thread->threadid==tid)
break;
if (i>=proc->threads)
return ((clock_t)(-1));
return ((clock_t)((thread->systime+thread->usertime)*CLOCKS_PER_SEC/32));
}
=== Cut ===
Tschau...Thomas
--- E3-32/1.11-32/2.50+
* Origin: Die TeX-Box +49-6034-1455 V.34 -930022 ISDN 24h (2:244/1130.42)SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 @PATH: 244/1130 24/999 888 396/1 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.