2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2021 The Crashpad Authors
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04: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 "util/ios/ios_intermediate_dump_writer.h"
|
|
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2022-07-14 13:41:55 -04:00
|
|
|
|
#include <mach/mach.h>
|
2022-07-24 12:09:07 -04:00
|
|
|
|
#include <string.h>
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2022-07-14 13:41:55 -04:00
|
|
|
|
#include <algorithm>
|
2022-05-22 15:08:03 +00:00
|
|
|
|
#include <ostream>
|
|
|
|
|
|
2022-05-17 15:18:21 -06:00
|
|
|
|
#include "base/check.h"
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
#include "base/posix/eintr_wrapper.h"
|
|
|
|
|
#include "build/build_config.h"
|
|
|
|
|
#include "util/ios/raw_logging.h"
|
|
|
|
|
#include "util/ios/scoped_vm_read.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
// Similar to LoggingWriteFile but with CRASHPAD_RAW_LOG.
|
2022-07-24 12:09:07 -04:00
|
|
|
|
bool RawLoggingWriteFile(int fd, const void* data, size_t size) {
|
|
|
|
|
const char* data_char = static_cast<const char*>(data);
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
while (size > 0) {
|
2022-07-24 12:09:07 -04:00
|
|
|
|
ssize_t bytes_written = HANDLE_EINTR(write(fd, data_char, size));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
if (bytes_written < 0 || bytes_written == 0) {
|
|
|
|
|
CRASHPAD_RAW_LOG_ERROR(bytes_written, "RawLoggingWriteFile");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-07-24 12:09:07 -04:00
|
|
|
|
data_char += bytes_written;
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
size -= bytes_written;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Similar to LoggingCloseFile but with CRASHPAD_RAW_LOG.
|
|
|
|
|
bool RawLoggingCloseFile(int fd) {
|
|
|
|
|
int rv = IGNORE_EINTR(close(fd));
|
|
|
|
|
if (rv != 0) {
|
|
|
|
|
CRASHPAD_RAW_LOG_ERROR(rv, "RawLoggingCloseFile");
|
|
|
|
|
}
|
|
|
|
|
return rv == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 15:18:21 -06:00
|
|
|
|
IOSIntermediateDumpWriter::~IOSIntermediateDumpWriter() {
|
2022-07-24 12:09:07 -04:00
|
|
|
|
CHECK_EQ(fd_, -1) << "Call Close() before this object is destroyed.";
|
2022-05-17 15:18:21 -06:00
|
|
|
|
}
|
|
|
|
|
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
bool IOSIntermediateDumpWriter::Open(const base::FilePath& path) {
|
|
|
|
|
// Set data protection class D (No protection). A file with this type of
|
|
|
|
|
// protection can be read from or written to at any time.
|
|
|
|
|
// See:
|
|
|
|
|
// https://support.apple.com/guide/security/data-protection-classes-secb010e978a/web
|
|
|
|
|
constexpr int PROTECTION_CLASS_D = 4;
|
|
|
|
|
fd_ = HANDLE_EINTR(open_dprotected_np(path.value().c_str(),
|
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC,
|
|
|
|
|
PROTECTION_CLASS_D,
|
|
|
|
|
0 /* dpflags */,
|
|
|
|
|
0644 /* mode */));
|
|
|
|
|
if (fd_ < 0) {
|
|
|
|
|
CRASHPAD_RAW_LOG_ERROR(fd_, "open intermediate dump");
|
|
|
|
|
CRASHPAD_RAW_LOG(path.value().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 13:53:37 -04:00
|
|
|
|
return true;
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::Close() {
|
2022-05-17 15:18:21 -06:00
|
|
|
|
if (fd_ < 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-04-10 14:19:23 -04:00
|
|
|
|
const bool flushed = FlushWriteBuffer();
|
|
|
|
|
const bool closed = RawLoggingCloseFile(fd_);
|
2022-05-17 15:18:21 -06:00
|
|
|
|
fd_ = -1;
|
2023-04-10 14:19:23 -04:00
|
|
|
|
return flushed && closed;
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 13:41:55 -04:00
|
|
|
|
bool IOSIntermediateDumpWriter::AddPropertyCString(IntermediateDumpKey key,
|
|
|
|
|
size_t max_length,
|
|
|
|
|
const char* value) {
|
|
|
|
|
constexpr size_t kMaxStringBytes = 1024;
|
|
|
|
|
if (max_length > kMaxStringBytes) {
|
|
|
|
|
CRASHPAD_RAW_LOG("AddPropertyCString max_length too large");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char buffer[kMaxStringBytes];
|
|
|
|
|
size_t string_length;
|
|
|
|
|
if (ReadCStringInternal(value, buffer, max_length, &string_length)) {
|
|
|
|
|
return Property(key, buffer, string_length);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::ReadCStringInternal(const char* value,
|
|
|
|
|
char* buffer,
|
|
|
|
|
size_t max_length,
|
|
|
|
|
size_t* string_length) {
|
|
|
|
|
size_t length = 0;
|
|
|
|
|
while (length < max_length) {
|
|
|
|
|
vm_address_t data_address = reinterpret_cast<vm_address_t>(value + length);
|
|
|
|
|
// Calculate bytes to read past `data_address`, either the number of bytes
|
|
|
|
|
// to the end of the page, or the remaining bytes in `buffer`, whichever is
|
|
|
|
|
// smaller.
|
|
|
|
|
size_t data_to_end_of_page =
|
|
|
|
|
getpagesize() - (data_address - trunc_page(data_address));
|
|
|
|
|
size_t remaining_bytes_in_buffer = max_length - length;
|
|
|
|
|
size_t bytes_to_read =
|
|
|
|
|
std::min(data_to_end_of_page, remaining_bytes_in_buffer);
|
|
|
|
|
|
|
|
|
|
char* buffer_start = buffer + length;
|
|
|
|
|
size_t bytes_read = 0;
|
|
|
|
|
kern_return_t kr =
|
|
|
|
|
vm_read_overwrite(mach_task_self(),
|
|
|
|
|
data_address,
|
|
|
|
|
bytes_to_read,
|
|
|
|
|
reinterpret_cast<vm_address_t>(buffer_start),
|
|
|
|
|
&bytes_read);
|
|
|
|
|
if (kr != KERN_SUCCESS || bytes_read <= 0) {
|
|
|
|
|
CRASHPAD_RAW_LOG("ReadCStringInternal vm_read_overwrite failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* nul = static_cast<char*>(memchr(buffer_start, '\0', bytes_read));
|
|
|
|
|
if (nul != nullptr) {
|
|
|
|
|
length += nul - buffer_start;
|
|
|
|
|
*string_length = length;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
length += bytes_read;
|
|
|
|
|
}
|
|
|
|
|
CRASHPAD_RAW_LOG("unterminated string");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::AddPropertyInternal(IntermediateDumpKey key,
|
|
|
|
|
const char* value,
|
|
|
|
|
size_t value_length) {
|
|
|
|
|
ScopedVMRead<char> vmread;
|
|
|
|
|
if (!vmread.Read(value, value_length))
|
|
|
|
|
return false;
|
|
|
|
|
return Property(key, vmread.get(), value_length);
|
|
|
|
|
}
|
|
|
|
|
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
bool IOSIntermediateDumpWriter::ArrayMapStart() {
|
|
|
|
|
const CommandType command_type = CommandType::kMapStart;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::MapStart(IntermediateDumpKey key) {
|
|
|
|
|
const CommandType command_type = CommandType::kMapStart;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type)) &&
|
|
|
|
|
BufferedWrite(&key, sizeof(key));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::ArrayStart(IntermediateDumpKey key) {
|
|
|
|
|
const CommandType command_type = CommandType::kArrayStart;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type)) &&
|
|
|
|
|
BufferedWrite(&key, sizeof(key));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::MapEnd() {
|
|
|
|
|
const CommandType command_type = CommandType::kMapEnd;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::ArrayEnd() {
|
|
|
|
|
const CommandType command_type = CommandType::kArrayEnd;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::RootMapStart() {
|
|
|
|
|
const CommandType command_type = CommandType::kRootMapStart;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::RootMapEnd() {
|
|
|
|
|
const CommandType command_type = CommandType::kRootMapEnd;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type));
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 13:41:55 -04:00
|
|
|
|
bool IOSIntermediateDumpWriter::Property(IntermediateDumpKey key,
|
|
|
|
|
const void* value,
|
|
|
|
|
size_t value_length) {
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
const CommandType command_type = CommandType::kProperty;
|
2022-07-24 12:09:07 -04:00
|
|
|
|
return BufferedWrite(&command_type, sizeof(command_type)) &&
|
|
|
|
|
BufferedWrite(&key, sizeof(key)) &&
|
|
|
|
|
BufferedWrite(&value_length, sizeof(size_t)) &&
|
|
|
|
|
BufferedWrite(value, value_length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::FlushWriteBuffer() {
|
|
|
|
|
size_t size = buffer_occupied_;
|
|
|
|
|
buffer_occupied_ = 0;
|
|
|
|
|
return RawLoggingWriteFile(fd_, buffer_, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IOSIntermediateDumpWriter::BufferedWrite(const void* data,
|
|
|
|
|
size_t data_size) {
|
|
|
|
|
const char* data_char = static_cast<const char*>(data);
|
|
|
|
|
// If `buffer_` is occupied, fill it up first, and flush if full.
|
|
|
|
|
if (buffer_occupied_ > 0) {
|
|
|
|
|
size_t data_size_to_copy =
|
|
|
|
|
std::min(kBufferSize - buffer_occupied_, data_size);
|
|
|
|
|
memcpy(buffer_ + buffer_occupied_, data_char, data_size_to_copy);
|
|
|
|
|
buffer_occupied_ += data_size_to_copy;
|
|
|
|
|
data_char += data_size_to_copy;
|
|
|
|
|
data_size -= data_size_to_copy;
|
|
|
|
|
|
|
|
|
|
if (buffer_occupied_ == kBufferSize) {
|
|
|
|
|
if (!FlushWriteBuffer()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Either `data_size` is big enough that it could fill `buffer_`, trigger
|
|
|
|
|
// a FlushWriteBuffer, and reset `buffer_occuppied_` to zero, or there is no
|
|
|
|
|
// data left to process.
|
|
|
|
|
DCHECK(buffer_occupied_ == 0 || data_size == 0);
|
|
|
|
|
|
|
|
|
|
// Write the rest of the `data` in an increment of kBufferSize.
|
|
|
|
|
if (data_size >= kBufferSize) {
|
|
|
|
|
DCHECK_EQ(buffer_occupied_, 0u);
|
|
|
|
|
size_t data_size_to_write = data_size - (data_size % kBufferSize);
|
|
|
|
|
if (!RawLoggingWriteFile(fd_, data_char, data_size_to_write)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
data_char += data_size_to_write;
|
|
|
|
|
data_size -= data_size_to_write;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there's any `data` left, put it in `buffer_`.
|
|
|
|
|
if (data_size > 0) {
|
|
|
|
|
DCHECK_EQ(buffer_occupied_, 0u);
|
|
|
|
|
memcpy(buffer_, data_char, data_size);
|
|
|
|
|
buffer_occupied_ = data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
ios: Add support for intermediate dump reader and writer.
Due to the limitations of in-process handling, an intermediate dump file
is written during exceptions. The data is streamed to a file using only
in-process safe methods. The file format is similar to binary JSON,
supporting keyed properties, maps and arrays.
- Property [key:int, length:int, value:intarray]
- StartMap [key:int], followed by repeating Properties until EndMap
- StartArray [key:int], followed by repeating Maps until EndArray
- EndMap, EndArray, EndDocument
Similar to JSON, maps can contain other maps, arrays and properties.
Once loaded, the binary file is read into a set of data structures that
expose the data, maps and arrays.
Bug: crashpad: 31
Change-Id: I43a19204935303afd753c8c7090c54099634ccd6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2870807
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2021-05-20 11:10:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
} // namespace crashpad
|