~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/gnulib/verify.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Compile-time assert-like macros.
 
2
 
 
3
   Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc.
 
4
 
 
5
   This program is free software: you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; either version 3 of the License, or
 
8
   (at your option) any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
   GNU General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
17
 
 
18
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
 
19
 
 
20
#ifndef VERIFY_H
 
21
# define VERIFY_H 1
 
22
 
 
23
/* Each of these macros verifies that its argument R is nonzero.  To
 
24
   be portable, R should be an integer constant expression.  Unlike
 
25
   assert (R), there is no run-time overhead.
 
26
 
 
27
   There are two macros, since no single macro can be used in all
 
28
   contexts in C.  verify_true (R) is for scalar contexts, including
 
29
   integer constant expression contexts.  verify (R) is for declaration
 
30
   contexts, e.g., the top level.
 
31
 
 
32
   Symbols ending in "__" are private to this header.
 
33
 
 
34
   The code below uses several ideas.
 
35
 
 
36
   * The first step is ((R) ? 1 : -1).  Given an expression R, of
 
37
     integral or boolean or floating-point type, this yields an
 
38
     expression of integral type, whose value is later verified to be
 
39
     constant and nonnegative.
 
40
 
 
41
   * Next this expression W is wrapped in a type
 
42
     struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
 
43
     If W is negative, this yields a compile-time error.  No compiler can
 
44
     deal with a bit-field of negative size.
 
45
 
 
46
     One might think that an array size check would have the same
 
47
     effect, that is, that the type struct { unsigned int dummy[W]; }
 
48
     would work as well.  However, inside a function, some compilers
 
49
     (such as C++ compilers and GNU C) allow local parameters and
 
50
     variables inside array size expressions.  With these compilers,
 
51
     an array size check would not properly diagnose this misuse of
 
52
     the verify macro:
 
53
 
 
54
       void function (int n) { verify (n < 0); }
 
55
 
 
56
   * For the verify macro, the struct verify_type__ will need to
 
57
     somehow be embedded into a declaration.  To be portable, this
 
58
     declaration must declare an object, a constant, a function, or a
 
59
     typedef name.  If the declared entity uses the type directly,
 
60
     such as in
 
61
 
 
62
       struct dummy {...};
 
63
       typedef struct {...} dummy;
 
64
       extern struct {...} *dummy;
 
65
       extern void dummy (struct {...} *);
 
66
       extern struct {...} *dummy (void);
 
67
 
 
68
     two uses of the verify macro would yield colliding declarations
 
69
     if the entity names are not disambiguated.  A workaround is to
 
70
     attach the current line number to the entity name:
 
71
 
 
72
       #define _GL_CONCAT0(x, y) x##y
 
73
       #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
 
74
       extern struct {...} * _GL_CONCAT (dummy, __LINE__);
 
75
 
 
76
     But this has the problem that two invocations of verify from
 
77
     within the same macro would collide, since the __LINE__ value
 
78
     would be the same for both invocations.  (The GCC __COUNTER__
 
79
     macro solves this problem, but is not portable.)
 
80
 
 
81
     A solution is to use the sizeof operator.  It yields a number,
 
82
     getting rid of the identity of the type.  Declarations like
 
83
 
 
84
       extern int dummy [sizeof (struct {...})];
 
85
       extern void dummy (int [sizeof (struct {...})]);
 
86
       extern int (*dummy (void)) [sizeof (struct {...})];
 
87
 
 
88
     can be repeated.
 
89
 
 
90
   * Should the implementation use a named struct or an unnamed struct?
 
91
     Which of the following alternatives can be used?
 
92
 
 
93
       extern int dummy [sizeof (struct {...})];
 
94
       extern int dummy [sizeof (struct verify_type__ {...})];
 
95
       extern void dummy (int [sizeof (struct {...})]);
 
96
       extern void dummy (int [sizeof (struct verify_type__ {...})]);
 
97
       extern int (*dummy (void)) [sizeof (struct {...})];
 
98
       extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
 
99
 
 
100
     In the second and sixth case, the struct type is exported to the
 
101
     outer scope; two such declarations therefore collide.  GCC warns
 
102
     about the first, third, and fourth cases.  So the only remaining
 
103
     possibility is the fifth case:
 
104
 
 
105
       extern int (*dummy (void)) [sizeof (struct {...})];
 
106
 
 
107
   * GCC warns about duplicate declarations of the dummy function if
 
108
     -Wredundant_decls is used.  GCC 4.3 and later have a builtin
 
109
     __COUNTER__ macro that can let us generate unique identifiers for
 
110
     each dummy function, to suppress this warning.
 
111
 
 
112
   * This implementation exploits the fact that GCC does not warn about
 
113
     the last declaration mentioned above.  If a future version of GCC
 
114
     introduces a warning for this, the problem could be worked around
 
115
     by using code specialized to GCC, just as __COUNTER__ is already
 
116
     being used if available.
 
117
 
 
118
       #if 4 <= __GNUC__
 
119
       # define verify(R) [another version to keep GCC happy]
 
120
       #endif
 
121
 
 
122
   * In C++, any struct definition inside sizeof is invalid.
 
123
     Use a template type to work around the problem.  */
 
124
 
 
125
/* Concatenate two preprocessor tokens.  */
 
126
# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
 
127
# define _GL_CONCAT0(x, y) x##y
 
128
 
 
129
/* _GL_COUNTER is an integer, preferably one that changes each time we
 
130
   use it.  Use __COUNTER__ if it works, falling back on __LINE__
 
131
   otherwise.  __LINE__ isn't perfect, but it's better than a
 
132
   constant.  */
 
133
# if defined __COUNTER__ && __COUNTER__ != __COUNTER__
 
134
#  define _GL_COUNTER __COUNTER__
 
135
# else
 
136
#  define _GL_COUNTER __LINE__
 
137
# endif
 
138
 
 
139
/* Generate a symbol with the given prefix, making it unique if
 
140
   possible.  */
 
141
# define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
 
142
 
 
143
/* Verify requirement R at compile-time, as an integer constant expression.
 
144
   Return 1.  */
 
145
 
 
146
# ifdef __cplusplus
 
147
template <int w>
 
148
  struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
 
149
#  define verify_true(R) \
 
150
     (!!sizeof (verify_type__<(R) ? 1 : -1>))
 
151
# else
 
152
#  define verify_true(R) \
 
153
     (!!sizeof \
 
154
      (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
 
155
# endif
 
156
 
 
157
/* Verify requirement R at compile-time, as a declaration without a
 
158
   trailing ';'.  */
 
159
 
 
160
# define verify(R) \
 
161
    extern int (* _GL_GENSYM (verify_function) (void)) [verify_true (R)]
 
162
 
 
163
#endif