]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/bp-asm.h
Update copyright notices with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / i386 / bp-asm.h
1 /* Bounded-pointer definitions for x86 assembler.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Contributed by Greg McGary <greg@mcgary.org>
4 This file is part of the GNU C Library. Its master source is NOT part of
5 the C library, however. The master source lives in the GNU MP Library.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
20
21 #ifndef _bp_asm_h_
22 # define _bp_asm_h_ 1
23
24 # if __ASSEMBLER__
25
26 # if __BOUNDED_POINTERS__
27
28 /* Bounded pointers occupy three words. */
29 # define PTR_SIZE 12
30 /* Bounded pointer return values are passed back through a hidden
31 argument that points to caller-allocate space. The hidden arg
32 occupies one word on the stack. */
33 # define RTN_SIZE 4
34 /* Although the caller pushes the hidden arg, the callee is
35 responsible for popping it. */
36 # define RET_PTR ret $RTN_SIZE
37 /* Maintain frame pointer chain in leaf assembler functions for the benefit
38 of debugging stack traces when bounds violations occur. */
39 # define ENTER pushl %ebp; movl %esp, %ebp
40 # define LEAVE movl %ebp, %esp; popl %ebp
41 /* Stack space overhead of procedure-call linkage: return address and
42 frame pointer. */
43 # define LINKAGE 8
44 /* Stack offset of return address after calling ENTER. */
45 # define PCOFF 4
46
47 /* Int 5 is the "bound range" exception also raised by the "bound"
48 instruction. */
49 # define BOUNDS_VIOLATED int $5
50
51 # define CHECK_BOUNDS_LOW(VAL_REG, BP_MEM) \
52 cmpl 4+BP_MEM, VAL_REG; \
53 jae 0f; /* continue if value >= low */ \
54 BOUNDS_VIOLATED; \
55 0:
56
57 # define CHECK_BOUNDS_HIGH(VAL_REG, BP_MEM, Jcc) \
58 cmpl 8+BP_MEM, VAL_REG; \
59 Jcc 0f; /* continue if value < high */ \
60 BOUNDS_VIOLATED; \
61 0:
62
63 # define CHECK_BOUNDS_BOTH(VAL_REG, BP_MEM) \
64 cmpl 4+BP_MEM, VAL_REG; \
65 jb 1f; /* die if value < low */ \
66 cmpl 8+BP_MEM, VAL_REG; \
67 jb 0f; /* continue if value < high */ \
68 1: BOUNDS_VIOLATED; \
69 0:
70
71 # define CHECK_BOUNDS_BOTH_WIDE(VAL_REG, BP_MEM, LENGTH) \
72 CHECK_BOUNDS_LOW(VAL_REG, BP_MEM); \
73 addl LENGTH, VAL_REG; \
74 cmpl 8+BP_MEM, VAL_REG; \
75 jbe 0f; /* continue if value <= high */ \
76 BOUNDS_VIOLATED; \
77 0: subl LENGTH, VAL_REG /* restore value */
78
79 /* Take bounds from BP_MEM and affix them to the pointer
80 value in %eax, stuffing all into memory at RTN(%esp).
81 Use %edx as a scratch register. */
82
83 # define RETURN_BOUNDED_POINTER(BP_MEM) \
84 movl RTN(%esp), %edx; \
85 movl %eax, 0(%edx); \
86 movl 4+BP_MEM, %eax; \
87 movl %eax, 4(%edx); \
88 movl 8+BP_MEM, %eax; \
89 movl %eax, 8(%edx)
90
91 # define RETURN_NULL_BOUNDED_POINTER \
92 movl RTN(%esp), %edx; \
93 movl %eax, 0(%edx); \
94 movl %eax, 4(%edx); \
95 movl %eax, 8(%edx)
96
97 /* The caller of __errno_location is responsible for allocating space
98 for the three-word BP return-value and passing pushing its address
99 as an implicit first argument. */
100 # define PUSH_ERRNO_LOCATION_RETURN \
101 subl $8, %esp; \
102 subl $4, %esp; \
103 pushl %esp
104
105 /* __errno_location is responsible for popping the implicit first
106 argument, but we must pop the space for the BP itself. We also
107 dereference the return value in order to dig out the pointer value. */
108 # define POP_ERRNO_LOCATION_RETURN \
109 popl %eax; \
110 addl $8, %esp
111
112 # else /* !__BOUNDED_POINTERS__ */
113
114 /* Unbounded pointers occupy one word. */
115 # define PTR_SIZE 4
116 /* Unbounded pointer return values are passed back in the register %eax. */
117 # define RTN_SIZE 0
118 /* Use simple return instruction for unbounded pointer values. */
119 # define RET_PTR ret
120 /* Don't maintain frame pointer chain for leaf assembler functions. */
121 # define ENTER
122 # define LEAVE
123 /* Stack space overhead of procedure-call linkage: return address only. */
124 # define LINKAGE 4
125 /* Stack offset of return address after calling ENTER. */
126 # define PCOFF 0
127
128 # define CHECK_BOUNDS_LOW(VAL_REG, BP_MEM)
129 # define CHECK_BOUNDS_HIGH(VAL_REG, BP_MEM, Jcc)
130 # define CHECK_BOUNDS_BOTH(VAL_REG, BP_MEM)
131 # define CHECK_BOUNDS_BOTH_WIDE(VAL_REG, BP_MEM, LENGTH)
132 # define RETURN_BOUNDED_POINTER(BP_MEM)
133
134 # define RETURN_NULL_BOUNDED_POINTER
135
136 # define PUSH_ERRNO_LOCATION_RETURN
137 # define POP_ERRNO_LOCATION_RETURN
138
139 # endif /* !__BOUNDED_POINTERS__ */
140
141 # endif /* __ASSEMBLER__ */
142
143 #endif /* _bp_asm_h_ */