1 /* Bounded-pointer definitions for x86 assembler.
2 Copyright (C) 2000 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.
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.
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.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 # if __BOUNDED_POINTERS__
29 /* Bounded pointers occupy three words. */
31 /* Bounded pointer return values are passed back through a hidden
32 argument that points to caller-allocate space. The hidden arg
33 occupies one word on the stack. */
35 /* Although the caller pushes the hidden arg, the callee is
36 responsible for popping it. */
37 # define RET_PTR ret $RTN_SIZE
38 /* Maintain frame pointer chain in leaf assembler functions for the benefit
39 of debugging stack traces when bounds violations occur. */
40 # define ENTER pushl %ebp; movl %esp, %ebp
41 # define LEAVE movl %ebp, %esp; popl %ebp
42 /* Stack space overhead of procedure-call linkage: return address and
45 /* Stack offset of return address after calling ENTER. */
48 /* Int 5 is the "bound range" exception also raised by the "bound"
50 # define BOUNDS_VIOLATED int $5
52 # define CHECK_BOUNDS_LOW(VAL_REG, BP_MEM) \
53 cmpl 4+BP_MEM, VAL_REG; \
54 jae 0f; /* continue if value >= low */ \
58 # define CHECK_BOUNDS_HIGH(VAL_REG, BP_MEM, Jcc) \
59 cmpl 8+BP_MEM, VAL_REG; \
60 Jcc 0f; /* continue if value < high */ \
64 # define CHECK_BOUNDS_BOTH(VAL_REG, BP_MEM) \
65 cmpl 4+BP_MEM, VAL_REG; \
66 jb 1f; /* die if value < low */ \
67 cmpl 8+BP_MEM, VAL_REG; \
68 jb 0f; /* continue if value < high */ \
72 # define CHECK_BOUNDS_BOTH_WIDE(VAL_REG, BP_MEM, LENGTH) \
73 CHECK_BOUNDS_LOW(VAL_REG, BP_MEM); \
74 addl LENGTH, VAL_REG; \
75 cmpl 8+BP_MEM, VAL_REG; \
76 jbe 0f; /* continue if value <= high */ \
78 0: subl LENGTH, VAL_REG /* restore value */
80 /* Take bounds from BP_MEM and affix them to the pointer
81 value in %eax, stuffing all into memory at RTN(%esp).
82 Use %edx as a scratch register. */
84 # define RETURN_BOUNDED_POINTER(BP_MEM) \
85 movl RTN(%esp), %edx; \
87 movl 4+BP_MEM, %eax; \
89 movl 8+BP_MEM, %eax; \
92 # define RETURN_NULL_BOUNDED_POINTER \
93 movl RTN(%esp), %edx; \
98 /* The caller of __errno_location is responsible for allocating space
99 for the three-word BP return-value and passing pushing its address
100 as an implicit first argument. */
101 # define PUSH_ERRNO_LOCATION_RETURN \
106 /* __errno_location is responsible for popping the implicit first
107 argument, but we must pop the space for the BP itself. We also
108 dereference the return value in order to dig out the pointer value. */
109 # define POP_ERRNO_LOCATION_RETURN \
113 # else /* !__BOUNDED_POINTERS__ */
115 /* Unbounded pointers occupy one word. */
117 /* Unbounded pointer return values are passed back in the register %eax. */
119 /* Use simple return instruction for unbounded pointer values. */
121 /* Don't maintain frame pointer chain for leaf assembler functions. */
124 /* Stack space overhead of procedure-call linkage: return address only. */
126 /* Stack offset of return address after calling ENTER. */
129 # define CHECK_BOUNDS_LOW(VAL_REG, BP_MEM)
130 # define CHECK_BOUNDS_HIGH(VAL_REG, BP_MEM, Jcc)
131 # define CHECK_BOUNDS_BOTH(VAL_REG, BP_MEM)
132 # define CHECK_BOUNDS_BOTH_WIDE(VAL_REG, BP_MEM, LENGTH)
133 # define RETURN_BOUNDED_POINTER(BP_MEM)
135 # define RETURN_NULL_BOUNDED_POINTER
137 # define PUSH_ERRNO_LOCATION_RETURN
138 # define POP_ERRNO_LOCATION_RETURN
140 # endif /* !__BOUNDED_POINTERS__ */
142 # endif /* __ASSEMBLER__ */
144 #endif /* _bp_asm_h_ */