1/* $OpenBSD: sigsetjmp.S,v 1.13 2020/12/13 21:21:32 bluhm Exp $ */ 2/*- 3 * Copyright (c) 1990 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * William Jolitz. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#include "SYS.h" 35#include <machine/setjmp.h> 36 37 .global __jmpxor 38 39ENTRY(sigsetjmp) 40 movl 4(%esp),%ecx # parameter, pointer to env 41 movl 8(%esp),%eax # parameter, savemask 42 movl %eax,(_JB_SIGFLAG * 4)(%ecx) 43 testl %eax,%eax 44 jz 1f 45 46 pushl $0 /* mask = empty */ 47 pushl $1 /* how = SIG_BLOCK */ 48 subl $4,%esp 49 movl $(SYS_sigprocmask),%eax 50 int $0x80 /* leave oset in %eax */ 51 addl $12,%esp 52 movl %eax,(_JB_SIGMASK * 4)(%ecx) 53 541: call 2f 552: popl %edx 56 addl $__jmpxor-2b,%edx # load cookie address 57 58 movl %ebx,(_JB_EBX * 4)(%ecx) 59 movl %esp,%eax 60 xorl 8(%edx),%eax # use esp cookie 61 movl %eax,(_JB_ESP * 4)(%ecx) 62 movl %ebp,%eax 63 xorl 0(%edx),%eax # use ebp cookie 64 movl %eax,(_JB_EBP * 4)(%ecx) 65 movl %esi,(_JB_ESI * 4)(%ecx) 66 movl %edi,(_JB_EDI * 4)(%ecx) 67 movl 4(%edx),%edx # load eip cookie over cookie address 68 xorl 0(%esp),%edx 69 movl %edx,(_JB_EIP * 4)(%ecx) 70 fnstcw (_JB_FCW * 4)(%ecx) 71 xorl %eax,%eax 72 ret 73END(sigsetjmp) 74 75ENTRY(siglongjmp) 76 movl 4(%esp),%edx # parameter, pointer to env 77 cmpl $0,(_JB_SIGFLAG * 4)(%edx) 78 jz 1f 79 80 pushl (_JB_SIGMASK * 4)(%edx) /* mask from sc_mask */ 81 pushl $3 /* how = SIG_SETMASK */ 82 subl $4,%esp 83 movl $(SYS_sigprocmask),%eax 84 int $0x80 85 addl $12,%esp 86 871: call 2f 882: popl %ecx 89 addl $__jmpxor-2b,%ecx # load cookie address 90 91 movl 4(%esp),%edx # reload in case sigprocmask failed 92 movl 8(%esp),%eax # parameter, val 93 fldcw (_JB_FCW * 4)(%edx) 94 movl (_JB_EBX * 4)(%edx),%ebx 95 movl (_JB_ESP * 4)(%edx),%esi 96 xorl 8(%ecx),%esi # use esp cookie 97 movl %esi,%esp # un-xor'ed esp is safe to use 98 movl (_JB_EBP * 4)(%edx),%ebp 99 xorl 0(%ecx),%ebp # use ebp cookie 100 movl (_JB_ESI * 4)(%edx),%esi 101 movl (_JB_EDI * 4)(%edx),%edi 102 103 movl 4(%ecx),%ecx # load eip cookie over cookie address 104 xorl (_JB_EIP * 4)(%edx),%ecx 105 testl %eax,%eax 106 jnz 2f 107 incl %eax 1082: movl %ecx,0(%esp) 109 ret 110END(siglongjmp) 111