@@ -1126,6 +1126,34 @@ DbgTransportSession::Message * DbgTransportSession::RemoveMessageFromSendQueue(D
1126
1126
#endif
1127
1127
1128
1128
#ifndef RIGHT_SIDE_COMPILE
1129
+
1130
+ #ifdef FEATURE_PAL
1131
+ __attribute__ ((noinline))
1132
+ __attribute__((optnone))
1133
+ static void
1134
+ ProbeMemory(__in_ecount(cbBuffer) volatile PBYTE pbBuffer, DWORD cbBuffer, bool fWriteAccess)
1135
+ {
1136
+ // Need an throw in this function to fool the C++ runtime into handling the
1137
+ // possible h/w exception below.
1138
+ if (pbBuffer == NULL )
1139
+ {
1140
+ throw PAL_SEHException ();
1141
+ }
1142
+
1143
+ // Simple one byte at a time probing
1144
+ while (cbBuffer > 0 )
1145
+ {
1146
+ volatile BYTE read = *pbBuffer;
1147
+ if (fWriteAccess )
1148
+ {
1149
+ *pbBuffer = read;
1150
+ }
1151
+ ++pbBuffer;
1152
+ --cbBuffer;
1153
+ }
1154
+ }
1155
+ #endif // FEATURE_PAL
1156
+
1129
1157
// Check read and optionally write memory access to the specified range of bytes. Used to check
1130
1158
// ReadProcessMemory and WriteProcessMemory requests.
1131
1159
HRESULT DbgTransportSession::CheckBufferAccess (__in_ecount(cbBuffer) PBYTE pbBuffer, DWORD cbBuffer, bool fWriteAccess)
@@ -1138,7 +1166,6 @@ HRESULT DbgTransportSession::CheckBufferAccess(__in_ecount(cbBuffer) PBYTE pbBuf
1138
1166
1139
1167
// VirtualQuery doesn't know much about memory allocated outside of PAL's VirtualAlloc
1140
1168
// that's why on Unix we can't rely on in to detect invalid memory reads
1141
- // TODO: We need to find and use appropriate memory map API on other operating systems.
1142
1169
#ifndef FEATURE_PAL
1143
1170
do
1144
1171
{
@@ -1179,11 +1206,24 @@ HRESULT DbgTransportSession::CheckBufferAccess(__in_ecount(cbBuffer) PBYTE pbBuf
1179
1206
}
1180
1207
}
1181
1208
while (cbBuffer > 0 );
1209
+ #else
1210
+ try
1211
+ {
1212
+ // Need to explicit h/w exception holder so to catch them in ProbeMemory
1213
+ CatchHardwareExceptionHolder __catchHardwareException;
1214
+
1215
+ ProbeMemory (pbBuffer, cbBuffer, fWriteAccess );
1216
+ }
1217
+ catch (...)
1218
+ {
1219
+ return HRESULT_FROM_WIN32 (ERROR_INVALID_ADDRESS);
1220
+ }
1182
1221
#endif
1183
1222
1184
1223
// The specified region has passed all of our checks.
1185
1224
return S_OK;
1186
1225
}
1226
+
1187
1227
#endif // !RIGHT_SIDE_COMPILE
1188
1228
1189
1229
// Initialize all session state to correct starting values. Used during Init() and on the LS when we
0 commit comments