|
@@ -329,6 +329,7 @@ process_win32_write(struct process_t *process, buf_t *buffer)
|
|
|
|
|
|
process_win32_t *win32_process = process_get_win32_process(process);
|
|
|
BOOL ret = FALSE;
|
|
|
+ DWORD error_code = 0;
|
|
|
const size_t buffer_size = buf_datalen(buffer);
|
|
|
|
|
|
|
|
@@ -350,6 +351,12 @@ process_win32_write(struct process_t *process, buf_t *buffer)
|
|
|
|
|
|
buf_get_bytes(buffer, win32_process->stdin_handle.buffer, write_size);
|
|
|
|
|
|
+
|
|
|
+ * before we call WriteFileEx() because WriteFileEx() does not reset the last
|
|
|
+ * error itself when it's succesful. See comment below after the call to
|
|
|
+ * GetLastError(). */
|
|
|
+ SetLastError(0);
|
|
|
+
|
|
|
|
|
|
ret = WriteFileEx(win32_process->stdin_handle.pipe,
|
|
|
win32_process->stdin_handle.buffer,
|
|
@@ -363,6 +370,24 @@ process_win32_write(struct process_t *process, buf_t *buffer)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * should check GetLastError() after a call to WriteFileEx() even though the
|
|
|
+ * `ret` return value was successful. If everything is good, GetLastError()
|
|
|
+ * returns `ERROR_SUCCESS` and nothing happens.
|
|
|
+ *
|
|
|
+ * XXX(ahf): I have not managed to trigger this code while stress-testing
|
|
|
+ * this code. */
|
|
|
+ error_code = GetLastError();
|
|
|
+
|
|
|
+ if (error_code != ERROR_SUCCESS) {
|
|
|
+
|
|
|
+ log_warn(LD_PROCESS, "WriteFileEx() failed after returning success: %s",
|
|
|
+ format_win32_error(error_code));
|
|
|
+ win32_process->stdin_handle.reached_eof = true;
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* large. */
|
|
|
return (int)write_size;
|
|
@@ -864,6 +889,7 @@ process_win32_read_from_handle(process_win32_handle_t *handle,
|
|
|
|
|
|
BOOL ret = FALSE;
|
|
|
int bytes_available = 0;
|
|
|
+ DWORD error_code = 0;
|
|
|
|
|
|
|
|
|
if (BUG(handle->busy))
|
|
@@ -887,6 +913,12 @@ process_win32_read_from_handle(process_win32_handle_t *handle,
|
|
|
memset(handle->buffer, 0, sizeof(handle->buffer));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * before we call ReadFileEx() because ReadFileEx() does not reset the last
|
|
|
+ * error itself when it's succesful. See comment below after the call to
|
|
|
+ * GetLastError(). */
|
|
|
+ SetLastError(0);
|
|
|
+
|
|
|
|
|
|
* the callback function when it is done. */
|
|
|
ret = ReadFileEx(handle->pipe,
|
|
@@ -901,6 +933,24 @@ process_win32_read_from_handle(process_win32_handle_t *handle,
|
|
|
return bytes_available;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * should check GetLastError() after a call to ReadFileEx() even though the
|
|
|
+ * `ret` return value was successful. If everything is good, GetLastError()
|
|
|
+ * returns `ERROR_SUCCESS` and nothing happens.
|
|
|
+ *
|
|
|
+ * XXX(ahf): I have not managed to trigger this code while stress-testing
|
|
|
+ * this code. */
|
|
|
+ error_code = GetLastError();
|
|
|
+
|
|
|
+ if (error_code != ERROR_SUCCESS) {
|
|
|
+
|
|
|
+ log_warn(LD_PROCESS, "ReadFileEx() failed after returning success: %s",
|
|
|
+ format_win32_error(error_code));
|
|
|
+ handle->reached_eof = true;
|
|
|
+ return bytes_available;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
handle->busy = true;
|
|
|
|