2.9
[glibc/nacl-glibc.git] / sysdeps / generic / bp-start.h
blob02765a577e49578499737b1098d6dfba51c8dbea
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
22 #if __BOUNDED_POINTERS__
24 /* The command-line arg vector and environment vector come to us from
25 the OS as an unbounded pointer to an array of unbounded strings.
26 The user's main expects argv and __environ to be bounded pointers
27 to arrays of bounded strings. */
28 # define INIT_ARGV_and_ENVIRON \
29 do { \
30 int envc; \
31 for (envc = 0; *ubp_ev; ubp_ev++, envc++) \
32 ; \
33 ubp_ev -= envc; \
35 /* GKM FIXME: we could save some space by allocating only enough for \
36 the additional low & high words, and destructively rewriting \
37 argv in place. */ \
38 __ptrvalue (argv) = __ptrlow (argv) \
39 = alloca ((argc + envc + 2) * sizeof (*argv)); \
40 __ptrhigh (argv) = __ptrvalue (argv) + argc + 1; \
41 __ptrvalue (__environ) = __ptrlow (__environ) = __ptrhigh (argv); \
42 __ptrhigh (__environ) = __ptrvalue (__environ) + envc + 1; \
43 boundify_vector (__environ, ubp_ev); \
44 boundify_vector (argv, ubp_av); \
45 } while (0)
48 /* Copy an unbounded vector of unbounded strings into a bounded
49 counterpart. */
51 static void
52 boundify_vector (char **dest, char *__unbounded *__unbounded src)
54 char *__unbounded s;
55 for (; *src; src++, dest++)
57 __ptrvalue (*dest) = __ptrlow (*dest) = *src;
58 __ptrhigh (*dest) = src[1];
60 *dest = 0;
61 /* The OS lays out strings contiguously in vector order,
62 so */
63 for (s = __ptrvalue (dest[-1]); *s; s++)
65 __ptrhigh (dest[-1]) = ++s;
68 #else
70 # define INIT_ARGV_and_ENVIRON __environ = ubp_ev
72 #endif