Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/win/registration_protocol_win.h" | 15 #include "util/win/registration_protocol_win.h" |
| 16 | 16 |
| 17 #include <windows.h> | 17 #include <windows.h> |
| 18 | 18 |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "util/win/scoped_handle.h" | 20 #include "util/win/scoped_handle.h" |
| 21 | 21 |
| 22 namespace crashpad { | 22 namespace crashpad { |
| 23 | 23 |
| 24 bool SendToCrashHandlerServer(const base::string16& pipe_name, | 24 bool SendToCrashHandlerServer(const base::string16& pipe_name, |
| 25 const crashpad::ClientToServerMessage& message, | 25 const crashpad::ClientToServerMessage& message, |
| 26 crashpad::ServerToClientMessage* response) { | 26 crashpad::ServerToClientMessage* response) { |
| 27 int tries = 0; | 27 // Retry CreateFile() in a loop. If the handler isn’t actively waiting in |
| 28 for (;;) { | 28 // ConnectNamedPipe() on a pipe instance because it’s busy doing something |
| 29 // else, CreateFile() will fail with ERROR_PIPE_BUSY. WaitNamedPipe() waits | |
| 30 // until a pipe instance is ready, but there’s no way to wait for this | |
| 31 // condition and atomically open the client side of the pipe in a single | |
| 32 // operation. CallNamedPipe() implements similar retry logic to this, also in | |
| 33 // user-mode code. | |
|
scottmg
2015/11/10 20:02:20
You could maybe also note that this means we don't
Mark Mentovai
2015/11/10 20:12:19
scottmg wrote:
| |
| 34 for (int tries = 0;;) { | |
| 29 ScopedFileHANDLE pipe( | 35 ScopedFileHANDLE pipe( |
| 30 CreateFile(pipe_name.c_str(), | 36 CreateFile(pipe_name.c_str(), |
| 31 GENERIC_READ | GENERIC_WRITE, | 37 GENERIC_READ | GENERIC_WRITE, |
| 32 0, | 38 0, |
| 33 nullptr, | 39 nullptr, |
| 34 OPEN_EXISTING, | 40 OPEN_EXISTING, |
| 35 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, | 41 SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, |
| 36 nullptr)); | 42 nullptr)); |
| 37 if (!pipe.is_valid()) { | 43 if (!pipe.is_valid()) { |
| 38 if (++tries == 5 || GetLastError() != ERROR_PIPE_BUSY) { | 44 if (++tries == 5 || GetLastError() != ERROR_PIPE_BUSY) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 58 BOOL result = TransactNamedPipe( | 64 BOOL result = TransactNamedPipe( |
| 59 pipe.get(), | 65 pipe.get(), |
| 60 // This is [in], but is incorrectly declared non-const. | 66 // This is [in], but is incorrectly declared non-const. |
| 61 const_cast<crashpad::ClientToServerMessage*>(&message), | 67 const_cast<crashpad::ClientToServerMessage*>(&message), |
| 62 sizeof(message), | 68 sizeof(message), |
| 63 response, | 69 response, |
| 64 sizeof(*response), | 70 sizeof(*response), |
| 65 &bytes_read, | 71 &bytes_read, |
| 66 nullptr); | 72 nullptr); |
| 67 if (!result) { | 73 if (!result) { |
| 74 PLOG(ERROR) << "TransactNamedPipe"; | |
| 75 return false; | |
| 76 } | |
| 77 if (bytes_read != sizeof(*response)) { | |
| 68 LOG(ERROR) << "TransactNamedPipe: expected " << sizeof(*response) | 78 LOG(ERROR) << "TransactNamedPipe: expected " << sizeof(*response) |
|
scottmg
2015/11/10 20:02:19
Duh, oops.
| |
| 69 << ", observed " << bytes_read; | 79 << ", observed " << bytes_read; |
| 70 return false; | 80 return false; |
| 71 } | 81 } |
| 72 if (bytes_read != sizeof(*response)) { | |
| 73 LOG(ERROR) << "TransactNamedPipe read incorrect number of bytes"; | |
| 74 return false; | |
| 75 } | |
| 76 return true; | 82 return true; |
| 77 } | 83 } |
| 78 } | 84 } |
| 79 | 85 |
| 80 } // namespace crashpad | 86 } // namespace crashpad |
| OLD | NEW |