chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / debian / patches / hurd-i386 / local-longjmp_chk.diff
1 From Thomas Schwinge.
2
3 Provide ____longjmp_chk, still WIP.
4 ---
5  sysdeps/mach/hurd/i386/Makefile           |    4 +
6  sysdeps/mach/hurd/i386/____longjmp_chk.S  |  108 ++++++++++++++++++++++++++++++
7  sysdeps/mach/hurd/i386/signal-defines.sym |   10 ++
8  3 files changed, 122 insertions(+)
9
10 --- /dev/null
11 +++ b/sysdeps/mach/hurd/i386/____longjmp_chk.S
12 @@ -0,0 +1,108 @@
13 +/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc.
14 +   This file is part of the GNU C Library.
15 +
16 +   The GNU C Library is free software; you can redistribute it and/or
17 +   modify it under the terms of the GNU Lesser General Public
18 +   License as published by the Free Software Foundation; either
19 +   version 2.1 of the License, or (at your option) any later version.
20 +
21 +   The GNU C Library is distributed in the hope that it will be useful,
22 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
23 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24 +   Lesser General Public License for more details.
25 +
26 +   You should have received a copy of the GNU Lesser General Public
27 +   License along with the GNU C Library; if not, write to the Free
28 +   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 +   02111-1307 USA.  */
30 +
31 +#include <sysdep.h>
32 +#include <jmpbuf-offsets.h>
33 +#include <asm-syntax.h>
34 +
35 +#include <signal-defines.h>
36 +/* #include <signal.h> */
37 +#define SS_ONSTACK 1
38 +
39 +
40 +       .section .rodata.str1.1,"aMS",@progbits,1
41 +       .type   longjmp_msg,@object
42 +longjmp_msg:
43 +       .string "longjmp causes uninitialized stack frame"
44 +       .size   longjmp_msg, .-longjmp_msg
45 +
46 +
47 +#ifdef PIC
48 +# define CALL_FAIL     movl    %ebx, %ecx; /* TODO: what's this mov good for? */ \
49 +                       cfi_register(%ebx,%ecx);                              \
50 +                       LOAD_PIC_REG (bx);                                    \
51 +                       leal    longjmp_msg@GOTOFF(%ebx), %eax;               \
52 +                       call    HIDDEN_JUMPTARGET(__fortify_fail)
53 +#else
54 +# define CALL_FAIL     movl    $longjmp_msg, %eax;                           \
55 +                       call    HIDDEN_JUMPTARGET(__fortify_fail)
56 +#endif
57 +
58 +
59 +       .text
60 +ENTRY (____longjmp_chk)
61 +       movl    4(%esp), %ecx   /* User's jmp_buf in %ecx.  */
62 +
63 +       /* Save the return address now.  */
64 +       movl    (JB_PC*4)(%ecx), %edx
65 +       /* Get the stack pointer.  */
66 +       movl    (JB_SP*4)(%ecx), %edi
67 +       cfi_undefined(%edi)
68 +       PTR_DEMANGLE (%edx)
69 +       PTR_DEMANGLE (%edi)
70 +
71 +       cmpl    %edi, %esp
72 +       /* Jumping to a higher-address frame is always allowed.  */
73 +       jbe     .Lok
74 +
75 +       /* Passing here, we're either about to do something invalid, or we're
76 +       executing on an alternative signal stack.  */
77 +
78 +       /* TODO: need locking?  */
79 +       /* struct hurd_sigstate * _hurd_self_sigstate (void) */
80 +       call    _hurd_self_sigstate
81 +       /* TODO: %eax and %eax->sigaltstack are always valid?  */
82 +
83 +       testl   $SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax)
84 +       /* Fail if SS_ONSTACK is not set.  */
85 +       jz      .Lfail
86 +
87 +       movl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SP__OFFSET)(%eax), %ebx
88 +       addl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
89 +       subl    %edi, %ebx
90 +       cmpl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
91 +       /* TODO: comment this calculation.  */
92 +       jae     .Lok
93 +
94 +.Lfail:        CALL_FAIL
95 +
96 +.Lok:  /* We add unwind information for the target here.  */
97 +       cfi_def_cfa(%ecx, 0)
98 +       cfi_register(%eip, %edx)
99 +       cfi_register(%esp, %edi)
100 +       cfi_offset(%ebx, JB_BX*4)
101 +       cfi_offset(%esi, JB_SI*4)
102 +       cfi_offset(%edi, JB_DI*4)
103 +       cfi_offset(%ebp, JB_BP*4)
104 +
105 +       movl    8(%esp), %eax   /* Second argument is return value.  */
106 +       movl    %edi, %esp
107 +
108 +       /* Restore registers.  */
109 +       movl    (JB_BX*4)(%ecx), %ebx
110 +       movl    (JB_SI*4)(%ecx), %esi
111 +       movl    (JB_DI*4)(%ecx), %edi
112 +       movl    (JB_BP*4)(%ecx), %ebp
113 +       cfi_restore(%ebx)
114 +       cfi_restore(%esi)
115 +       cfi_restore(%edi)
116 +       cfi_restore(%ebp)
117 +
118 +       /* Jump to saved PC.  */
119 +       jmp     *%edx
120 +END (____longjmp_chk)
121 --- /dev/null
122 +++ b/sysdeps/mach/hurd/i386/signal-defines.sym
123 @@ -0,0 +1,10 @@
124 +#include <hurd/signal.h>
125 +#include <signal.h>
126 +
127 +--
128 +
129 +HURD_SIGSTATE__SIGALTSTACK__OFFSET     offsetof(struct hurd_sigstate, sigaltstack)
130 +
131 +SIGALTSTACK__SS_SP__OFFSET             offsetof(struct sigaltstack, ss_sp)
132 +SIGALTSTACK__SS_SIZE__OFFSET           offsetof(struct sigaltstack, ss_size)
133 +SIGALTSTACK__SS_FLAGS__OFFSET          offsetof(struct sigaltstack, ss_flags)
134 --- a/sysdeps/mach/hurd/i386/Makefile
135 +++ b/sysdeps/mach/hurd/i386/Makefile
136 @@ -2,3 +2,7 @@
137  sysdep_routines += ioperm
138  sysdep_headers += sys/io.h
139  endif
140 +
141 +ifeq ($(subdir),debug)
142 +gen-as-const-headers += signal-defines.sym
143 +endif