1 | /* $Id: odin32validate.h,v 1.1 2000-04-16 02:59:03 bird Exp $
|
---|
2 | *
|
---|
3 | * Parameter validation macros.
|
---|
4 | *
|
---|
5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 | #ifndef _odin32validate_h_
|
---|
11 | #define _odin32validate_h_
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * ADDRESS_SPACE_LIMIT holds the largest possible address in the address space + 1.
|
---|
15 | * 3GB is the higest possible address in the user address space in OS/2.
|
---|
16 | */
|
---|
17 | #define ADDRESS_SPACE_LIMIT 0xc0000000
|
---|
18 |
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Validates that the value of a pointer is within the virtual address space.
|
---|
22 | * @returns TRUE if valid.
|
---|
23 | * FALSE if invalid.
|
---|
24 | * @param p Pointer value.
|
---|
25 | */
|
---|
26 | #define VALIDFAST_PTR(p) \
|
---|
27 | ((char*)(p) >= (char*)0x10000 \
|
---|
28 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT)
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Validates that a area pointed to is within the virtual address space.
|
---|
33 | * @returns TRUE if valid.
|
---|
34 | * FALSE if invalid.
|
---|
35 | * @param p Pointer value.
|
---|
36 | * @param cb Size of data pointer to by the pointer.
|
---|
37 | */
|
---|
38 | #define VALIDFAST_PTRSIZE(p, cb) \
|
---|
39 | ((char*)(p) >= (char*)0x10000 \
|
---|
40 | && (char*)(p) < (char*)ADDRESS_SPACE_LIMIT \
|
---|
41 | && (char*)(p) + (char*)(cb) < (char*)ADDRESS_SPACE_LIMIT)
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Validates that the value of a string pointer is within the virtual address
|
---|
45 | * space, and that its length less or equal to the given max length.
|
---|
46 | * @returns TRUE if valid.
|
---|
47 | * FALSE if invalid.
|
---|
48 | * @param psz String pointer.
|
---|
49 | * @param cchMax Max string length
|
---|
50 | */
|
---|
51 | #define VALIDFAST_PSZLENGTH(psz, cchMax) \
|
---|
52 | (VALIDFAST_PTRSIZE(psz, 1) \
|
---|
53 | && strlen(psz) <= cchMax)
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | #endif /* !defined(_odin32validate_h_) */
|
---|