1From 7975a962e1d6dbad5a46792a54e647abd7caf5f1 Mon Sep 17 00:00:00 2001
2From: Mark Mentovai <mark@chromium.org>
3Date: Tue, 19 Sep 2017 22:48:30 -0400
4Subject: [PATCH] Replace remaining references to 'struct ucontext' with
5 'ucontext_t'
6
7This relands
8https://chromium.googlesource.com/breakpad/breakpad/src/+/e3035bc406cee8a4d765e59ad46eb828705f17f4,
9which was accidentally committed to breakpad/breakpad/src, the read-only
10mirror of src in breakpad/breakpad. (Well, it should have been
11read-only.) See https://crbug.com/766164.
12
13This fixes issues with glibc-2.26.
14
15See https://bugs.gentoo.org/show_bug.cgi?id=628782 ,
16https://sourceware.org/git/?p=glibc.git;h=251287734e89a52da3db682a8241eb6bccc050c9 , and
17https://sourceware.org/ml/libc-alpha/2017-08/msg00010.html for context.
18Change-Id: Id66f474d636dd2afa450bab925c5514a800fdd6f
19Reviewed-on: https://chromium-review.googlesource.com/674304
20Reviewed-by: Mark Mentovai <mark@chromium.org>
21
22(cherry picked from commit bddcc58860f522a0d4cbaa7e9d04058caee0db9d)
23[Romain: backport from upstream]
24Signed-off-by: Romain Naour <romain.naour@gmail.com>
25---
26 .../linux/dump_writer_common/ucontext_reader.cc    | 32 +++++++++++-----------
27 .../linux/dump_writer_common/ucontext_reader.h     | 14 +++++-----
28 src/client/linux/handler/exception_handler.cc      | 10 +++----
29 src/client/linux/handler/exception_handler.h       |  6 ++--
30 .../linux/microdump_writer/microdump_writer.cc     |  2 +-
31 .../linux/minidump_writer/minidump_writer.cc       |  2 +-
32 6 files changed, 33 insertions(+), 33 deletions(-)
33
34diff --git a/src/client/linux/dump_writer_common/ucontext_reader.cc b/src/client/linux/dump_writer_common/ucontext_reader.cc
35index c80724d..052ce37 100644
36--- a/src/client/linux/dump_writer_common/ucontext_reader.cc
37+++ b/src/client/linux/dump_writer_common/ucontext_reader.cc
38@@ -36,19 +36,19 @@ namespace google_breakpad {
39
40 // Minidump defines register structures which are different from the raw
41 // structures which we get from the kernel. These are platform specific
42-// functions to juggle the ucontext and user structures into minidump format.
43+// functions to juggle the ucontext_t and user structures into minidump format.
44
45 #if defined(__i386__)
46
47-uintptr_t UContextReader::GetStackPointer(const struct ucontext* uc) {
48+uintptr_t UContextReader::GetStackPointer(const ucontext_t* uc) {
49   return uc->uc_mcontext.gregs[REG_ESP];
50 }
51
52-uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) {
53+uintptr_t UContextReader::GetInstructionPointer(const ucontext_t* uc) {
54   return uc->uc_mcontext.gregs[REG_EIP];
55 }
56
57-void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
58+void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext_t *uc,
59                                     const struct _libc_fpstate* fp) {
60   const greg_t* regs = uc->uc_mcontext.gregs;
61
62@@ -88,15 +88,15 @@ void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
63
64 #elif defined(__x86_64)
65
66-uintptr_t UContextReader::GetStackPointer(const struct ucontext* uc) {
67+uintptr_t UContextReader::GetStackPointer(const ucontext_t* uc) {
68   return uc->uc_mcontext.gregs[REG_RSP];
69 }
70
71-uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) {
72+uintptr_t UContextReader::GetInstructionPointer(const ucontext_t* uc) {
73   return uc->uc_mcontext.gregs[REG_RIP];
74 }
75
76-void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
77+void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext_t *uc,
78                                     const struct _libc_fpstate* fpregs) {
79   const greg_t* regs = uc->uc_mcontext.gregs;
80
81@@ -145,15 +145,15 @@ void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
82
83 #elif defined(__ARM_EABI__)
84
85-uintptr_t UContextReader::GetStackPointer(const struct ucontext* uc) {
86+uintptr_t UContextReader::GetStackPointer(const ucontext_t* uc) {
87   return uc->uc_mcontext.arm_sp;
88 }
89
90-uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) {
91+uintptr_t UContextReader::GetInstructionPointer(const ucontext_t* uc) {
92   return uc->uc_mcontext.arm_pc;
93 }
94
95-void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc) {
96+void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext_t *uc) {
97   out->context_flags = MD_CONTEXT_ARM_FULL;
98
99   out->iregs[0] = uc->uc_mcontext.arm_r0;
100@@ -184,15 +184,15 @@ void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc) {
101
102 #elif defined(__aarch64__)
103
104-uintptr_t UContextReader::GetStackPointer(const struct ucontext* uc) {
105+uintptr_t UContextReader::GetStackPointer(const ucontext_t* uc) {
106   return uc->uc_mcontext.sp;
107 }
108
109-uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) {
110+uintptr_t UContextReader::GetInstructionPointer(const ucontext_t* uc) {
111   return uc->uc_mcontext.pc;
112 }
113
114-void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
115+void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext_t *uc,
116                                     const struct fpsimd_context* fpregs) {
117   out->context_flags = MD_CONTEXT_ARM64_FULL;
118
119@@ -210,15 +210,15 @@ void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc,
120
121 #elif defined(__mips__)
122
123-uintptr_t UContextReader::GetStackPointer(const struct ucontext* uc) {
124+uintptr_t UContextReader::GetStackPointer(const ucontext_t* uc) {
125   return uc->uc_mcontext.gregs[MD_CONTEXT_MIPS_REG_SP];
126 }
127
128-uintptr_t UContextReader::GetInstructionPointer(const struct ucontext* uc) {
129+uintptr_t UContextReader::GetInstructionPointer(const ucontext_t* uc) {
130   return uc->uc_mcontext.pc;
131 }
132
133-void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext *uc) {
134+void UContextReader::FillCPUContext(RawContextCPU *out, const ucontext_t *uc) {
135 #if _MIPS_SIM == _ABI64
136   out->context_flags = MD_CONTEXT_MIPS64_FULL;
137 #elif _MIPS_SIM == _ABIO32
138diff --git a/src/client/linux/dump_writer_common/ucontext_reader.h b/src/client/linux/dump_writer_common/ucontext_reader.h
139index b6e77b4..2de80b7 100644
140--- a/src/client/linux/dump_writer_common/ucontext_reader.h
141+++ b/src/client/linux/dump_writer_common/ucontext_reader.h
142@@ -39,23 +39,23 @@
143
144 namespace google_breakpad {
145
146-// Wraps platform-dependent implementations of accessors to ucontext structs.
147+// Wraps platform-dependent implementations of accessors to ucontext_t structs.
148 struct UContextReader {
149-  static uintptr_t GetStackPointer(const struct ucontext* uc);
150+  static uintptr_t GetStackPointer(const ucontext_t* uc);
151
152-  static uintptr_t GetInstructionPointer(const struct ucontext* uc);
153+  static uintptr_t GetInstructionPointer(const ucontext_t* uc);
154
155-  // Juggle a arch-specific ucontext into a minidump format
156+  // Juggle a arch-specific ucontext_t into a minidump format
157   //   out: the minidump structure
158   //   info: the collection of register structures.
159 #if defined(__i386__) || defined(__x86_64)
160-  static void FillCPUContext(RawContextCPU *out, const ucontext *uc,
161+  static void FillCPUContext(RawContextCPU *out, const ucontext_t *uc,
162                              const struct _libc_fpstate* fp);
163 #elif defined(__aarch64__)
164-  static void FillCPUContext(RawContextCPU *out, const ucontext *uc,
165+  static void FillCPUContext(RawContextCPU *out, const ucontext_t *uc,
166                              const struct fpsimd_context* fpregs);
167 #else
168-  static void FillCPUContext(RawContextCPU *out, const ucontext *uc);
169+  static void FillCPUContext(RawContextCPU *out, const ucontext_t *uc);
170 #endif
171 };
172
173diff --git a/src/client/linux/handler/exception_handler.cc b/src/client/linux/handler/exception_handler.cc
174index b63f973..3d809b8 100644
175--- a/src/client/linux/handler/exception_handler.cc
176+++ b/src/client/linux/handler/exception_handler.cc
177@@ -439,9 +439,9 @@ bool ExceptionHandler::HandleSignal(int sig, siginfo_t* info, void* uc) {
178   // Fill in all the holes in the struct to make Valgrind happy.
179   memset(&g_crash_context_, 0, sizeof(g_crash_context_));
180   memcpy(&g_crash_context_.siginfo, info, sizeof(siginfo_t));
181-  memcpy(&g_crash_context_.context, uc, sizeof(struct ucontext));
182+  memcpy(&g_crash_context_.context, uc, sizeof(ucontext_t));
183 #if defined(__aarch64__)
184-  struct ucontext* uc_ptr = (struct ucontext*)uc;
185+  ucontext_t* uc_ptr = (ucontext_t*)uc;
186   struct fpsimd_context* fp_ptr =
187       (struct fpsimd_context*)&uc_ptr->uc_mcontext.__reserved;
188   if (fp_ptr->head.magic == FPSIMD_MAGIC) {
189@@ -450,9 +450,9 @@ bool ExceptionHandler::HandleSignal(int sig, siginfo_t* info, void* uc) {
190   }
191 #elif !defined(__ARM_EABI__) && !defined(__mips__)
192   // FP state is not part of user ABI on ARM Linux.
193-  // In case of MIPS Linux FP state is already part of struct ucontext
194+  // In case of MIPS Linux FP state is already part of ucontext_t
195   // and 'float_state' is not a member of CrashContext.
196-  struct ucontext* uc_ptr = (struct ucontext*)uc;
197+  ucontext_t* uc_ptr = (ucontext_t*)uc;
198   if (uc_ptr->uc_mcontext.fpregs) {
199     memcpy(&g_crash_context_.float_state, uc_ptr->uc_mcontext.fpregs,
200            sizeof(g_crash_context_.float_state));
201@@ -476,7 +476,7 @@ bool ExceptionHandler::SimulateSignalDelivery(int sig) {
202   // ExceptionHandler::HandleSignal().
203   siginfo.si_code = SI_USER;
204   siginfo.si_pid = getpid();
205-  struct ucontext context;
206+  ucontext_t context;
207   getcontext(&context);
208   return HandleSignal(sig, &siginfo, &context);
209 }
210diff --git a/src/client/linux/handler/exception_handler.h b/src/client/linux/handler/exception_handler.h
211index 591c310..42f4055 100644
212--- a/src/client/linux/handler/exception_handler.h
213+++ b/src/client/linux/handler/exception_handler.h
214@@ -191,11 +191,11 @@ class ExceptionHandler {
215   struct CrashContext {
216     siginfo_t siginfo;
217     pid_t tid;  // the crashing thread.
218-    struct ucontext context;
219+    ucontext_t context;
220 #if !defined(__ARM_EABI__) && !defined(__mips__)
221     // #ifdef this out because FP state is not part of user ABI for Linux ARM.
222-    // In case of MIPS Linux FP state is already part of struct
223-    // ucontext so 'float_state' is not required.
224+    // In case of MIPS Linux FP state is already part of ucontext_t so
225+    // 'float_state' is not required.
226     fpstate_t float_state;
227 #endif
228   };
229diff --git a/src/client/linux/microdump_writer/microdump_writer.cc b/src/client/linux/microdump_writer/microdump_writer.cc
230index 6f5b435..a508667 100644
231--- a/src/client/linux/microdump_writer/microdump_writer.cc
232+++ b/src/client/linux/microdump_writer/microdump_writer.cc
233@@ -571,7 +571,7 @@ class MicrodumpWriter {
234
235   void* Alloc(unsigned bytes) { return dumper_->allocator()->Alloc(bytes); }
236
237-  const struct ucontext* const ucontext_;
238+  const ucontext_t* const ucontext_;
239 #if !defined(__ARM_EABI__) && !defined(__mips__)
240   const google_breakpad::fpstate_t* const float_state_;
241 #endif
242diff --git a/src/client/linux/minidump_writer/minidump_writer.cc b/src/client/linux/minidump_writer/minidump_writer.cc
243index 86009b9..f2aec73 100644
244--- a/src/client/linux/minidump_writer/minidump_writer.cc
245+++ b/src/client/linux/minidump_writer/minidump_writer.cc
246@@ -1248,7 +1248,7 @@ class MinidumpWriter {
247   const int fd_;  // File descriptor where the minidum should be written.
248   const char* path_;  // Path to the file where the minidum should be written.
249
250-  const struct ucontext* const ucontext_;  // also from the signal handler
251+  const ucontext_t* const ucontext_;  // also from the signal handler
252 #if !defined(__ARM_EABI__) && !defined(__mips__)
253   const google_breakpad::fpstate_t* const float_state_;  // ditto
254 #endif
255--
2562.9.5
257
258