2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2016 The Crashpad Authors
|
2016-02-26 14:42:47 -08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2020-06-22 11:14:31 +02:00
|
|
|
#include "base/check.h"
|
2016-02-26 14:42:47 -08:00
|
|
|
#include "client/crashpad_info.h"
|
|
|
|
#include "util/file/file_io.h"
|
|
|
|
|
|
|
|
|
|
|
|
int wmain(int argc, wchar_t* argv[]) {
|
|
|
|
using namespace crashpad;
|
|
|
|
|
|
|
|
CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo();
|
|
|
|
|
|
|
|
// This is "leaked" to crashpad_info.
|
|
|
|
SimpleAddressRangeBag* extra_ranges = new SimpleAddressRangeBag();
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(0, 1));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(1, 0));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(0x1000000000ULL, 0x1000));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(0x2000, 0x2000000000ULL));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(1234, 5678));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(1234, 5678));
|
|
|
|
extra_ranges->Insert(CheckedRange<uint64_t>(1234, 5678));
|
|
|
|
crashpad_info->set_extra_memory_ranges(extra_ranges);
|
|
|
|
|
|
|
|
// Tell the parent that the environment has been set up.
|
|
|
|
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
PCHECK(out != INVALID_HANDLE_VALUE) << "GetStdHandle";
|
|
|
|
char c = ' ';
|
|
|
|
CheckedWriteFile(out, &c, sizeof(c));
|
|
|
|
|
|
|
|
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
PCHECK(in != INVALID_HANDLE_VALUE) << "GetStdHandle";
|
Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.
This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.
Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.
Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.
Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 13:36:38 -04:00
|
|
|
CheckedReadFileExactly(in, &c, sizeof(c));
|
2016-02-26 14:42:47 -08:00
|
|
|
CHECK(c == 'd' || c == ' ');
|
|
|
|
|
|
|
|
// If 'd' we crash with a debug break, otherwise exit normally.
|
|
|
|
if (c == 'd')
|
|
|
|
__debugbreak();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|