Index: trunk/libc/include/os2safe.h
===================================================================
--- trunk/libc/include/os2safe.h	(revision 3942)
+++ trunk/libc/include/os2safe.h	(revision 3943)
@@ -55,4 +55,21 @@
 #define WinUpper                SafeWinUpper
 
+/*
+ * Note! The DOS queue API does not work with data, but with addresses, request
+ * numbers, priorities and process IDs.  I.e. the data address you give
+ * DosWriteQueue is NOT used to memcpy() what it points to into some internal
+ * buffer that is then queued.  Instead that address is converted to 16-bit and
+ * placed on the queue.
+ *
+ * This means that the data pointer passed to DosWriteQueue CANNOT be a high
+ * address!  (The wrappers below makes sure all the other pointer parameters
+ * can be pointing to high memory, though.)
+ */
+#define DosCreateQueue          SafeDosCreateQueue
+#define DosOpenQueue            SafeDosOpenQueue
+#define DosPeekQueue            SafeDosPeekQueue
+#define DosQueryQueue           SafeDosQueryQueue
+#define DosReadQueue            SafeDosReadQueue
+
 #endif
 
Index: trunk/libc/src/libos2/safe/SafeDosCreateQueue.c
===================================================================
--- trunk/libc/src/libos2/safe/SafeDosCreateQueue.c	(revision 3943)
+++ trunk/libc/src/libos2/safe/SafeDosCreateQueue.c	(revision 3943)
@@ -0,0 +1,30 @@
+/* $Id$ */
+/** @file
+ * kLibC - Safe DosCreateQueue().
+ *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
+ */
+
+
+/*******************************************************************************
+* Header Files                                                                 *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include "safe.h"
+
+ULONG APIENTRY SafeDosCreateQueue(PHQUEUE phq, ULONG ulPriority, PCSZ pszName);
+ULONG APIENTRY SafeDosCreateQueue(PHQUEUE phq, ULONG ulPriority, PCSZ pszName)
+{
+    APIRET rc;
+    SAFE_PCSZ(pszName);
+    SAFE_INOUTTYPE(phq, HQUEUE);
+
+    rc = DosCreateQueue(SAFE_INOUTTYPE_USE(phq), ulPriority, SAFE_PCSZ_USE(pszName));
+
+    SAFE_INOUTTYPE_DONE(phq);
+    SAFE_PCSZ_DONE(pszName);
+    return rc;
+}
+
Index: trunk/libc/src/libos2/safe/SafeDosOpenQueue.c
===================================================================
--- trunk/libc/src/libos2/safe/SafeDosOpenQueue.c	(revision 3943)
+++ trunk/libc/src/libos2/safe/SafeDosOpenQueue.c	(revision 3943)
@@ -0,0 +1,32 @@
+/* $Id$ */
+/** @file
+ * kLibC - Safe DosOpenQueue().
+ *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
+ */
+
+
+/*******************************************************************************
+* Header Files                                                                 *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include "safe.h"
+
+ULONG APIENTRY SafeDosOpenQueue(PPID ppid, PHQUEUE phq, PCSZ pszName);
+ULONG APIENTRY SafeDosOpenQueue(PPID ppid, PHQUEUE phq, PCSZ pszName)
+{
+    APIRET rc;
+    SAFE_PCSZ(pszName);
+    SAFE_INOUTTYPE(phq, HQUEUE);
+    SAFE_INOUTTYPE(ppid, PID);
+
+    rc = DosOpenQueue(SAFE_INOUTTYPE_USE(ppid), SAFE_INOUTTYPE_USE(phq), SAFE_PCSZ_USE(pszName));
+
+    SAFE_INOUTTYPE_DONE(ppid);
+    SAFE_INOUTTYPE_DONE(phq);
+    SAFE_PCSZ_DONE(pszName);
+    return rc;
+}
+
Index: trunk/libc/src/libos2/safe/SafeDosPeekQueue.c
===================================================================
--- trunk/libc/src/libos2/safe/SafeDosPeekQueue.c	(revision 3943)
+++ trunk/libc/src/libos2/safe/SafeDosPeekQueue.c	(revision 3943)
@@ -0,0 +1,39 @@
+/* $Id$ */
+/** @file
+ * kLibC - Safe DosPeekQueue().
+ *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
+ */
+
+
+/*******************************************************************************
+* Header Files                                                                 *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include "safe.h"
+
+ULONG APIENTRY SafeDosPeekQueue(HQUEUE hq, PREQUESTDATA pRequest, PULONG pcbData, PPVOID ppvData, PULONG pulElement,
+                                BOOL32 fNowait, PBYTE pbPriority, HEV hsem);
+ULONG APIENTRY SafeDosPeekQueue(HQUEUE hq, PREQUESTDATA pRequest, PULONG pcbData, PPVOID ppvData, PULONG pulElement,
+                                BOOL32 fNowait, PBYTE pbPriority, HEV hsem)
+{
+    APIRET rc;
+    SAFE_INOUTTYPE(pRequest, REQUESTDATA);
+    SAFE_INOUTTYPE(pcbData, ULONG);
+    SAFE_INOUTTYPE(ppvData, PVOID);
+    SAFE_INOUTTYPE(pulElement, ULONG);
+    SAFE_INOUTTYPE(pbPriority, BYTE);
+
+    rc = DosPeekQueue(hq, SAFE_INOUTTYPE_USE(pRequest), SAFE_INOUTTYPE_USE(pcbData), SAFE_INOUTTYPE_USE(ppvData),
+                      SAFE_INOUTTYPE_USE(pulElement), fNowait, SAFE_INOUTTYPE_USE(pbPriority), hsem);
+
+    SAFE_INOUTTYPE_DONE(pbPriority);
+    SAFE_INOUTTYPE_DONE(pulElement);
+    SAFE_INOUTTYPE_DONE(ppvData);
+    SAFE_INOUTTYPE_DONE(pcbData);
+    SAFE_INOUTTYPE_DONE(pRequest);
+    return rc;
+}
+
Index: trunk/libc/src/libos2/safe/SafeDosQueryQueue.c
===================================================================
--- trunk/libc/src/libos2/safe/SafeDosQueryQueue.c	(revision 3943)
+++ trunk/libc/src/libos2/safe/SafeDosQueryQueue.c	(revision 3943)
@@ -0,0 +1,28 @@
+/* $Id$ */
+/** @file
+ * kLibC - Safe DosQueryQueue().
+ *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
+ */
+
+
+/*******************************************************************************
+* Header Files                                                                 *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include "safe.h"
+
+ULONG APIENTRY SafeDosQueryQueue(HQUEUE hq, PULONG pulCount);
+ULONG APIENTRY SafeDosQueryQueue(HQUEUE hq, PULONG pulCount)
+{
+    APIRET rc;
+    SAFE_INOUTTYPE(pulCount, ULONG);
+
+    rc = DosQueryQueue(hq, SAFE_INOUTTYPE_USE(pulCount));
+
+    SAFE_INOUTTYPE_DONE(pulCount);
+    return rc;
+}
+
Index: trunk/libc/src/libos2/safe/SafeDosReadQueue.c
===================================================================
--- trunk/libc/src/libos2/safe/SafeDosReadQueue.c	(revision 3943)
+++ trunk/libc/src/libos2/safe/SafeDosReadQueue.c	(revision 3943)
@@ -0,0 +1,38 @@
+/* $Id$ */
+/** @file
+ * kLibC - Safe DosReadQueue().
+ *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
+ */
+
+
+/*******************************************************************************
+* Header Files                                                                 *
+*******************************************************************************/
+#define INCL_BASE
+#include <os2.h>
+#include "safe.h"
+
+ULONG APIENTRY SafeDosReadQueue(HQUEUE hq, PREQUESTDATA pRequest, PULONG pcbData, PPVOID ppvData, ULONG ulElement,
+                                BOOL32 fNowait, PBYTE pbPriority, HEV hsem);
+ULONG APIENTRY SafeDosReadQueue(HQUEUE hq, PREQUESTDATA pRequest, PULONG pcbData, PPVOID ppvData, ULONG ulElement,
+                                BOOL32 fNowait, PBYTE pbPriority, HEV hsem)
+{
+    APIRET rc;
+    SAFE_INOUTTYPE(pRequest, REQUESTDATA);
+    SAFE_INOUTTYPE(pcbData, ULONG);
+    SAFE_INOUTTYPE(ppvData, PVOID);
+    SAFE_INOUTTYPE(pbPriority, BYTE);
+
+    rc = DosReadQueue(hq, SAFE_INOUTTYPE_USE(pRequest), SAFE_INOUTTYPE_USE(pcbData), SAFE_INOUTTYPE_USE(ppvData),
+                      ulElement, fNowait, SAFE_INOUTTYPE_USE(pbPriority), hsem);
+
+    SAFE_INOUTTYPE_DONE(pbPriority);
+    SAFE_INOUTTYPE_DONE(ppvData);
+    SAFE_INOUTTYPE_DONE(pcbData);
+    SAFE_INOUTTYPE_DONE(pRequest);
+    return rc;
+}
+
+
Index: trunk/libc/src/libos2/safe/safe.h
===================================================================
--- trunk/libc/src/libos2/safe/safe.h	(revision 3942)
+++ trunk/libc/src/libos2/safe/safe.h	(revision 3943)
@@ -1,25 +1,10 @@
 /* $Id$ */
 /** @file
- *
  * Macros, prototypes and inline helpers.
  *
- * Copyright (c) 2003 knut st. osmundsen <bird-srcspam@anduin.net>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with This program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
+ * @copyright   Copyright (C) 2003-2015 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
+ * @licenses    MIT, BSD2, BSD3, BSD4, LGPLv2.1, LGPLv3, LGPLvFuture.
  */
+
 #ifndef __safe_h__
 #define __safe_h__
@@ -46,8 +31,6 @@
             memcpy(arg##_safe, (arg), cch); \
         } else do {} while (0)
-
 /** Use the const string. */
 #define SAFE_PCSZ_USE(arg) arg##_safe
-
 /** Cleanup a const string. */
 #define SAFE_PCSZ_DONE(arg) \
@@ -56,4 +39,27 @@
     } \
     l_##arg##_failed: do {} while (0)
+
+
+
+/** Wrap an input only buffer. */
+#define SAFE_INBUF(arg, len, type) \
+    { \
+        type *arg##_safe = arg; \
+        if (SAFE_IS_HIGH(arg)) \
+        { \
+            arg##_safe = (type *)_lmalloc(len); \
+            if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \
+            memcpy(arg##_safe, (arg), len); \
+        } else do {} while (0)
+/** Use the safe input only buffer. */
+#define SAFE_INBUF_USE(arg) arg##_safe
+/** Cleanup an input only buffer. */
+#define SAFE_INBUF_DONE(arg, len) \
+        if (arg##_safe != arg) \
+           free(arg##_safe); \
+    } \
+    l_##arg##_failed: do {} while (0)
+
+
 
 /** Wrap an input/output buffer. */
@@ -67,8 +73,6 @@
             memcpy(arg##_safe, (arg), len);\
         } else do {} while (0)
-
 /** Use the safe input/output buffer. */
 #define SAFE_INOUTBUF_USE(arg) arg##_safe
-
 /** Cleanup an input/output buffer. */
 #define SAFE_INOUTBUF_DONE(arg, len) \
@@ -80,4 +84,6 @@
     } \
     l_##arg##_failed: do {} while (0)
+
+
 
 /** Wrap the pointer to an input only type/struct. */
@@ -95,8 +101,6 @@
             *arg##_safe = *(arg); \
         } else do {} while (0)
-
 /** Use the safe pointer to an input only type/struct. */
 #define SAFE_INTYPE_USE(arg) arg##_safe
-
 /** Cleanup after wrapping an input only type/struct. */
 #define SAFE_INTYPE_DONE(arg) \
@@ -105,4 +109,6 @@
     } \
     l_##arg##_failed: do {} while (0)
+
+
 
 /** Wrap the pointer to an input/output type/struct. */
@@ -120,8 +126,6 @@
             *arg##_safe = *(arg); \
         } else do {} while (0)
-
 /** Use the safe pointer to an input/output type/struct. */
 #define SAFE_INOUTTYPE_USE(arg) arg##_safe
-
 /** Cleanup after wrapping an input/output type/struct. */
 #define SAFE_INOUTTYPE_DONE(arg) \
@@ -134,10 +138,4 @@
 
 
+#endif
 
-/** Generic failure label for Dos API wappers.
- * It'll just return out of memory error.
- * @obsolete  */
-#define SAFE_DOS_FAILURE() do { } while (0)
-
-
-#endif
