source: project/chicken/trunk/apply-hack.x86-64.s @ 15484

Last change on this file since 15484 was 15484, checked in by felix winkelmann, 11 years ago

apply patch by Zbigniew to disable executable stack in assembly code modules (reported by Marihn Schouten)

File size: 2.4 KB
Line 
1/* Apply-hack.x86-64.s
2;
3; Copyright (c) 2007, Felix L. Winkelmann
4; Copyright (c) 2008-2009, The Chicken Team
5; All rights reserved.
6;
7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
8; conditions are met:
9;
10;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11;     disclaimer.
12;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13;     disclaimer in the documentation and/or other materials provided with the distribution.
14;   Neither the name of the author nor the names of its contributors may be used to endorse or promote
15;     products derived from this software without specific prior written permission.
16;
17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25; POSSIBILITY OF SUCH DAMAGE.
26*/
27
28        .text
29
30        .globl _C_do_apply_hack
31#ifndef __APPLE__
32        .type _C_do_apply_hack, @function
33#endif
34
35_C_do_apply_hack:
36        subq $8, %rsp           /* force non-16 byte alignment */
37        movq %rdi, %r11         /* get proc */
38        movq %rsi, %r10         /* save buffer address, before we clobber %rsi */
39        cmpl $6, %edx           /* clamp at 6 */
40        ja l2
41        je l3
42        movq $6, %rbx           /* (6 - count) * 4 gives instruction address */
43        subq %rdx, %rbx
44        shlq $2, %rbx
45        lea l3(%rip), %rdx
46        addq %rdx, %rbx
47        jmp *%rbx
48l2:     lea 48(%r10), %rsp      /* %r10 must be 16-byte aligned at this point */
49l3:     movq 40(%r10), %r9      /* fill registers... */
50        movq 32(%r10), %r8
51        movq 24(%r10), %rcx
52        movq 16(%r10), %rdx
53        movq 8(%r10), %rsi
54        movq (%r10), %rdi
55        xorq %rax, %rax
56        call *%r11
57
58/* Set non-executable stack for Linux ELF target */
59#if defined(__linux__) && defined(__ELF__)
60        .section .note.GNU-stack,"",%progbits
61#endif
Note: See TracBrowser for help on using the repository browser.