|
|
1.1 root 1: // This is a part of the Microsoft Foundation Classes C++ library.
2: // Copyright (C) 1992 Microsoft Corporation
3: // All rights reserved.
4: //
5: // This source code is only intended as a supplement to the
6: // Microsoft Foundation Classes Reference and Microsoft
7: // QuickHelp documentation provided with the library.
8: // See these sources for detailed information regarding the
9: // Microsoft Foundation Classes product.
10:
11: #include "afx.h"
12: #ifdef _WINDOWS
13: #include "afxwin.h"
14: #endif
15: #pragma hdrstop
16:
17: #ifdef AFX_CORE_SEG
18: #pragma code_seg(AFX_CORE_SEG)
19: #endif
20:
21: #pragma optimize("qgel", off)
22: #pragma warning(disable:4100)
23:
24: extern "C" BOOL FAR PASCAL
25: AfxIsValidAddress(const void FAR* lp, UINT nBytes, BOOL bReadWrite /* = TRUE */)
26: {
27: #ifdef _NTWIN
28: return TRUE;
29: #else
30: BOOL bValid = FALSE;
31:
32: #ifdef _WINDOWS
33: BOOL b286 = (WF_CPU286 & GetWinFlags()) ? TRUE : FALSE;
34:
35: if ( !b286 )
36: {
37:
38: _asm {
39: _asm _emit 0x66
40: xor bx, bx ; clear out ebx
41: mov bx, WORD PTR lp + 2
42: or bx,bx
43: jz done ; zero segments are always bad
44: _asm _emit 0x0F ; lar cx, bx
45: _asm _emit 0x02
46: _asm _emit 0xCB
47: jnz done
48:
49: test ch,128 ; if (!present(bx))
50: jz skip_range_test ; return fTrue;
51:
52: cmp bReadWrite, 0
53: je skip_write_test
54:
55: _asm _emit 0x0F ; verw bx
56: _asm _emit 0x00
57: _asm _emit 0xEB
58: ; if (!writeable(bx))
59: jnz done
60:
61: skip_write_test:
62:
63: _asm _emit 0x66
64: _asm _emit 0x0F ; lsl, edx, bx
65: _asm _emit 0x03
66: _asm _emit 0xD3
67: jnz done
68: ;* dx = last valid address
69:
70: mov bx, WORD PTR lp
71: mov cx, nBytes
72: jcxz skip_range_test ; if length == 0, ignore offset part
73:
74: ;* make sure start address is valid
75: _asm _emit 0x66
76: cmp bx,dx ; if (offsetof(lp) > dx)
77: ja done
78:
79: ;* make sure last address is also valid
80: dec cx ; bias for last byte
81: add bx,cx
82: jc done ; overflow => no good
83: _asm _emit 0x66
84: cmp dx,bx ; if (offsetof(lp) + nBytes <= dx)
85: jb done
86: skip_range_test:
87: inc bValid
88: done:
89: }
90: }
91: else
92: #endif // !_WINDOWS
93: _asm {
94: mov bx, WORD PTR lp + 2
95: or bx,bx
96: jz done2 ; zero segments are always bad
97: #ifndef _DOS
98: _asm _emit 0x0F ; lar cx, bx
99: _asm _emit 0x02
100: _asm _emit 0xCB
101: jnz done2
102:
103: test ch,128 ; if (!present(bx))
104: jz skip_range_test2 ; return fTrue;
105:
106: cmp bReadWrite, 0
107: je skip_write_test2
108:
109: _asm _emit 0x0F ; verw bx
110: _asm _emit 0x00
111: _asm _emit 0xEB
112: ; if (!writeable(bx))
113: jnz done2
114:
115: skip_write_test2:
116:
117: _asm _emit 0x0F ; lsl, dx, bx
118: _asm _emit 0x03
119: _asm _emit 0xD3
120: jnz done2
121: ;* dx = last valid address
122:
123: mov bx, WORD PTR lp
124: mov cx, nBytes
125: jcxz skip_range_test2 ; if length == 0, ignore offset part
126:
127: ;* make sure start address is valid
128: cmp bx,dx ; if (offsetof(lp) > dx)
129: ja done2
130:
131: ;* make sure last address is also valid
132: dec cx ; bias for last byte
133: add bx,cx
134: jc done2 ; overflow => no good
135: cmp dx,bx ; if (offsetof(lp) + nBytes <= dx)
136: jb done2
137: skip_range_test2:
138:
139: #endif //!_DOS
140: inc bValid
141: done2:
142: }
143: return bValid;
144: #endif // _NTWIN
145: }
146:
147: #pragma warning(default:4100)
148: #pragma optimize("", on)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.