1 // Copyright (c) 2010 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "client/linux/crash_generation/crash_generation_client.h"
33 #include <sys/socket.h>
34 #include <sys/types.h>
38 #include "common/linux/eintr_wrapper.h"
39 #include "common/linux/ignore_ret.h"
40 #include "third_party/lss/linux_syscall_support.h"
42 namespace google_breakpad {
46 class CrashGenerationClientImpl : public CrashGenerationClient {
48 explicit CrashGenerationClientImpl(int server_fd) : server_fd_(server_fd) {}
49 virtual ~CrashGenerationClientImpl() {}
51 virtual bool RequestDump(const void* blob, size_t blob_size) {
53 if (sys_pipe(fds) < 0)
55 static const unsigned kControlMsgSize = CMSG_SPACE(sizeof(int));
57 struct kernel_iovec iov;
58 iov.iov_base = const_cast<void*>(blob);
59 iov.iov_len = blob_size;
61 struct kernel_msghdr msg = { 0 };
64 char cmsg[kControlMsgSize] = "";
65 msg.msg_control = cmsg;
66 msg.msg_controllen = sizeof(cmsg);
68 struct cmsghdr* hdr = CMSG_FIRSTHDR(&msg);
69 hdr->cmsg_level = SOL_SOCKET;
70 hdr->cmsg_type = SCM_RIGHTS;
71 hdr->cmsg_len = CMSG_LEN(sizeof(int));
72 int* p = reinterpret_cast<int*>(CMSG_DATA(hdr));
75 ssize_t ret = HANDLE_EINTR(sys_sendmsg(server_fd_, &msg, 0));
82 // Wait for an ACK from the server.
84 IGNORE_RET(HANDLE_EINTR(sys_read(fds[0], &b, 1)));
93 DISALLOW_COPY_AND_ASSIGN(CrashGenerationClientImpl);
99 CrashGenerationClient* CrashGenerationClient::TryCreate(int server_fd) {
102 return new CrashGenerationClientImpl(server_fd);
105 } // namespace google_breakpad