Merge lp:~michaelh1/ubuntu/precise/eglibc/lp696794 into lp:ubuntu/precise/eglibc

Proposed by Michael Hope
Status: Merged
Merge reported by: Adam Conrad
Merged at revision: not available
Proposed branch: lp:~michaelh1/ubuntu/precise/eglibc/lp696794
Merge into: lp:ubuntu/precise/eglibc
Diff against target: 466 lines (+443/-0)
3 files modified
debian/changelog (+6/-0)
debian/patches/arm/cvs-makecontext.diff (+436/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~michaelh1/ubuntu/precise/eglibc/lp696794
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+96468@code.launchpad.net

This proposal supersedes a proposal from 2012-03-07.

Description of the change

eglibc (2.15-0ubuntu5) precise; urgency=low

  * Backport ARM makecontext() routines. LP: #696794

The makecontext() family are used in qemu, GNU pth, and libgo for user space coroutines.

Any chance of adding this to Precise? It's committed upstream, ARM only, self contained, doesn't change the ABI (past versions had a stub implementations that returned error), passes the glibc tests, and passes the pth tests. The advantage is that Precise will better support KVM virtualisation on ARM when it arrives.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-02-27 10:21:40 +0000
3+++ debian/changelog 2012-03-07 22:03:19 +0000
4@@ -1,3 +1,9 @@
5+eglibc (2.15-0ubuntu5) precise; urgency=low
6+
7+ * Backport ARM makecontext() routines. LP: #696794
8+
9+ -- Michael Hope <michael.hope@linaro.org> Wed, 07 Mar 2012 09:32:39 +1300
10+
11 eglibc (2.15-0ubuntu4) precise; urgency=low
12
13 * Merge from Debian (r5173, 2.13-27).
14
15=== added file 'debian/patches/arm/cvs-makecontext.diff'
16--- debian/patches/arm/cvs-makecontext.diff 1970-01-01 00:00:00 +0000
17+++ debian/patches/arm/cvs-makecontext.diff 2012-03-07 22:03:19 +0000
18@@ -0,0 +1,436 @@
19+commit 402a76b62dded0ee93cfec0471aaeccb989196d2
20+Author: Michael Hope <michael.hope@linaro.org>
21+Date: Mon Mar 5 17:58:13 2012 -0500
22+
23+ ARM: Implement *context routines.
24+
25+ * sysdeps/unix/sysv/linux/arm/eabi/getcontext.S: New file.
26+ * sysdeps/unix/sysv/linux/arm/eabi/makecontext.c: New file.
27+ * sysdeps/unix/sysv/linux/arm/eabi/setcontext.S: New file.
28+ * sysdeps/unix/sysv/linux/arm/eabi/swapcontext.S: New file.
29+ * sysdeps/unix/sysv/linux/arm/ucontext_i.sym: New file.
30+ * sysdeps/unix/sysv/linux/arm/Makefile (gen-as-const-headers): Add
31+ ucontext_i.sym.
32+
33+diff --git a/ports/sysdeps/unix/sysv/linux/arm/Makefile b/ports/sysdeps/unix/sysv/linux/arm/Makefile
34+index d91b968..a981736 100644
35+--- a/ports/sysdeps/unix/sysv/linux/arm/Makefile
36++++ b/ports/sysdeps/unix/sysv/linux/arm/Makefile
37+@@ -20,3 +20,7 @@ endif
38+ ifeq ($(subdir),resource)
39+ sysdep_routines += oldgetrlimit64
40+ endif
41++
42++ifeq ($(subdir),stdlib)
43++gen-as-const-headers += ucontext_i.sym
44++endif
45+diff --git a/ports/sysdeps/unix/sysv/linux/arm/eabi/getcontext.S b/ports/sysdeps/unix/sysv/linux/arm/eabi/getcontext.S
46+new file mode 100644
47+index 0000000..435eb12
48+--- /dev/null
49++++ b/ports/sysdeps/unix/sysv/linux/arm/eabi/getcontext.S
50+@@ -0,0 +1,113 @@
51++/* Copyright (C) 2012 Free Software Foundation, Inc.
52++ This file is part of the GNU C Library.
53++
54++ The GNU C Library is free software; you can redistribute it and/or
55++ modify it under the terms of the GNU Lesser General Public
56++ License as published by the Free Software Foundation; either
57++ version 2.1 of the License, or (at your option) any later version.
58++
59++ The GNU C Library is distributed in the hope that it will be useful,
60++ but WITHOUT ANY WARRANTY; without even the implied warranty of
61++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
62++ Lesser General Public License for more details.
63++
64++ You should have received a copy of the GNU Lesser General Public
65++ License along with the GNU C Library; if not, see
66++ <http://www.gnu.org/licenses/>. */
67++
68++#include <sysdep.h>
69++#include <rtld-global-offsets.h>
70++
71++#include "ucontext_i.h"
72++
73++ .syntax unified
74++ .text
75++
76++/* int getcontext (ucontext_t *ucp) */
77++
78++ENTRY(__getcontext)
79++ /* No need to save r0-r3, d0-d7, or d16-d31. */
80++ add r1, r0, #MCONTEXT_ARM_R4
81++ stmia r1, {r4-r11}
82++
83++ /* Save R13 separately as Thumb can't STM it. */
84++ str r13, [r0, #MCONTEXT_ARM_SP]
85++ str r14, [r0, #MCONTEXT_ARM_LR]
86++ /* Return to LR */
87++ str r14, [r0, #MCONTEXT_ARM_PC]
88++ /* Return zero */
89++ mov r2, #0
90++ str r2, [r0, #MCONTEXT_ARM_R0]
91++
92++ /* Save ucontext_t * across the next call. */
93++ mov r4, r0
94++
95++ /* __sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */
96++ mov r0, #SIG_BLOCK
97++ mov r1, #0
98++ add r2, r4, #UCONTEXT_SIGMASK
99++ bl PLTJMP(__sigprocmask)
100++
101++ /* Store FP regs. Much of the FP code is copied from arm/eabi/setjmp.S. */
102++
103++#ifdef PIC
104++ ldr r2, 1f
105++ ldr r1, Lrtld_global_ro
106++0: add r2, pc, r2
107++ ldr r2, [r2, r1]
108++ ldr r2, [r2, #RTLD_GLOBAL_RO_DL_HWCAP_OFFSET]
109++#else
110++ ldr r2, Lhwcap
111++ ldr r2, [r2, #0]
112++#endif
113++
114++ add r0, r4, #UCONTEXT_REGSPACE
115++
116++ tst r2, #HWCAP_ARM_VFP
117++ beq Lno_vfp
118++
119++ /* Store the VFP registers.
120++ Don't use VFP instructions directly because this code
121++ is used in non-VFP multilibs. */
122++ /* Following instruction is vstmia r0!, {d8-d15}. */
123++ stc p11, cr8, [r0], #64
124++ /* Store the floating-point status register. */
125++ /* Following instruction is vmrs r1, fpscr. */
126++ mrc p10, 7, r1, cr1, cr0, 0
127++ str r1, [r0], #4
128++Lno_vfp:
129++
130++ tst r2, #HWCAP_ARM_IWMMXT
131++ beq Lno_iwmmxt
132++
133++ /* Save the call-preserved iWMMXt registers. */
134++ /* Following instructions are wstrd wr10, [r0], #8 (etc.) */
135++ stcl p1, cr10, [r0], #8
136++ stcl p1, cr11, [r0], #8
137++ stcl p1, cr12, [r0], #8
138++ stcl p1, cr13, [r0], #8
139++ stcl p1, cr14, [r0], #8
140++ stcl p1, cr15, [r0], #8
141++Lno_iwmmxt:
142++
143++ /* Restore the clobbered R4 and LR. */
144++ ldr r14, [r4, #MCONTEXT_ARM_LR]
145++ ldr r4, [r4, #MCONTEXT_ARM_R4]
146++
147++ mov r0, #0
148++
149++ DO_RET(r14)
150++
151++END(__getcontext)
152++
153++#ifdef PIC
154++1: .long _GLOBAL_OFFSET_TABLE_ - 0b - 8
155++Lrtld_global_ro:
156++ .long C_SYMBOL_NAME(_rtld_global_ro)(GOT)
157++#else
158++Lhwcap:
159++ .long C_SYMBOL_NAME(_dl_hwcap)
160++#endif
161++
162++
163++weak_alias(__getcontext, getcontext)
164+diff --git a/ports/sysdeps/unix/sysv/linux/arm/eabi/makecontext.c b/ports/sysdeps/unix/sysv/linux/arm/eabi/makecontext.c
165+new file mode 100644
166+index 0000000..d6ae6f0
167+--- /dev/null
168++++ b/ports/sysdeps/unix/sysv/linux/arm/eabi/makecontext.c
169+@@ -0,0 +1,73 @@
170++/* Copyright (C) 2012 Free Software Foundation, Inc.
171++ This file is part of the GNU C Library.
172++
173++ The GNU C Library is free software; you can redistribute it and/or
174++ modify it under the terms of the GNU Lesser General Public
175++ License as published by the Free Software Foundation; either
176++ version 2.1 of the License, or (at your option) any later version.
177++
178++ The GNU C Library is distributed in the hope that it will be useful,
179++ but WITHOUT ANY WARRANTY; without even the implied warranty of
180++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
181++ Lesser General Public License for more details.
182++
183++ You should have received a copy of the GNU Lesser General Public
184++ License along with the GNU C Library; if not, see
185++ <http://www.gnu.org/licenses/>. */
186++
187++#include <stdarg.h>
188++#include <ucontext.h>
189++
190++/* Number of arguments that go in registers. */
191++#define NREG_ARGS 4
192++
193++/* Take a context previously prepared via getcontext() and set to
194++ call func() with the given int only args. */
195++void
196++__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
197++{
198++ extern void __startcontext (void);
199++ unsigned long *funcstack;
200++ va_list vl;
201++ unsigned long *regptr;
202++ unsigned int reg;
203++ int misaligned;
204++
205++ /* Start at the top of stack. */
206++ funcstack = (unsigned long *) (ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
207++
208++ /* Ensure the stack stays eight byte aligned. */
209++ misaligned = ((unsigned long) funcstack & 4) != 0;
210++
211++ if ((argc > NREG_ARGS) && (argc & 1) != 0)
212++ misaligned = !misaligned;
213++
214++ if (misaligned)
215++ funcstack -= 1;
216++
217++ va_start (vl, argc);
218++
219++ /* Reserve space for the on-stack arguments. */
220++ if (argc > NREG_ARGS)
221++ funcstack -= (argc - NREG_ARGS);
222++
223++ ucp->uc_mcontext.arm_sp = (unsigned long) funcstack;
224++ ucp->uc_mcontext.arm_pc = (unsigned long) func;
225++
226++ /* Exit to startcontext() with the next context in R4 */
227++ ucp->uc_mcontext.arm_r4 = (unsigned long) ucp->uc_link;
228++ ucp->uc_mcontext.arm_lr = (unsigned long) __startcontext;
229++
230++ /* The first four arguments go into registers. */
231++ regptr = &(ucp->uc_mcontext.arm_r0);
232++
233++ for (reg = 0; (reg < argc) && (reg < NREG_ARGS); reg++)
234++ *regptr++ = va_arg (vl, unsigned long);
235++
236++ /* And the remainder on the stack. */
237++ for (; reg < argc; reg++)
238++ *funcstack++ = va_arg (vl, unsigned long);
239++
240++ va_end (vl);
241++}
242++weak_alias (__makecontext, makecontext)
243+diff --git a/ports/sysdeps/unix/sysv/linux/arm/eabi/setcontext.S b/ports/sysdeps/unix/sysv/linux/arm/eabi/setcontext.S
244+new file mode 100644
245+index 0000000..78003f5
246+--- /dev/null
247++++ b/ports/sysdeps/unix/sysv/linux/arm/eabi/setcontext.S
248+@@ -0,0 +1,101 @@
249++/* Copyright (C) 2012 Free Software Foundation, Inc.
250++ This file is part of the GNU C Library.
251++
252++ The GNU C Library is free software; you can redistribute it and/or
253++ modify it under the terms of the GNU Lesser General Public
254++ License as published by the Free Software Foundation; either
255++ version 2.1 of the License, or (at your option) any later version.
256++
257++ The GNU C Library is distributed in the hope that it will be useful,
258++ but WITHOUT ANY WARRANTY; without even the implied warranty of
259++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
260++ Lesser General Public License for more details.
261++
262++ You should have received a copy of the GNU Lesser General Public
263++ License along with the GNU C Library; if not, see
264++ <http://www.gnu.org/licenses/>. */
265++
266++#include <sysdep.h>
267++#include <rtld-global-offsets.h>
268++
269++#include "ucontext_i.h"
270++
271++ .syntax unified
272++ .text
273++
274++/* int setcontext (const ucontext_t *ucp) */
275++
276++ENTRY(__setcontext)
277++ mov r4, r0
278++ add r0, r0, #UCONTEXT_REGSPACE
279++
280++ /* Restore the VFP registers. Copied from arm/eabi/__longjmp.S. */
281++#ifdef PIC
282++ ldr r2, 1f
283++ ldr r1, Lrtld_global_ro
284++0: add r2, pc, r2
285++ ldr r2, [r2, r1]
286++ ldr r2, [r2, #RTLD_GLOBAL_RO_DL_HWCAP_OFFSET]
287++#else
288++ ldr r2, Lhwcap
289++ ldr r2, [r2, #0]
290++#endif
291++
292++ tst r2, #HWCAP_ARM_VFP
293++ beq Lno_vfp_sc
294++
295++ /* Following instruction is vldmia r0!, {d8-d15}. */
296++ ldc p11, cr8, [r0], #64
297++ /* Restore the floating-point status register. */
298++ ldr r1, [r0], #4
299++ /* Following instruction is fmxr fpscr, r1. */
300++ mcr p10, 7, r1, cr1, cr0, 0
301++Lno_vfp_sc:
302++ tst r2, #HWCAP_ARM_IWMMXT
303++ beq Lno_iwmmxt_sc
304++
305++ /* Restore the call-preserved iWMMXt registers. */
306++ /* Following instructions are wldrd wr10, [r0], #8 (etc.) */
307++ ldcl p1, cr10, [r0], #8
308++ ldcl p1, cr11, [r0], #8
309++ ldcl p1, cr12, [r0], #8
310++ ldcl p1, cr13, [r0], #8
311++ ldcl p1, cr14, [r0], #8
312++ ldcl p1, cr15, [r0], #8
313++Lno_iwmmxt_sc:
314++
315++ /* Now bring back the signal status. */
316++ mov r0, #SIG_SETMASK
317++ add r1, r4, #UCONTEXT_SIGMASK
318++ mov r2, #0
319++ bl PLTJMP(__sigprocmask)
320++
321++ /* Loading r0-r3 makes makecontext easier. */
322++ add r14, r4, #MCONTEXT_ARM_R0
323++ ldmia r14, {r0-r12}
324++ ldr r13, [r14, #(MCONTEXT_ARM_SP - MCONTEXT_ARM_R0)]
325++ add r14, r14, #(MCONTEXT_ARM_LR - MCONTEXT_ARM_R0)
326++ ldmia r14, {r14, pc}
327++
328++END(setcontext)
329++weak_alias(__setcontext, setcontext)
330++
331++ /* Called when a makecontext() context returns. Start the
332++ context in R4 or fall through to exit(). */
333++ENTRY(__startcontext)
334++ movs r0, r4
335++ bne PLTJMP(__setcontext)
336++
337++ @ New context was 0 - exit
338++ b PLTJMP(_exit)
339++END(__startcontext)
340++
341++#ifdef PIC
342++1: .long _GLOBAL_OFFSET_TABLE_ - 0b - 8
343++Lrtld_global_ro:
344++ .long C_SYMBOL_NAME(_rtld_global_ro)(GOT)
345++#else
346++Lhwcap:
347++ .long C_SYMBOL_NAME(_dl_hwcap)
348++#endif
349++
350+diff --git a/ports/sysdeps/unix/sysv/linux/arm/eabi/swapcontext.S b/ports/sysdeps/unix/sysv/linux/arm/eabi/swapcontext.S
351+new file mode 100644
352+index 0000000..09492d0
353+--- /dev/null
354++++ b/ports/sysdeps/unix/sysv/linux/arm/eabi/swapcontext.S
355+@@ -0,0 +1,63 @@
356++/* Copyright (C) 2012 Free Software Foundation, Inc.
357++ This file is part of the GNU C Library.
358++
359++ The GNU C Library is free software; you can redistribute it and/or
360++ modify it under the terms of the GNU Lesser General Public
361++ License as published by the Free Software Foundation; either
362++ version 2.1 of the License, or (at your option) any later version.
363++
364++ The GNU C Library is distributed in the hope that it will be useful,
365++ but WITHOUT ANY WARRANTY; without even the implied warranty of
366++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
367++ Lesser General Public License for more details.
368++
369++ You should have received a copy of the GNU Lesser General Public
370++ License along with the GNU C Library; if not, see
371++ <http://www.gnu.org/licenses/>. */
372++
373++#include <sysdep.h>
374++
375++#include "ucontext_i.h"
376++
377++ .syntax unified
378++ .text
379++
380++/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
381++
382++ENTRY(swapcontext)
383++
384++ /* Have getcontext() do most of the work then fix up
385++ LR afterwards. Save R3 to keep the stack aligned. */
386++ push {r0,r1,r3,r14}
387++ cfi_adjust_cfa_offset (16)
388++ cfi_rel_offset (r0,0)
389++ cfi_rel_offset (r1,4)
390++ cfi_rel_offset (r3,8)
391++ cfi_rel_offset (r14,12)
392++
393++ bl __getcontext
394++ mov r4, r0
395++
396++ pop {r0,r1,r3,r14}
397++ cfi_adjust_cfa_offset (-16)
398++ cfi_restore (r0)
399++ cfi_restore (r1)
400++ cfi_restore (r3)
401++ cfi_restore (r14)
402++
403++ /* Exit if getcontext() failed. */
404++ cmp r4, #0
405++ itt ne
406++ movne r0, r4
407++ RETINSTR(ne, r14)
408++
409++ /* Fix up LR and the PC. */
410++ str r13,[r0, #MCONTEXT_ARM_SP]
411++ str r14,[r0, #MCONTEXT_ARM_LR]
412++ str r14,[r0, #MCONTEXT_ARM_PC]
413++
414++ /* And swap using swapcontext(). */
415++ mov r0, r1
416++ b __setcontext
417++
418++END(swapcontext)
419+diff --git a/ports/sysdeps/unix/sysv/linux/arm/ucontext_i.sym b/ports/sysdeps/unix/sysv/linux/arm/ucontext_i.sym
420+new file mode 100644
421+index 0000000..306292f
422+--- /dev/null
423++++ b/ports/sysdeps/unix/sysv/linux/arm/ucontext_i.sym
424+@@ -0,0 +1,30 @@
425++#include <inttypes.h>
426++#include <signal.h>
427++#include <stddef.h>
428++#include <sys/ucontext.h>
429++
430++SIG_BLOCK
431++SIG_SETMASK
432++
433++-- Offsets of the fields in the ucontext_t structure.
434++#define ucontext(member) offsetof (ucontext_t, member)
435++#define mcontext(member) ucontext (uc_mcontext.member)
436++
437++UCONTEXT_FLAGS ucontext (uc_flags)
438++UCONTEXT_LINK ucontext (uc_link)
439++UCONTEXT_STACK ucontext (uc_stack)
440++UCONTEXT_MCONTEXT ucontext (uc_mcontext)
441++UCONTEXT_SIGMASK ucontext (uc_sigmask)
442++
443++UCONTEXT_REGSPACE ucontext (uc_regspace)
444++
445++MCONTEXT_TRAP_NO mcontext (trap_no)
446++MCONTEXT_ERROR_CODE mcontext (error_code)
447++MCONTEXT_OLDMASK mcontext (oldmask)
448++MCONTEXT_ARM_R0 mcontext (arm_r0)
449++MCONTEXT_ARM_R4 mcontext (arm_r4)
450++MCONTEXT_ARM_SP mcontext (arm_sp)
451++MCONTEXT_ARM_LR mcontext (arm_lr)
452++MCONTEXT_ARM_PC mcontext (arm_pc)
453++MCONTEXT_ARM_CPSR mcontext (arm_cpsr)
454++MCONTEXT_FAULT_ADDRESS mcontext (fault_address)
455
456=== modified file 'debian/patches/series'
457--- debian/patches/series 2012-02-10 19:00:22 +0000
458+++ debian/patches/series 2012-03-07 22:03:19 +0000
459@@ -53,6 +53,7 @@
460 arm/unsubmitted-ldconfig-cache-abi.diff
461 arm/unsubmitted-ldso-abi-check.diff
462 arm/cvs-syscall-mcount.diff
463+arm/cvs-makecontext.diff
464
465 ia64/local-dlfptr.diff
466 ia64/submitted-libm.diff

Subscribers

People subscribed via source and target branches

to all changes: