| [3396] | 1 | /* $Id: odin32validate.h,v 1.2 2000-04-16 04:06:11 bird Exp $ | 
|---|
| [3395] | 2 | * | 
|---|
|  | 3 | * Parameter validation macros. | 
|---|
|  | 4 | * | 
|---|
| [3396] | 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 | * | 
|---|
| [3395] | 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 | /** | 
|---|
| [3396] | 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. | 
|---|
| [3395] | 22 | */ | 
|---|
|  | 23 | #define ADDRESS_SPACE_LIMIT 0xc0000000 | 
|---|
|  | 24 |  | 
|---|
|  | 25 |  | 
|---|
|  | 26 | /** | 
|---|
| [3396] | 27 | * Validates that the specified pointer points at valid. | 
|---|
|  | 28 | * (Currently it only check that it's within the user virtual address space.) | 
|---|
| [3395] | 29 | * @returns   TRUE if valid. | 
|---|
|  | 30 | *            FALSE if invalid. | 
|---|
|  | 31 | * @param     p     Pointer value. | 
|---|
|  | 32 | */ | 
|---|
| [3396] | 33 | #define VALID_PTR(p) \ | 
|---|
| [3395] | 34 | ((char*)(p) >= (char*)0x10000 \ | 
|---|
|  | 35 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT) | 
|---|
|  | 36 |  | 
|---|
|  | 37 |  | 
|---|
|  | 38 | /** | 
|---|
| [3396] | 39 | * Validates that the area pointed to is valid. | 
|---|
|  | 40 | * (Currently it only check that it's within the user virtual address space.) | 
|---|
| [3395] | 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 | */ | 
|---|
| [3396] | 46 | #define VALID_PTRSIZE(p, cb) \ | 
|---|
| [3395] | 47 | ((char*)(p) >= (char*)0x10000 \ | 
|---|
|  | 48 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT \ | 
|---|
| [3396] | 49 | && (char*)(p) + (unsigned)(cb) < (char*)ADDRESS_SPACE_LIMIT) | 
|---|
| [3395] | 50 |  | 
|---|
| [3396] | 51 |  | 
|---|
| [3395] | 52 | /** | 
|---|
| [3396] | 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.) | 
|---|
| [3395] | 56 | * @returns   TRUE if valid. | 
|---|
|  | 57 | *            FALSE if invalid. | 
|---|
|  | 58 | * @param     psz       String pointer. | 
|---|
|  | 59 | * @param     cchMax    Max string length | 
|---|
|  | 60 | */ | 
|---|
| [3396] | 61 | #define VALID_PSZ(psz) \ | 
|---|
|  | 62 | (VALID_PTRSIZE(psz, 1)) | 
|---|
| [3395] | 63 |  | 
|---|
| [3396] | 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) | 
|---|
| [3395] | 75 |  | 
|---|
|  | 76 |  | 
|---|
| [3396] | 77 |  | 
|---|
| [3395] | 78 | #endif /* !defined(_odin32validate_h_) */ | 
|---|