1 // Copyright 2019 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CRASHPAD_HANDLER_LINUX_CAPTURE_SNAPSHOT_H_
16 #define CRASHPAD_HANDLER_LINUX_CAPTURE_SNAPSHOT_H_
17 
18 #include <sys/types.h>
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include "snapshot/linux/process_snapshot_linux.h"
25 #include "snapshot/sanitized/process_snapshot_sanitized.h"
26 #include "util/linux/exception_handler_protocol.h"
27 #include "util/linux/ptrace_connection.h"
28 #include "util/misc/address_types.h"
29 
30 namespace crashpad {
31 
32 //! \brief Captures a snapshot of a client over \a connection.
33 //!
34 //! \param[in] connection A PtraceConnection to the client to snapshot.
35 //! \param[in] info Information about the client configuring the snapshot.
36 //! \param[in] process_annotations A map of annotations to insert as
37 //!     process-level annotations into the snapshot.
38 //! \param[in] client_uid The client's user ID.
39 //! \param[in] requesting_thread_stack_address An address on the stack of the
40 //!     thread requesting the snapshot. If \a info includes an exception
41 //!     address, the exception will be assigned to the thread whose stack
42 //!     address range contains this address. If 0, \a requesting_thread_id will
43 //!     be -1.
44 //! \param[out] requesting_thread_id The thread ID of the thread corresponding
45 //!     to \a requesting_thread_stack_address. Set to -1 if the thread ID could
46 //!     not be determined. Optional.
47 //! \param[out] process_snapshot A snapshot of the client process, valid if this
48 //!     function returns `true`.
49 //! \param[out] sanitized_snapshot A sanitized snapshot of the client process,
50 //!     valid if this function returns `true` and sanitization was requested in
51 //!     \a info.
52 //! \return `true` if \a process_snapshot was successfully created. A message
53 //!     will be logged on failure, but not if the snapshot was skipped because
54 //!     handling was disabled by CrashpadInfoClientOptions.
55 bool CaptureSnapshot(
56     PtraceConnection* connection,
57     const ExceptionHandlerProtocol::ClientInformation& info,
58     const std::map<std::string, std::string>& process_annotations,
59     uid_t client_uid,
60     VMAddress requesting_thread_stack_address,
61     pid_t* requesting_thread_id,
62     std::unique_ptr<ProcessSnapshotLinux>* process_snapshot,
63     std::unique_ptr<ProcessSnapshotSanitized>* sanitized_snapshot);
64 
65 }  // namespace crashpad
66 
67 #endif  // CRASHPAD_HANDLER_LINUX_CAPTURE_SNAPSHOT_H_
68