| 1 | /* $Id: odin32validate.h,v 1.2 2000-04-16 04:06:11 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Parameter validation macros.
|
|---|
| 4 | *
|
|---|
| 5 | * Note that these are not fully implemented yet. Pointers and memory areas
|
|---|
| 6 | * are not checked if valid yet, since this requires some more effort. So,
|
|---|
| 7 | * for the time being pointers and memory areas are checked agains the
|
|---|
| 8 | * maximum user virtual address space limits.
|
|---|
| 9 | *
|
|---|
| 10 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
|---|
| 11 | *
|
|---|
| 12 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | #ifndef _odin32validate_h_
|
|---|
| 16 | #define _odin32validate_h_
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * ADDRESS_SPACE_LIMIT holds the largest possible address in the user virtual
|
|---|
| 20 | * address virtual space + 1.
|
|---|
| 21 | * 3GB is the higest possible address in the user virtual address space in OS/2.
|
|---|
| 22 | */
|
|---|
| 23 | #define ADDRESS_SPACE_LIMIT 0xc0000000
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * Validates that the specified pointer points at valid.
|
|---|
| 28 | * (Currently it only check that it's within the user virtual address space.)
|
|---|
| 29 | * @returns TRUE if valid.
|
|---|
| 30 | * FALSE if invalid.
|
|---|
| 31 | * @param p Pointer value.
|
|---|
| 32 | */
|
|---|
| 33 | #define VALID_PTR(p) \
|
|---|
| 34 | ((char*)(p) >= (char*)0x10000 \
|
|---|
| 35 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT)
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Validates that the area pointed to is valid.
|
|---|
| 40 | * (Currently it only check that it's within the user virtual address space.)
|
|---|
| 41 | * @returns TRUE if valid.
|
|---|
| 42 | * FALSE if invalid.
|
|---|
| 43 | * @param p Pointer value.
|
|---|
| 44 | * @param cb Size of data pointer to by the pointer.
|
|---|
| 45 | */
|
|---|
| 46 | #define VALID_PTRSIZE(p, cb) \
|
|---|
| 47 | ((char*)(p) >= (char*)0x10000 \
|
|---|
| 48 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT \
|
|---|
| 49 | && (char*)(p) + (unsigned)(cb) < (char*)ADDRESS_SPACE_LIMIT)
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | /**
|
|---|
| 53 | * Validates that a string pointer is valid and that the entire string is valid.
|
|---|
| 54 | * (Currently it only checks that the first byte of the string is within
|
|---|
| 55 | * the user virtual address space.)
|
|---|
| 56 | * @returns TRUE if valid.
|
|---|
| 57 | * FALSE if invalid.
|
|---|
| 58 | * @param psz String pointer.
|
|---|
| 59 | * @param cchMax Max string length
|
|---|
| 60 | */
|
|---|
| 61 | #define VALID_PSZ(psz) \
|
|---|
| 62 | (VALID_PTRSIZE(psz, 1))
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * Validates that a string less or equal to a given max length.
|
|---|
| 66 | * Note! the pointer isn't validated. That you'll have to do separatly using
|
|---|
| 67 | * VALID_PSZ(psz) which is defined right above.
|
|---|
| 68 | * @returns TRUE if valid.
|
|---|
| 69 | * FALSE if invalid.
|
|---|
| 70 | * @param psz String pointer.
|
|---|
| 71 | * @param cchMax Max string length
|
|---|
| 72 | */
|
|---|
| 73 | #define VALID_PSZMAXSIZE(psz, cchMax) \
|
|---|
| 74 | (strlen(psz) <= cchMax)
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | #endif /* !defined(_odin32validate_h_) */
|
|---|