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