/*static char *SCCSID = "@(#)semxport.h 6.2 92/01/06";*/
/* char *SCCSID = "@(#)semxport.h       6.2 92/01/06"   */

/*      Semaphores - Exported Data, Constants, and Structures */



/* 32-bit Semaphore Attributes */

#define DC_SEM_SHARED   0x0001   // DosCreateMutex, DosCreateEvent, and
                                 //   DosCreateMuxWait use it to indicate
                                 //   whether the semaphore is shared or
                                 //   private when the PSZ is null

/* Definition flag for PM Shared Event Semphore. Specified on the
 * DosCreateEven API call.
 */
#define DC_SEM_PM       0x0040

#define DCMW_WAIT_ANY   0x0002   // DosCreateMuxWait option for wait on any
                                 //   event/mutex to occur
#define DCMW_WAIT_ALL   0x0004   // DosCreateMuxWait option for wait on all
                                 //   events/mutexs to occur
#define DCM_MUTEX_SEM   0x0008   // DosCreateMutex sets this flag to show
                                 //   that it's a mutex semaphore
#define DCE_EVENT_SEM   0x0010   // DosCreateEvent sets this flag to show
                                 //   that it's an event semaphore
#define DCMW_MUX_SEM    0x0020   // DosCreateMuxWait sets this flag to
                                 //   show that it's a muxwait semaphore


/*
 *  32-bit handle signature constants (for 16/32 bit use)
 */
#define SEM_HANDLESIG   0x00010000    // 32-bit handle signature
#define SEM_PMSEMCALL   0x00020000    // Called from PMSem worker
#define SEM_SIGBITS     0x00030000    // Isolates 32-bit signature bits
#define SEM_16HANDLESIG 0x0001        // For SEM.ASM
#define SEM_16SIGBITS   0x0003        // For SEM.ASM


/* Types */

typedef  PID    *PPID;           // pointer to a pid
typedef  TID    *PTID;           // pointer to a tid

typedef  ULONG   HMTX;           // handle of a mutex
typedef  HMTX   *PHMTX;          // pointer to a mutex handle
typedef  ULONG   HEV;            // handle of an event
typedef  HEV    *PHEV;           // pointer to an event handle
typedef  ULONG   HMUX;           // handle of a muxwait
typedef  HMUX   *PHMUX;          // pointer to a muxwait handle
typedef  ULONG   HSEM;           // semaphore handle
typedef  HSEM   *PHSEM;          // pointer to a semaphore handle
typedef  VOID   *PSEM;           // pointer to a semaphore structure


typedef struct semrecord_s {     // semrecord structure for mux sems
    HSEM        hsemCur;         // semaphore handle
    ULONG       ulUser;          // user value
} SEMRECORD;
typedef SEMRECORD *PSEMRECORD;   // pointer to a SEMRECORD


/*  Extern Declarations  */

/*  32-bit Semaphore Initialization and Exit Routines
 *
 *  These routines take care of the system and process initialization
 *  and cleanup for the 32-bit semaphore APIs.
 */
extern  ULONG   SEMInitShrTbl(void);
extern  ULONG   SEMInitPTDA(struct ptda_s *);
extern  void    SEMMarkOwnerDied(ULONG);
extern  void    SEMCleanProcDying(void);
extern  void    SEMTerminatePTDA(struct ptda_s *);


/*  32-bit Semaphore Allocation/Validation Layer Routines
 *
 *  These routines should only be called from within the kernel.
 *  They are called directly from the verification layer (the
 *  entry point into the kernel for the 32-bit semaphore APIs).
 *  They perform all allocations that are necessary for the worker
 *  layer routines to complete their operations.  In addition, they
 *  ensure that the semaphore handle passed in is valid before
 *  it reaches the worker layer.  If the caller knows that
 *  (1) the semaphore handle is a valid 32-bit semaphore handle, AND
 *  (2) no allocations are required, the caller may call the worker
 *  layer directly.
 */
extern  ULONG    SEMApiCreateEventSem(PSZ,PHEV,ULONG,BOOL);
extern  ULONG    SEMApiOpenEventSem(PSZ,PHEV,struct ptda_s *);
extern  ULONG    SEMApiCloseEventSem(HEV,struct ptda_s *);
//extern  ULONG    SEMApiResetEventSem(HEV,PULONG,struct ptda_s *);
//extern  ULONG    SEMApiPostEventSem(HEV,struct ptda_s *);
//extern  ULONG    SEMApiWaitEventSem(HEV,ULONG);
//extern  ULONG    SEMApiQueryEventSem(HEV,PULONG);

extern  ULONG    SEMApiCreateMutexSem(PSZ,PHMTX,ULONG,BOOL);
extern  ULONG    SEMApiOpenMutexSem(PSZ,PHMTX);
//extern  ULONG    SEMApiCloseMutexSem(HMTX);
//extern  ULONG    SEMApiRequestMutexSem(HMTX,ULONG);
//extern  ULONG    SEMApiReleaseMutexSem(HMTX);
extern  ULONG    SEMApiQueryMutexSem(HMTX,PPID,PTID,PULONG);

extern  ULONG    SEMApiCreateMuxWaitSem(PSZ,PHMUX,ULONG,PSEMRECORD,ULONG);
extern  ULONG    SEMApiOpenMuxWaitSem(PSZ,PHMUX);
//extern  ULONG    SEMApiCloseMuxWaitSem(HMUX);
extern  ULONG    SEMApiWaitMuxWaitSem(HMUX,ULONG,PULONG);
extern  ULONG    SEMApiAddMuxWaitSem(HMUX,PSEMRECORD);
extern  ULONG    SEMApiDeleteMuxWaitSem(HMUX,HSEM);
extern  ULONG    SEMApiQueryMuxWaitSem(HMUX,PULONG,PSEMRECORD,PULONG);



/*  32-bit Semaphore Device Helper Routines
 *
 *  These routines may only be called from within the kernel.
 *  They are the C-callable routines for the device helpers.
 *  These routines may be called by either the device helpers or
 *  kernel code.  They call directly into the allocation/validation
 *  layer.
 */
extern  ULONG    dhw_OpenEventSem(HEV);
extern  ULONG    dhw_CloseEventSem(HEV);
extern  ULONG    dhw_PostEventSem(HEV);
extern  ULONG    dhw_ResetEventSem(HEV,PULONG);



/*  32-bit Semaphore Worker Layer Routines
 *
 *  These routines should only be called when NO VALIDATION of the
 *  handle is required by the caller.  If handle validation is required
 *  in the kernel for the following semaphore functions, the
 *  appropriate allocation/validation layer routine should be called
 *  instead of these worker routines.
 */
extern  ULONG    SEMCloseEventSem(HEV,struct ptda_s *);
extern  ULONG    SEMResetEventSem(HEV,PULONG,struct ptda_s *);
extern  ULONG    SEMPostEventSem(HEV,struct ptda_s *);
extern  ULONG    SEMWaitEventSem(HEV,ULONG);
extern  ULONG    SEMQueryEventSem(HEV,PULONG);

extern  ULONG    SEMCloseMutexSem(HMTX);
extern  ULONG    SEMRequestMutexSem(HMTX,ULONG);
extern  ULONG    SEMReleaseMutexSem(HMTX);
extern  ULONG    SEMQueryMutexSem(HMTX,PPID,PTID,PULONG);

extern  ULONG    SEMCloseMuxWaitSem(HMUX);
extern  ULONG    SEMDeleteMuxWaitSem(HMUX,HSEM);
extern  ULONG    SEMQueryMuxWaitSem(HMUX,PULONG,PSEMRECORD,PULONG);


/*  32-bit Semaphore Tools Routines
 *
 *  These routines can be called from anywhere within the kernel.
 *  They can be found in semtools.c in the task subdirectory.
 */
extern  ULONG    SEMMuxWait16(HEV);
extern  ULONG    SEMFindType(HSEM);

