;       SCCSID = @(#)quethnk.asm        6.3 92/03/06
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
;
;         Source File Name:              QUETHNK.ASM
;
;         Function:                      32 to 16 bit thunks for quecalls
;                                          and 16 to 32 bit thunks
;
;         Entry Points:                  DOS32CREATEQUEUE
;                                        DOS32OPENQUEUE
;                                        DOS32CLOSEQUEUE
;                                        DOS32READQUEUE
;                                        DOS32WRITEQUEUE
;                                        DOS32PEEKQUEUE
;                                        DOS32PURGEQUEUE
;                                        DOS32QUERYQUEUE
;                                        QUEINIT
;                                        _OPEN16EVENTSEM
;                                        _POST16EVENTSEM
;                                        _RESET16EVENTSEM
;                                        _CLOSE16EVENTSEM
;
;         External References:           w_DOSCREATEQUEUE
;                                        w_DOSOPENQUEUE
;                                        DOSCLOSEQUEUE
;                                        w_DOSREADQUEUE
;                                        w_DOSWRITEQUEUE
;                                        w_DOSPEEKQUEUE
;                                        DOSPURGEQUEUE
;                                        DOSQUERYQUEUE
;                                        _DYNAINIT
;                                        DOS32OPENEVENTSEM
;                                        DOS32POSTEVENTSEM
;                                        DOS32RESETEVENTSEM
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32CreateQueue
;
;         Descriptive Name:              Create a Queue
;
;         Function:
;                    Dos32CreateQueue creates a queue owned by  the  32 bit
;                    requesting process.
;
;         Notes:
;                    Dos32CreateQueue is used to  create  a queue.  A queue
;                    must be created before  it can be opened.  The process
;                    which creates a queue is the owner of the queue.  Only
;                    the  owner  can access or  remove  the  elements in  a
;                    queue.
;
;                    Once created, each process  wishing  to  write  to the
;                    queue  must  open  the  queue by the  DosOpenQueue  or
;                    Dos32OpenQueue system  call.  Any  process  may open a
;                    queue and place data into it.
;
;                    A queue exists when it is created;  it ceases to exist
;                    when  the  process  which  created  it  terminates  or
;                    explicitly closes it.
;
;         Entry Point:                   Dos32CreateQueue
;             Linkage:            dyna-link at pl 3
;
;         Input:
;              @RWHandle         (dword)
;              QueueFlags        (dword)
;                bits 0 & 1 (priority)
;                   00 = FIFO Queue
;                   01 = LIFO Queue
;                   10 = Priority Queue (sender specifies 0 low - 15 high)
;                bit 2 (thunking)
;                   0 = do not thunk 16-bit addresses
;                   1 = thunk 16-bit addresses
;              @QueueName        (asciiz)
;
;         Exit-Normal:
;              AX = 0
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Duplicate Name
;                   xx = Invalid Name
;                   xx = Invalid Parameter
;                   xx = Insufficient Memory
;                   xx = Sys Error
;
;         Effects:
;              If not already done, initialize Queue Segment
;              Add Queue Strucure
;
;*************************** PSEUDOCODE ***************************
;
; DosCreateQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call w_DosCreateQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32OpenQueue
;
;         Descriptive Name:              Open a Queue
;
;         Function:
;                    Dos32OpenQueue opens  a  queue for the current  32 bit
;                    process.
;
;         Notes:
;                    Dos32OpenQueue  is used to make a queue  accessible to
;                    the current process.  A  queue must be  opened  before
;                    elements can be sent to it.
;
;         Entry Point:         Dos32OpenQueue
;             Linkage:    dyna-link at pl 3
;
;         Input
;              @OwnerPid  (dword)
;              @QHandle   (dword)
;              @QueueName (asciiz)
;
;         Exit-Normal:
;              AX = 0
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Insufficient memory
;                   xx = Queue Name does not exist
;                   xx = Sys Error
;
;         Effects:
;              Update Queue Strucure
;              Create/Update Link Structure
;
;*************************** PSEUDOCODE ***************************
;
; Dos32OpenQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call w_DosOpenQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32CloseQueue
;
;         Descriptive Name:              Close a Queue
;
;         Function:
;                    Dos32CloseQueue closes a queue which  is in use by the
;                    requesting process.
;
;         Notes:
;                    Dos32CloseQueue   is   used   to   terminate   further
;                    processing of  a queue by the requesting process.  The
;                    actions taken depend on  whether  the requestor is the
;                    is the owner or a writer of the queue:
;
;                    For the owner, any outstanding elements will be purged
;                    and the queue will be deleted.  Any further actions on
;                    this queue will result in error invalid queue handle.
;
;                    For  a writer to  the queue, its access  to the  queue
;                    will be terminated but the queue will not be affected.
;
;         Entry Point:         Dos32CloseQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;              QueueHandle (dword)
;
;         Exit-Normal:
;              AX = 0
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Invalid Queue Handle
;                   xx = Sys Error
;
;         Effects:
;              Delete all associated Element Structures
;              Update/Delete all associated Link Structures
;              Update/Delete Queue Structure
;                 or
;              Update/Delete Link Structure
;              Update/Delete Queue Structure
;
;*************************** PSEUDOCODE ***************************
;
; Dos32CloseQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call DosCloseQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32ReadQueue
;
;         Descriptive Name:              Read an element from a Queue.
;
;         Function:
;                    Dos32ReadQueue reads an element from a queue.
;
;         Notes:
;                    This system call is used  to retrieve  an element from
;                    the specified queue and to remove the element from the
;                    queue.
;
;                    If the queue is empty and  the  wait  option  has been
;                    specified, the thread will  be placed in a wait  state
;                    waiting  for  an element to be added to the queue.  If
;                    the Nowait option  is selected, the thread will not be
;                    placed in a wait  state,  but will return with  a code
;                    indicating there are no entries on the queue.
;
;                    The  address  provided  in  the  DataBuffer  parameter
;                    excludes  the   previous   Dos32ReadQueue   DataBuffer
;                    returned on a Dos32PeekQueue system call.  This allows
;                    a process  to  read  an element from a  queue  and use
;                    Dos32PeekQueue to compare other  elements in the queue
;                    to the one read.
;
;                    Only  the queue owner (the process which  created  the
;                    queue  via  Dos32CreateQueue) is allowed to issue this
;                    call.  Any thread within that process may  also  issue
;                    Dos32ReadQueue  calls  to  any  queue  owned  by  that
;                    process.
;
;                    The address  of an element written  with DosWriteQueue
;                    (16   bit)  will   be  converted  to   32   bits.  The
;                    applications must handle  any  conflicts between  word
;                    and dword alignment of the data.
;
;         Entry Point:         Dos32ReadQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;              QueueHandle   (dword)
;              @Request      (2 dwords)
;              @DataLength   (dword)
;              @DataAddress  (dword)
;              ElementCode   (dword)
;                   0 = read first element in queue
;                   not  0  (value returned by  a  peek)  =  read  specific
;                   element
;              NoWait        (dword)
;                   0 = thread will wait
;                   1 = thread will not wait
;              @ElemPriority {0...15} (dword)
;                   0 = lowest priority
;                   15 = highest priority
;              @SemHandle (dword)
;
;         Exit-Normal:
;              AX = 0
;              Request+0 = Sender's PID
;              Request+2 = Application specific code
;              DataAddress = Packet Address
;              DataLength = Packet Length
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Current Process does not own Queue
;                   xx = Element does not exist
;                   xx = Invalid Queue Handle
;                   xx = Invalid Wait
;                   xx = Queue is empty
;                   xx = Sys Error
;
;         Effects:
;              Delete Element Structure
;              Update associated Element Structures
;              Update associated Queue Structure
;
;*************************** PSEUDOCODE ***************************
;
; Dos32ReadQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call w_DosReadQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32WriteQueue
;
;         Descriptive Name:              Write  an  element   to  a   Queue
;         created by Dos32CreateQueue.
;
;         Function:
;                    Dos32WriteQueue adds an element to a queue.
;
;         Notes:
;                    This  system  call  is  used  to  add  entries to  the
;                    specified queue.
;
;                    The queue must have been created by Dos32CreateQueue.
;
;         Entry Point:         Dos32WriteQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;              QueueHandle  (dword)
;              Request      (dword)
;              DataLength   (dword)
;              @DataBuffer  (other)
;              ElemPriority {0...15} (dword)
;                   0 = lowest priority
;                   15 = highest priority
;
;         Exit-Normal:
;              AX = 0
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Insufficient memory
;                   xx = Invalid Queue Handle
;                   xx = Not Permitted
;                   xx = Sys Error
;
;         Effects:
;              Add Element Structure
;              Update associated Element Structures
;              Update associated Queue Structure
;
;*************************** PSEUDOCODE ***************************
;
; Dos32WriteQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call w_DosWriteQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32PeekQueue
;
;         Descriptive Name:              Perform a non-destructive read.
;
;         Function:
;                    Dos32PeekQueue  retrieves  an element from a queue but
;                    does not remove it from the queue.
;
;         Notes:
;                    This  system  call is used to retrieve an element from
;                    the  specified  queue but  leave  the element  in  the
;                    queue.
;
;                    If  the queue is  empty and the wait  option has  been
;                    specified, the thread  will be placed in  a wait state
;                    waiting for  an element to be added to the  queue.  If
;                    the Nowait option  is selected, the thread will not be
;                    placed in a  wait state, but  will return with  a code
;                    indicating there are no entries on the queue.
;
;                    ElementCode  is an indicator of the element to peek or
;                    read next.
;
;                              *         Following    a    peek    request,
;                                        ElementCode    will   contain   an
;                                        identifier  of  the element  which
;                                        has   been   peeked;    the   next
;                                        Dos32PeekQueue  or  Dos32ReadQueue
;                                        request   which   provides    that
;                                        identifier  as   the   ElementCode
;                                        parameter  will  begin  with  that
;                                        element.
;
;                              *         When the application  program sets
;                                        this  field   to   '0',  the  next
;                                        Dos32PeekQueue  or  Dos32ReadQueue
;                                        request  will   access  the  first
;                                        element in the queue.
;
;                    Only  the  queue owner (the  process which created the
;                    queue  via  Dos32CreateQueue) is allowed to issue this
;                    call.  Any  thread within that process may also  issue
;                    DosPeekQueue calls to any queue owned by that process.
;
;         Entry Point:         Dos32PeekQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;              QueueHandle   (dword)
;              @Request      (2 dwords)
;              @DataLength   (dword)
;              @DataAddress  (dword)
;              @ElementCode  (dword)
;                   0 = start at beginning of queue
;                   1 = indicate "peek next"
;              Nowait        (dword)
;                   0 = wait
;                   1 = no wait
;              @ElemPriority {0...15} (dword)
;                   0 = lowest priority
;                   15 = highest priority
;              SemHandle     (dword)
;
;         Exit-Normal:
;              AX = 0
;              Request+0 = Sender's PID
;              Request+4 = Application specific code
;              DataAddress = Packet Address
;              DataLength = Packet Length
;              Element Code = Identifier for particular element
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Current Process does not own Queue
;                   xx = Element does not exist
;                   xx = Invalid Queue Handle
;                   xx = Invalid Wait
;                   xx = Queue is empty
;                   xx = Sys Error
;
;         Effects:
;
;*************************** PSEUDOCODE ***************************
;
; Dos32PeekQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call w_DosPeekQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32PurgeQueue
;
;         Descriptive Name:              Purge a queue of all elements.
;
;         Function:
;                    Dos32PurgeQueue purges a queue of all elements.
;
;         Notes:
;                    Only the queue owner (the  process  which  created the
;                    queue via Dos32CreateQueue)  is allowed to issue  this
;                    call.
;
;         Entry Point:         Dos32PurgeQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;              QueueHandle  (dword)
;
;         Exit-Normal:
;              AX = 0
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Current Process does not own Queue
;                   xx = Invalid Queue Handle
;                   xx = Sys Error
;
;         Effects:
;              Deletes all associated element strucutres
;              Updates the Queue Strucure
;
;*************************** PSEUDOCODE ***************************
;
; Dos32PurgeQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call DosPurgeQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               Dos32QueryQueue
;
;         Descriptive Name:              Query the size of a queue.
;
;         Function:
;                    Dos32QueryQueue finds  the  size  of  (i.e.  number of
;                    elements in) a queue.
;
;         Notes:
;                    Any 32 bit process which  has  a  queue open may issue
;                    this request.
;
;         Entry Point:         Dos32QueryQueue
;             Linkage:    dyna-link at pl 3
;
;         Input:
;               QueueHandle     (dword)
;               @NumberElements (dword)
;
;         Exit-Normal:
;              AX = 0
;              NumberElements = number of elements in the queue
;
;         Exit-Error:
;              AX = Error Code
;                   xx = Invalid Queue Handle
;                   xx = Sys Error
;
;         Effects:
;
;*************************** PSEUDOCODE ***************************
;
; Dos32QueryQueue:
; convert input parameters to 16 bit
; jump to 16 bit code
; call DosQueryQueue
; jump to 32 bit code
; convert output parameters to 32 bit
; return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               _Open16EventSem
;
;         Descriptive Name:              Open 32-bit semaphore
;
;         Function:
;                    Sub-procedure from DosWriteQueue to open
;                        32-bit event semaphore.
;
;         Notes:
;
;         Entry Point:         _Open16EventSem
;             Linkage:    dyna-link at pl 3
;
;         Input:
;                    SemHandle (DWORD)
;
;         Exit-Normal:
;                    AX=0;
;
;         Exit-Error:
;                    AX = Error Code
;                         xx = ERROR_INVALID_HANDLE
;                         xx = ERROR_INVALID_NAME
;                         xx = ERROR_INVALID_PARAMETER
;                         xx = ERROR_NOT_ENOUGH_MEMORY
;                         xx = ERROR_SEM_NOT_FOUND
;                         xx = ERROR_TOO_MANY_OPENS
;
;         Effects:
;                    Open 32-bit event semaphore SemHandle
;
;*************************** PSEUDOCODE ***************************
;
; _Open16EventSem
; Convert parameter to 32 bit
; Switch to 32 bit code
; Call Dos32OpenEventSem
; Switch to 16 bit code
; Remove parameter
; Return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               _Post16EventSem
;
;         Descriptive Name:              Clear 32-bit semaphore
;
;         Function:
;                    Sub-procedure from DosWriteQueue to clear
;                        32-bit event semaphore.
;
;         Notes:
;
;         Entry Point:         _Post16EventSem
;             Linkage:    dyna-link at pl 3
;
;         Input:
;                    SemHandle (DWORD)
;
;         Exit-Normal:
;                    AX=0;
;
;         Exit-Error:
;                    AX = Error Code
;                         xx = ERROR_ALREADY_POSTED
;                         xx = ERROR_INVALID_HANDLE
;                         xx = ERROR_TOO_MANY_POSTS
;
;         Effects:
;                    Clear 32-bit event semaphore SemHandle
;
;*************************** PSEUDOCODE ***************************
;
; _Post16EventSem
; Convert parameter to 32 bit
; Switch to 32 bit code
; Call Dos32PostEventSem
; Switch to 16 bit code
; Remove parameter
; Return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               _Reset16EventSem
;
;         Descriptive Name:              Set 32-bit semaphore
;
;         Function:
;                    Sub-procedure from DosReadQueue and DosPeekQueue
;                        to set 32-bit event semaphore.
;
;         Notes:
;
;         Entry Point:         _Reset16EventSem
;             Linkage:    dyna-link at pl 3
;
;         Input:
;                    SemHandle (DWORD)
;
;         Exit-Normal:
;                    AX=0;
;
;         Exit-Error:
;                    AX = Error Code
;                         xx = ERROR_ALREADY_RESET
;                         xx = ERROR_INVALID_HANDLE
;
;         Effects:
;                    Set 32-bit event semaphore SemHandle
;
;*************************** PSEUDOCODE ***************************
;
; _Reset16EventSem
; Convert parameter to 32 bit
; Switch to 32 bit code
; Call Dos32ResetEventSem
; Switch to 16 bit code
; Remove parameter
; Return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               _Close16EventSem
;
;         Descriptive Name:              Close 32-bit semaphore
;
;         Function:
;                    Sub-procedure from DosReadQueue and DosPeekQueue
;                        to close 32-bit event semaphore.
;
;         Notes:     Defect 65343 D.B.
;
;         Entry Point:         _Close16EventSem
;             Linkage:    dyna-link at pl 3
;
;         Input:
;                    SemHandle (DWORD)
;
;         Exit-Normal:
;                    AX=0;
;
;         Exit-Error:
;                    AX = Error Code
;                         xx = ERROR_INVALID_HANDLE
;
;         Effects:
;                    Close 32-bit event semaphore SemHandle
;
;*************************** PSEUDOCODE ***************************
;
; _Close16EventSem
; Convert parameter to 32 bit
; Switch to 32 bit code
; Call Dos32CloseEventSem
; Switch to 16 bit code
; Remove parameter
; Return
;
;********************** END OF SPECIFICATIONS *********************
;
;         Subroutine Name:               QueInit
;
;         Descriptive Name:              Quecalls initialization.
;
;         Function:
;                    Initialize Quecalls.
;
;         Notes:
;
;         Entry Point:         QueInit
;             Linkage:    dyna-link at pl 3
;
;         Input:
;
;         Exit-Normal:
;
;         Exit-Error:
;
;         Effects:
;
;*************************** PSEUDOCODE ***************************
;
; QueInit
; jump to 16 bit code
; call DosQueryQueue
; jump to 32 bit code
; return
;
;********************** END OF SPECIFICATIONS *********************

include bsexcpt.inc
include bsetib.inc
include qthkcode.inc
