Changeset 3942


Ignore:
Timestamp:
Dec 26, 2014, 8:15:42 PM (11 years ago)
Author:
bird
Message:

os2safe: Wrap high memory buffers for DosQueryDBCSEnv as well as DosMapCase, DosQueryCollate, DosQueryCp and DosQueryCtryInfo.

Location:
trunk/libc
Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/os2safe.h

    r3926 r3942  
    11/* os2safe.h,v 1.1 2003/10/06 00:54:20 bird Exp */
    22/** @file
    3  *
    43 * OS/2 API High Memory Wrappers.
    54 * You include this file before os2.h and link with -los2safe.
     5 */
     6
     7/*
    68 *
    7  * Copyright (c) 2003-2014 knut st. osmundsen <bird-srcspam@anduin.net>
     9 * Copyright (c) 2003-2015 knut st. osmundsen <bird-srcspam@anduin.net>
    810 *
    911 *
     
    4446#define DosStartSession         SafeDosStartSession
    4547#define DosQueryAppType         SafeDosQueryAppType
    46 #define DosDevIOCtl             SafeDosDevIOCtl
     48
     49#define DosMapCase              SafeDosMapCase
     50#define DosQueryCollate         SafeDosQueryCollate
     51#define DosQueryCp              SafeDosQueryCp
     52#define DosQueryCtryInfo        SafeDosQueryCtryInfo
     53#define DosQueryDBCSEnv         SafeDosQueryDBCSEnv
     54
    4755#define WinUpper                SafeWinUpper
    4856
    4957#endif
     58
  • trunk/libc/src/libos2/safe/SafeDosForceDelete.c

    r3897 r3942  
    3434    rc = DosForceDelete(SAFE_PCSZ_USE(pszFileName));
    3535    SAFE_PCSZ_DONE(pszFileName);
    36     SAFE_DOS_FAILURE();
    3736    return rc;
    3837}
  • trunk/libc/src/libos2/safe/SafeDosOpen.c

    r3926 r3942  
    5050
    5151    SAFE_PCSZ_DONE(pszFileName);
    52     SAFE_DOS_FAILURE();
    5352    return rc;
    5453}
  • trunk/libc/src/libos2/safe/SafeDosOpenL.c

    r3897 r3942  
    6262
    6363    SAFE_PCSZ_DONE(pszFileName);
    64     SAFE_DOS_FAILURE();
    6564    return rc;
    6665}
  • trunk/libc/src/libos2/safe/SafeDosQueryAppType.c

    r3897 r3942  
    4848
    4949    SAFE_PCSZ_DONE(pszName);
    50     SAFE_DOS_FAILURE();
    5150    return rc;
    5251}
  • trunk/libc/src/libos2/safe/SafeDosWaitNPipe.c

    r3897 r3942  
    3434    rc = DosWaitNPipe(SAFE_PCSZ_USE(pszName), ulTimeout);
    3535    SAFE_PCSZ_DONE(pszName);
    36     SAFE_DOS_FAILURE();
    3736    return rc;
    3837}
     38
  • trunk/libc/src/libos2/safe/safe.h

    r3897 r3942  
    3737/** Wrap a const string. */
    3838#define SAFE_PCSZ(arg) \
    39     char * arg##_safe = (char*)arg;                 \
    40     if (SAFE_IS_HIGH(arg))                          \
    41     {                                               \
    42         int cch = strlen(arg) + 1;                  \
    43         arg##_safe = _lmalloc(cch);                 \
    44         if (!arg##_safe) goto safe_failure;         \
    45         memcpy(arg##_safe, (arg), cch);             \
    46     }                                               \
    47         {
    48 
     39    { \
     40        char *arg##_safe = (char *)arg; \
     41        if (SAFE_IS_HIGH(arg)) \
     42        { \
     43            int cch = strlen(arg) + 1; \
     44            arg##_safe = _lmalloc(cch); \
     45            if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \
     46            memcpy(arg##_safe, (arg), cch); \
     47        } else do {} while (0)
    4948
    5049/** Use the const string. */
     
    5352/** Cleanup a const string. */
    5453#define SAFE_PCSZ_DONE(arg) \
    55         }                                           \
    56     if (arg##_safe != (char*)arg) free(arg##_safe)
     54        if (arg##_safe != (char *)arg) \
     55            free(arg##_safe); \
     56    } \
     57    l_##arg##_failed: do {} while (0)
     58
     59/** Wrap an input/output buffer. */
     60#define SAFE_INOUTBUF(arg, len, type) \
     61    { \
     62        type *arg##_safe = arg; \
     63        if (SAFE_IS_HIGH(arg)) \
     64        { \
     65            arg##_safe = (type *)_lmalloc(len); \
     66            if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \
     67            memcpy(arg##_safe, (arg), len);\
     68        } else do {} while (0)
     69
     70/** Use the safe input/output buffer. */
     71#define SAFE_INOUTBUF_USE(arg) arg##_safe
     72
     73/** Cleanup an input/output buffer. */
     74#define SAFE_INOUTBUF_DONE(arg, len) \
     75        if (arg##_safe != arg) \
     76        { \
     77           memcpy(arg, arg##_safe, len); \
     78           free(arg##_safe); \
     79        } \
     80    } \
     81    l_##arg##_failed: do {} while (0)
     82
     83/** Wrap the pointer to an input only type/struct. */
     84#define SAFE_INTYPE(arg, type) \
     85   { \
     86        type *arg##_free = NULL; \
     87        type *arg##_safe = (type *)arg; \
     88        if (SAFE_IS_HIGH(arg)) \
     89        { \
     90            if (sizeof(type) < 256) \
     91                arg##_safe = (type *)alloca(sizeof(type)); \
     92            else \
     93                arg##_free = arg##_safe = (type *)_lmalloc(sizeof(type)); \
     94            if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \
     95            *arg##_safe = *(arg); \
     96        } else do {} while (0)
     97
     98/** Use the safe pointer to an input only type/struct. */
     99#define SAFE_INTYPE_USE(arg) arg##_safe
     100
     101/** Cleanup after wrapping an input only type/struct. */
     102#define SAFE_INTYPE_DONE(arg) \
     103       if (arg##_free) \
     104          free(arg##_free); \
     105    } \
     106    l_##arg##_failed: do {} while (0)
     107
     108/** Wrap the pointer to an input/output type/struct. */
     109#define SAFE_INOUTTYPE(arg, type) \
     110    { \
     111        type *arg##_free = NULL; \
     112        type *arg##_safe = (type *)arg; \
     113        if (SAFE_IS_HIGH(arg)) \
     114        { \
     115            if (sizeof(type) < 256) \
     116                arg##_safe = (type *)alloca(sizeof(type)); \
     117            else \
     118                arg##_free = arg##_safe = (type *)_lmalloc(sizeof(type)); \
     119            if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \
     120            *arg##_safe = *(arg); \
     121        } else do {} while (0)
     122
     123/** Use the safe pointer to an input/output type/struct. */
     124#define SAFE_INOUTTYPE_USE(arg) arg##_safe
     125
     126/** Cleanup after wrapping an input/output type/struct. */
     127#define SAFE_INOUTTYPE_DONE(arg) \
     128        if (arg##_safe != (arg)) \
     129          *(arg) = *arg##_safe; \
     130        if (arg##_free) \
     131           free(arg##_free); \
     132    } \
     133    l_##arg##_failed: do {} while (0)
     134
    57135
    58136
    59137/** Generic failure label for Dos API wappers.
    60  * It'll just return out of memory error. */
    61 #define SAFE_DOS_FAILURE() \
    62     if (0)                                          \
    63     {                                               \
    64         safe_failure:                               \
    65             rc = 8;                                 \
    66     }
     138 * It'll just return out of memory error.
     139 * @obsolete  */
     140#define SAFE_DOS_FAILURE() do { } while (0)
    67141
    68142
Note: See TracChangeset for help on using the changeset viewer.