1 /* Bounded-pointer checking macros for C.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Greg McGary <greg@mcgary.org>
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
21 #if __BOUNDED_POINTERS__
23 /* The command-line arg vector and environment vector come to us from
24 the OS as an unbounded pointer to an array of unbounded strings.
25 The user's main expects argv and __environ to be bounded pointers
26 to arrays of bounded strings. */
27 # define INIT_ARGV_and_ENVIRON \
30 for (envc = 0; *ubp_ev; ubp_ev++, envc++) \
34 /* GKM FIXME: we could save some space by allocating only enough for \
35 the additional low & high words, and destructively rewriting \
37 __ptrvalue (argv) = __ptrlow (argv) \
38 = alloca ((argc + envc + 2) * sizeof (*argv)); \
39 __ptrhigh (argv) = __ptrvalue (argv) + argc + 1; \
40 __ptrvalue (__environ) = __ptrlow (__environ) = __ptrhigh (argv); \
41 __ptrhigh (__environ) = __ptrvalue (__environ) + envc + 1; \
42 boundify_vector (__environ, ubp_ev); \
43 boundify_vector (argv, ubp_av); \
47 /* Copy an unbounded vector of unbounded strings into a bounded
51 boundify_vector (char **dest
, char *__unbounded
*__unbounded src
)
54 for (; *src
; src
++, dest
++)
56 __ptrvalue (*dest
) = __ptrlow (*dest
) = *src
;
57 __ptrhigh (*dest
) = src
[1];
60 /* The OS lays out strings contiguously in vector order,
62 for (s
= __ptrvalue (dest
[-1]); *s
; s
++)
64 __ptrhigh (dest
[-1]) = ++s
;
69 # define INIT_ARGV_and_ENVIRON __environ = ubp_ev