Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,38 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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.
#ifndef CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_
#define CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_
#include <mach/mach.h>
#include "util/numeric/checked_address_range.h"
namespace crashpad {
//! \brief Ensures that a range, composed of a base and a size, does not
//! overflow the pointer type of the process it describes a range in.
//!
//! This class checks bases of type `mach_vm_address_t` and sizes of type
//! `mach_vm_address_t` against a process whose pointer type is either 32 or 64
//! bits wide.
//!
//! Aside from varying the overall range on the basis of a process pointer type
//! width, this class functions very similarly to CheckedRange.
using CheckedMachAddressRange =
internal::CheckedAddressRangeGeneric<mach_vm_address_t, mach_vm_size_t>;
} // namespace crashpad
#endif // CRASHPAD_UTIL_MAC_CHECKED_MACH_ADDRESS_RANGE_H_
+148
View File
@@ -0,0 +1,148 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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.
#ifndef CRASHPAD_UTIL_MAC_LAUNCHD_H_
#define CRASHPAD_UTIL_MAC_LAUNCHD_H_
#include <CoreFoundation/CoreFoundation.h>
#include <launch.h>
#include <sys/types.h>
namespace crashpad {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
//! \{
//! \brief Wraps the `<launch.h>` function of the same name.
//!
//! The OS X 10.10 SDK deprecates `<launch.h>`, although the functionality it
//! provides is still useful. These wrappers allow the deprecated functions to
//! be called without triggering deprecated-declaration warnings.
inline launch_data_t LaunchDataAlloc(launch_data_type_t type) {
return launch_data_alloc(type);
}
inline launch_data_type_t LaunchDataGetType(const launch_data_t data) {
return launch_data_get_type(data);
}
inline void LaunchDataFree(launch_data_t data) {
return launch_data_free(data);
}
inline bool LaunchDataDictInsert(launch_data_t dict,
const launch_data_t value,
const char* key) {
return launch_data_dict_insert(dict, value, key);
}
inline launch_data_t LaunchDataDictLookup(const launch_data_t dict,
const char* key) {
return launch_data_dict_lookup(dict, key);
}
inline size_t LaunchDataDictGetCount(launch_data_t dict) {
return launch_data_dict_get_count(dict);
}
inline bool LaunchDataArraySetIndex(launch_data_t array,
const launch_data_t value,
size_t index) {
return launch_data_array_set_index(array, value, index);
}
inline launch_data_t LaunchDataArrayGetIndex(launch_data_t array,
size_t index) {
return launch_data_array_get_index(array, index);
}
inline size_t LaunchDataArrayGetCount(launch_data_t array) {
return launch_data_array_get_count(array);
}
inline launch_data_t LaunchDataNewInteger(long long integer) {
return launch_data_new_integer(integer);
}
inline launch_data_t LaunchDataNewBool(bool boolean) {
return launch_data_new_bool(boolean);
}
inline launch_data_t LaunchDataNewReal(double real) {
return launch_data_new_real(real);
}
inline launch_data_t LaunchDataNewString(const char* string) {
return launch_data_new_string(string);
}
inline launch_data_t LaunchDataNewOpaque(const void* opaque, size_t size) {
return launch_data_new_opaque(opaque, size);
}
inline long long LaunchDataGetInteger(const launch_data_t data) {
return launch_data_get_integer(data);
}
inline bool LaunchDataGetBool(const launch_data_t data) {
return launch_data_get_bool(data);
}
inline double LaunchDataGetReal(const launch_data_t data) {
return launch_data_get_real(data);
}
inline const char* LaunchDataGetString(const launch_data_t data) {
return launch_data_get_string(data);
}
inline void* LaunchDataGetOpaque(const launch_data_t data) {
return launch_data_get_opaque(data);
}
inline size_t LaunchDataGetOpaqueSize(const launch_data_t data) {
return launch_data_get_opaque_size(data);
}
inline int LaunchDataGetErrno(const launch_data_t data) {
return launch_data_get_errno(data);
}
inline launch_data_t LaunchMsg(const launch_data_t data) {
return launch_msg(data);
}
//! \}
#pragma clang diagnostic pop
//! \brief Converts a Core Foundation-type property list to a launchd-type
//! `launch_data_t`.
//!
//! \param[in] property_cf The Core Foundation-type property list to convert.
//!
//! \return The converted launchd-type `launch_data_t`. The caller takes
//! ownership of the returned value. On error, returns `nullptr`.
//!
//! \note This function handles all `CFPropertyListRef` types except for
//! `CFDateRef`, because theres no `launch_data_type_t` analogue. Not all
//! types supported in a launchd-type `launch_data_t` have
//! `CFPropertyListRef` analogues.
launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MAC_LAUNCHD_H_
@@ -0,0 +1,73 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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.
#ifndef CRASHPAD_UTIL_MAC_MAC_UTIL_H_
#define CRASHPAD_UTIL_MAC_MAC_UTIL_H_
#include <string>
namespace crashpad {
//! \brief Returns the version of the running operating system.
//!
//! \return The minor version of the operating system, such as `12` for macOS
//! 10.12.1.
//!
//! \note This is similar to the base::mac::IsOS*() family of functions, but
//! is provided for situations where the caller needs to obtain version
//! information beyond what is provided by Chromiums base, or for when the
//! caller needs the actual minor version value.
int MacOSXMinorVersion();
//! \brief Returns the version of the running operating system.
//!
//! All parameters are required. No parameter may be `nullptr`.
//!
//! \param[out] major The major version of the operating system, such as `10`
//! for macOS 10.12.1.
//! \param[out] minor The major version of the operating system, such as `12`
//! for macOS 10.12.1.
//! \param[out] bugfix The bugfix version of the operating system, such as `1`
//! for macOS 10.12.1.
//! \param[out] build The operating systems build string, such as `"16B2657"`
//! for macOS 10.12.1.
//! \param[out] server `true` for a macOS Server installation, `false` otherwise
//! (for a desktop/laptop, client, or workstation system).
//! \param[out] version_string A string representing the full operating system
//! version, such as `"macOS 10.12.1 (16B2657)"`.
//!
//! \return `true` on success, `false` on failure, with an error message logged.
//! A failure is considered to have occurred if any element could not be
//! determined. When this happens, their values will be untouched, but other
//! values that could be determined will still be set properly.
bool MacOSXVersion(int* major,
int* minor,
int* bugfix,
std::string* build,
bool* server,
std::string* version_string);
//! \brief Returns the model name and board ID of the running system.
//!
//! \param[out] model The systems model name. A mid-2012 15" MacBook Pro would
//! report “MacBookPro10,1”.
//! \param[out] board_id The systems board ID. A mid-2012 15" MacBook Pro would
//! report “Mac-C3EC7CD22292981F”.
//!
//! If a value cannot be determined, its string is cleared.
void MacModelAndBoard(std::string* model, std::string* board_id);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MAC_MAC_UTIL_H_
@@ -0,0 +1,80 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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.
#ifndef CRASHPAD_UTIL_MAC_SERVICE_MANAGEMENT_H_
#define CRASHPAD_UTIL_MAC_SERVICE_MANAGEMENT_H_
#include <CoreFoundation/CoreFoundation.h>
#include <unistd.h>
#include <string>
namespace crashpad {
//! \brief Submits a job to the user launchd domain as in `SMJobSubmit()`.
//!
//! \param[in] job_cf A dictionary describing a job.
//!
//! \return `true` if the job was submitted successfully, otherwise `false`.
//!
//! \note This function is provided because `SMJobSubmit()` is deprecated in OS
//! X 10.10. It may or may not be implemented using `SMJobSubmit()` from
//! `ServiceManagement.framework`.
bool ServiceManagementSubmitJob(CFDictionaryRef job_cf);
//! \brief Removes a job from the user launchd domain as in `SMJobRemove()`.
//!
//! \param[in] label The label for the job to remove.
//! \param[in] wait `true` if this function should block, waiting for the job to
//! be removed. `false` if the job may be removed asynchronously.
//!
//! \return `true` if the job was removed successfully or if an asynchronous
//! attempt to remove the job was started successfully, otherwise `false`.
//!
//! \note This function is provided because `SMJobRemove()` is deprecated in OS
//! X 10.10. On OS X 10.10, observed in DP8 14A361c, it also blocks for far
//! too long (`_block_until_job_exits()` contains a one-second `sleep()`,
//! filed as radar 18398683) and does not signal failure via its return
//! value when asked to remove a nonexistent job (filed as radar 18268941).
bool ServiceManagementRemoveJob(const std::string& label, bool wait);
//! \brief Determines whether a specified job is loaded in the user launchd
//! domain.
//!
//! \param[in] label The label for the job to look up.
//!
//! \return `true` if the job is loaded, otherwise `false`.
//!
//! \note A loaded job is not necessarily presently running, nor has it
//! necessarily ever run in the past.
//! \note This function is provided because `SMJobCopyDictionary()` is
//! deprecated in OS X 10.10. It may or may not be implemented using
//! `SMJobCopyDictionary()` from `ServiceManagement.framework`.
bool ServiceManagementIsJobLoaded(const std::string& label);
//! \brief Determines whether a specified job is running in the user launchd
//! domain.
//!
//! \param[in] label The label for the job to look up.
//!
//! \return The jobs process ID if running, otherwise `0`.
//!
//! \note This function is provided because `SMJobCopyDictionary()` is
//! deprecated in OS X 10.10. It may or may not be implemented using
//! `SMJobCopyDictionary()` from `ServiceManagement.framework`.
pid_t ServiceManagementIsJobRunning(const std::string& label);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MAC_SERVICE_MANAGEMENT
+106
View File
@@ -0,0 +1,106 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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.
#ifndef CRASHPAD_UTIL_MAC_XATTR_H_
#define CRASHPAD_UTIL_MAC_XATTR_H_
#include <time.h>
#include <string>
#include "base/files/file_path.h"
#include "base/strings/string_piece.h"
namespace crashpad {
//! \brief The result code for a ReadXattr operation.
enum class XattrStatus {
//! \brief No error occured. No message is logged.
kOK = 0,
//! \brief The attribute does not exist. No message is logged.
kNoAttribute,
//! \brief An error occurred and an error message was logged.
kOtherError,
};
//! \brief Reads an extended attribute on a file.
//!
//! \param[in] file The path to the file.
//! \param[in] name The name of the extended attribute to read.
//! \param[out] value The value of the attribute.
//!
//! \return XattrStatus
XattrStatus ReadXattr(const base::FilePath& file,
const base::StringPiece& name,
std::string* value);
//! \brief Writes an extended attribute on a file.
//!
//! \param[in] file The path to the file.
//! \param[in] name The name of the extended attribute to write.
//! \param[in] value The value of the attribute.
//!
//! \return `true` if the write was successful. `false` on error, with a message
//! logged.
bool WriteXattr(const base::FilePath& file,
const base::StringPiece& name,
const std::string& value);
//! \copydoc ReadXattr
//!
//! Only the values `"0"` and `"1"`, for `false` and `true` respectively, are
//! valid conversions.
XattrStatus ReadXattrBool(const base::FilePath& file,
const base::StringPiece& name,
bool* value);
//! \copydoc WriteXattr
bool WriteXattrBool(const base::FilePath& file,
const base::StringPiece& name,
bool value);
//! \copydoc ReadXattr
XattrStatus ReadXattrInt(const base::FilePath& file,
const base::StringPiece& name,
int* value);
//! \copydoc WriteXattr
bool WriteXattrInt(const base::FilePath& file,
const base::StringPiece& name,
int value);
//! \copydoc ReadXattr
XattrStatus ReadXattrTimeT(const base::FilePath& file,
const base::StringPiece& name,
time_t* value);
//! \copydoc WriteXattr
bool WriteXattrTimeT(const base::FilePath& file,
const base::StringPiece& name,
time_t value);
//! \brief Removes an extended attribute from a file.
//!
//! \param[in] file The path to the file.
//! \param[in] name The name of the extended attribute to remove.
//!
//! \return XattrStatus
XattrStatus RemoveXattr(const base::FilePath& file,
const base::StringPiece& name);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MAC_XATTR_H_